'materials', 'site_name' => '', 'keywords' => '', 'description' => '', 'logo' => '', 'logo1' => '', 'footer_logo' => '', 'tel' => '', 'facsimile' => '', 'email' => '', 'address' => '', 'gongwang' => '', 'link1' => '', 'beian' => '', 'link2' => '', 'copyright' => '', 'weibo' => '', 'wechat' => '', 'tencent_map_key' =>'', 'douyin' => '', 'content' => '', 'strength' => '' ]; // 语言标识 const LANG_CN = 1; const LANG_EN = 2; /** * 查看 */ public function index() { // 初始化中英文数据 $dataCN = $this->initConfigData(self::LANG_CN); $dataEN = $this->initConfigData(self::LANG_EN); //获取模板名称 $directory = ADDON_PATH . 'wwh' . DS . 'view' . DS; $files = scandir($directory); $folders = []; foreach ($files as $file) { if ($file !== '.' && $file !== '..' && is_dir($directory . '/' . $file)) { $folders[] = $file; } } $this->assign([ 'dataCN' => $dataCN, 'dataEN' => $dataEN, 'folders' => $folders ]); return $this->view->fetch(); } /** * 初始化数据 * @param int $lang 语言标识 * @return array */ protected function initConfigData($lang) { $id = $lang; // ID与语言标识相同 $data = Db::name('wwh_config')->where('id', $id)->find(); if (!$data) { $data = array_merge( ['id' => $id, 'lang' => $lang], self::DEFAULT_CONFIG ); Db::name('wwh_config')->insert($data); } return $data; } /** * 保存数据 * @param int $lang 语言标识 */ public function saveConfig($lang) { $id = $lang; // ID与语言标识相同 $data = [ 'id' => $id, 'template' => input('template'), 'site_name' => input('site_name'), 'keywords' => input('keywords'), 'description' => input('description'), 'logo' => input('logo'), 'logo1' => input('logo1'), 'footer_logo' => input('footer_logo'), 'tel' => input('tel'), 'facsimile' => input('facsimile'), 'email' => input('email'), 'address' => input('address'), 'gongwang' => input('gongwang'), 'link1' => input('link1'), 'beian' => input('beian'), 'link2' => input('link2'), 'copyright' => input('copyright'), 'weibo' => input('weibo'), 'wechat' => input('wechat'), 'douyin' => input('douyin'), 'tencent_map_key' => input('tencent_map_key'), 'content' => input('content'), 'strength' => input('strength'), 'lang' => $lang ]; $exists = Db::name('wwh_config')->where('id', $id)->find(); if ($exists) { // 检查数据变动 foreach (array_keys(self::DEFAULT_CONFIG) as $field) { if ($exists[$field] != $data[$field]) { $result = Db::name('wwh_config')->update($data); return $this->returnResult($result); } } return $this->error('未检测到数据变动', null, null, false); } $result = Db::name('wwh_config')->insert($data); return $this->returnResult($result); } /** * 返回操作结果 * @param bool $result */ protected function returnResult($result) { return $result ? $this->success('保存成功') : $this->error('保存失败'); } /** * 中文站点配置修改 */ public function ConfigCN() { return $this->saveConfig(self::LANG_CN); } /** * 英文站点配置修改 */ public function ConfigEN() { return $this->saveConfig(self::LANG_EN); } }