HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot//www.kvrdp.com/application/cms/controller/Domain.php
<?php
/**
 * TopAdmin
 * 版权所有 TopAdmin,并保留所有权利。
 * Author: TopAdmin
 * Date: 2021/11/16
 * 站点域名管理
 */
namespace app\cms\controller;


use app\cms\model\SiteDomain;
use app\cms\model\Site;
use app\common\controller\Adminbase;
use think\Db;
use think\facade\Cache;

class Domain extends Adminbase
{

    protected $searchFields = 'id,domain';
    //初始化
    protected function initialize()
    {
        parent::initialize();
        $this->modelClass = new SiteDomain();
    }
    /**
     * 域名列表
     */
    public function index()
    {
        $siteId = $this->request->param('id/d', '');
        if (empty($siteId)) {
            $this->error('参数错误!');
        }
        $sites = allSite();
        $site  = [];
        foreach ($sites as $v) {
            if ($v['id'] == $siteId) {
                $site[] = $v;
            }
        }
        $site = $site[0];
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $_list                      = $this->modelClass->where($where)->where('sites', $siteId)->order(['listorder' => 'desc', 'id' => 'desc'])->page($page, $limit)->select();
            $total  = $this->modelClass->where($where)->where('sites', $siteId)->count();
            $result = array("code" => 0, "count" => $total, "data" => $_list);
            return json($result);
        }
        $this->assign([
            "siteId" => $siteId,
            "name"    => $site['name'],
        ]);
        return $this->fetch();
    }

    /**
     * 站点域名
     */
    public function add()
    {
        $siteId = $this->request->param('siteId/d', '');
        if (empty($siteId)) {
            $this->error('参数错误!');
        }
        if ($this->request->isPost()) {
            $data   = $this->request->post();
            $result = $this->validate($data, 'site_domain');
            if (true !== $result) {
                return $this->error($result);
            }
            $data['create_time'] = time();
            if ($row = SiteDomain::create($data)) {
                //更新缓存
                Cache::set('Domain',null);
                return $this->success('域名添加成功~', url('index'));
            } else {
                $this->error("添加失败!");
            }
        } else {
            $this->assign(
                [
                    "siteId"   => $siteId,
                ]
            );
            return $this->fetch();
        }
    }

    /**
     * 属性删除
     */
    public function del()
    {
        $ids = $this->request->param('id/d');
        if (!is_numeric($ids) || $ids < 0) {
            return '参数错误';
        }
        if (SiteDomain::where(['id' => $ids])->delete()) {
            cache('Domain', null); //清空缓存配置
            SiteDomain::where(['id' => $ids])->delete();
            $this->success('删除成功');
        } else {
            $this->error('删除失败!');
        }
    }

    //更新站点缓存
    public function cache() {
        $domains = SiteDomain::where('status',1)->column('*','id');
        Cache::set('Domain',$domains);
        $this->success("域名缓存更新成功!");
    }

}