diff --git a/application/admin/controller/posts/Sites.php b/application/admin/controller/posts/Sites.php index d1906b8d..59cd6080 100644 --- a/application/admin/controller/posts/Sites.php +++ b/application/admin/controller/posts/Sites.php @@ -35,7 +35,7 @@ class Sites extends Backend { //从站点管理登录,进入自己的站点配置页 if(Session::has("user_site_id")) { - $this->redirect('posts/sites/config?addtabs=1'); + $this->redirect('posts/sites/edit?addtabs=1'); } //超级管理员从总后台登录 else { @@ -70,88 +70,6 @@ class Sites extends Backend } } - /** - * Config - */ - public function config() - { - $row = $this->model->get(Session::get("user_site_id")); - - $settings = ['seo' => [ - 'zh-cn' => [ - 'title'=>'', - 'keywords'=>'', - 'description'=>'' - ] - ], 'custom' => '']; - - if($this->request->isPost()){ - - $params = $this->request->post("row/a"); - if ($params) { - foreach ($params as $k => $v) { - if( in_array($k, ['name','domain','lang'])){ - if($k=='lang') - $params[$k] = implode(',', $v); - }else{ - unset($params[$k]); - } - } - $seo = $this->request->post("seo/a"); - $custom = $this->request->post("custom/a"); - if ($seo) { - $settings['seo'] = json_encode($seo, JSON_UNESCAPED_UNICODE); - } - if ($custom) { - $arr = []; - foreach ($custom as $k => $v) { - $arr[$v['field']] = $v['value']; - } - $settings['custom'] = json_encode($arr, JSON_UNESCAPED_UNICODE); - } - if($row) $params['id'] = $row['id']; - try - { - //是否采用模型验证 - if ($this->modelValidate) - { - $name = basename(str_replace('\\', '/', get_class($this->model))); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate; - $this->model->validate($validate); - } - $result = $this->model->allowField(true)->save($params); - - if ($result !== false) - { - $this->model->config()->save($settings); - $this->model->refreshRulesCache(); - $this->success(); - } - else - { - $this->error($this->model->getError()); - } - } - catch (\think\exception\PDOException $e) - { - $this->error($e->getMessage()); - } - } - $this->error(__('Parameter %s can not be empty', '')); - } - - $this->view->assign('row', $row); - - if($row) { - $settings['seo'] = !empty($row->config->seo) ? json_decode($row->config->seo, true) : null; - $settings['custom'] = !empty($row->config->custom) ? json_decode($row->config->custom, true) : null; - } - $this->view->assign('settings', $settings); - $this->view->assign('multilanguage', Seven::build_langs('row[lang]', $row?$row['lang']:'', ['type'=>'checkbox'])); - return $this->view->fetch(); - - } - /** * Add */ @@ -222,13 +140,26 @@ class Sites extends Backend */ public function edit($ids = NULL) { - if(!$this->auth->isSuperAdmin()) { - $this->error(__('You have no permission')); - } + if(!$this->auth->isSuperAdmin()){ + $ids=Session::get("user_site_id"); + } + $row = $this->model->get($ids); if (!$row) $this->error(__('No Results were found')); + $settings = ['seo' => [ + 'zh-cn' => [ + 'title'=>'', + 'keywords'=>'', + 'description'=>'' + ] + ], 'custom' => [ + 'logo' => '', + 'favicon' => '', + ] + ]; + if ($this->request->isPost()) { @@ -252,6 +183,8 @@ class Sites extends Backend } $settings['custom'] = json_encode($arr, JSON_UNESCAPED_UNICODE); } + + if(!$row) $row=$this->model; try { @@ -265,7 +198,7 @@ class Sites extends Backend $result = $row->allowField(true)->save($params); if ($result !== false) { - $row->config()->save($settings); + $row->config->save($settings); $this->model->refreshRulesCache(); $this->success(); } @@ -281,10 +214,10 @@ class Sites extends Backend } $this->error(__('Parameter %s can not be empty', '')); } - $arr['seo'] = !empty($row->config->seo) ? json_decode($row->config->seo,true) : null; - $arr['custom'] = !empty($row->config->custom) ? json_decode($row->config->custom,true) : null; + $row['seo'] = !empty($row->config->seo) ? json_decode($row->config->seo,true) : null; + $row['custom'] = !empty($row->config->custom) ? json_decode($row->config->custom,true) : null; $this->view->assign("row", $row); - $this->view->assign('settings', $arr); + $this->view->assign('editstyle', $this->auth->isSuperAdmin()?'1':'0'); $this->view->assign('multilanguage', Seven::build_langs('row[lang]', $row['lang'], ['type'=>'checkbox'])); return $this->view->fetch(); } diff --git a/application/admin/view/posts/sites/edit.html b/application/admin/view/posts/sites/edit.html index 9f1428bb..a5c24138 100644 --- a/application/admin/view/posts/sites/edit.html +++ b/application/admin/view/posts/sites/edit.html @@ -1,7 +1,18 @@ +