* Date: 2019/12/5 * Time: 17:44 */ namespace app\admin\controller; use app\admin\controller\base\Permissions; use app\admin\model\AdminLog; use app\admin\model\Urlconfig; use app\common\model\ConfigTab as configTabModel; use think\Cache; use think\Db; class Webconfig extends Permissions { protected function _initialize() { parent::_initialize(); //扩展配置标签 $tabs = (new configTabModel())->where('status', configTabModel::STATUS_OPEN)->order('sort desc')->select(); $this->assign('tabs', $tabs); $this->assign('web_config', \app\common\model\Webconfig::get(1)); } public function index() { $this->assign('is_close_site_key', (new Urlconfig())->getCloseSiteKey()); $this->assign('admin_log_num', (new AdminLog())->count()); $this->assign('backend_pass', (new Urlconfig())->getBackendPass()); return $this->fetch(); } public function publish() { if ($this->request->isPost()) { $post = $this->request->post(); $validate = new \think\Validate([ ['file_type', 'requireWith:name', '上传类型不能为空'], ['file_size', 'requireWith:name', '上传大小不能为空'], ['host', 'url'], ]); if (!$validate->check($post)) { $this->error('提交失败:' . $validate->getError()); } if (!isset($post['is_log'])) { $post['is_log'] = 0; } if (!isset($post['is_close_site'])) { $post['is_close_site'] = 0; } $model = (new \app\common\model\Webconfig())->where('id', 1)->find(); if (false == $model->allowField(true)->save($post)) { $this->error('提交失败'); } else { Cache::clear(); $this->success('提交成功', 'admin/webconfig/index'); } } } public function appointmentConfig() { if ($this->request->isPost()) { $post = $this->request->post(); $weeks = $post['weeks']??[]; $weeks = array_keys($weeks); $post['weeks'] = implode(',', $weeks); $post['morning_time_periods'] = json_encode($post['morning_time_periods']??[]); $post['afternoon_time_periods'] = json_encode($post['afternoon_time_periods']??[]); $model = (new \app\common\model\Webconfig())->where('id', 1)->find(); if (false == $model->allowField(true)->save($post)) { $this->error('提交失败'); } else { //修改系统放号记录, 新增放号记录 $speciaIds = (new \app\common\model\Specialist())->column('id'); foreach ($speciaIds as $pid) { if ((new \app\common\model\Appointment())->where('provider_id', $pid)->count() == 0) { $post['provider_id'] = $pid; (new \app\common\model\Appointment())->allowField(true)->save($post); } } $this->success('提交成功'); } } else { $webconfig = \app\common\model\Webconfig::get(1); $this->assign('morning_time_periods_json', json_decode($webconfig->morning_time_periods, true)); $this->assign('afternoon_time_periods_json', json_decode($webconfig->afternoon_time_periods, true)); return $this->fetch(); } } public function applicationConfig() { return $this->fetch(); } public function noticeConfig() { return $this->fetch(); } }