From c958252c02149a8e7337ed83f2c38f453f55a388 Mon Sep 17 00:00:00 2001 From: Anyon Date: Thu, 6 Jul 2017 15:33:38 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E9=9B=85=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Auth.php | 80 ++++++++++++++----------- application/admin/controller/Config.php | 7 +-- application/admin/controller/Log.php | 11 ++-- 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/application/admin/controller/Auth.php b/application/admin/controller/Auth.php index 59c992922..b075d7bbe 100644 --- a/application/admin/controller/Auth.php +++ b/application/admin/controller/Auth.php @@ -45,36 +45,48 @@ class Auth extends BasicAdmin { /** * 权限授权 - * @return string|array + * @return string */ public function apply() { $auth_id = $this->request->get('id', '0'); - switch (strtolower($this->request->get('action', '0'))) { - case 'getnode': - $nodes = NodeService::get(); - $checked = Db::name('SystemAuthNode')->where('auth', $auth_id)->column('node'); - foreach ($nodes as $key => &$node) { - $node['checked'] = in_array($node['node'], $checked); - if (empty($node['is_auth']) && substr_count($node['node'], '/') > 1) { - unset($nodes[$key]); - } - } - $this->success('获取节点成功!', '', $this->_filterNodes($this->_filterNodes(ToolsService::arr2tree($nodes, 'node', 'pnode', '_sub_')))); - break; - case 'save': - $data = []; - $post = $this->request->post(); - foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) { - $data[] = ['auth' => $auth_id, 'node' => $node]; - } - Db::name('SystemAuthNode')->where('auth', $auth_id)->delete(); - Db::name('SystemAuthNode')->insertAll($data); - $this->success('节点授权更新成功!', ''); - break; - default : - $this->assign('title', '节点授权'); - return $this->_form($this->table, 'apply'); + $method = '_apply_' . strtolower($this->request->get('action', '0')); + if (method_exists($this, $method)) { + return $this->$method($auth_id); } + $this->assign('title', '节点授权'); + return $this->_form($this->table, 'apply'); + } + + /** + * 读取授权节点 + * @param $auth_id + */ + protected function _apply_getnode($auth_id) { + $nodes = NodeService::get(); + $checked = Db::name('SystemAuthNode')->where('auth', $auth_id)->column('node'); + foreach ($nodes as $key => &$node) { + $node['checked'] = in_array($node['node'], $checked); + if (empty($node['is_auth']) && substr_count($node['node'], '/') > 1) { + unset($nodes[$key]); + } + } + $allnode = $this->_apply_filter(ToolsService::arr2tree($nodes, 'node', 'pnode', '_sub_')); + $this->success('获取节点成功!', '', $allnode); + } + + /** + * 保存授权节点 + * @param $auth_id + */ + protected function _apply_save($auth_id) { + $data = []; + $post = $this->request->post(); + foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) { + $data[] = ['auth' => $auth_id, 'node' => $node]; + } + Db::name('SystemAuthNode')->where('auth', $auth_id)->delete(); + Db::name('SystemAuthNode')->insertAll($data); + $this->success('节点授权更新成功!', ''); } /** @@ -83,10 +95,10 @@ class Auth extends BasicAdmin { * @param int $level * @return array */ - protected function _filterNodes($nodes, $level = 1) { + protected function _apply_filter($nodes, $level = 1) { foreach ($nodes as $key => &$node) { if (!empty($node['_sub_']) && is_array($node['_sub_'])) { - $node['_sub_'] = $this->_filterNodes($node['_sub_'], $level + 1); + $node['_sub_'] = $this->_apply_filter($node['_sub_'], $level + 1); } elseif ($level < 3) { unset($nodes[$key]); } @@ -113,9 +125,9 @@ class Auth extends BasicAdmin { */ public function forbid() { if (DataService::update($this->table)) { - $this->success("权限禁用成功!", ''); + $this->success("权限禁用成功!", ''); } - $this->error("权限禁用失败,请稍候再试!"); + $this->error("权限禁用失败, 请稍候再试!"); } /** @@ -123,9 +135,9 @@ class Auth extends BasicAdmin { */ public function resume() { if (DataService::update($this->table)) { - $this->success("权限启用成功!", ''); + $this->success("权限启用成功!", ''); } - $this->error("权限启用失败,请稍候再试!"); + $this->error("权限启用失败, 请稍候再试!"); } /** @@ -135,9 +147,9 @@ class Auth extends BasicAdmin { if (DataService::update($this->table)) { $id = $this->request->post('id'); Db::name('SystemAuthNode')->where('auth', $id)->delete(); - $this->success("权限删除成功!", ''); + $this->success("权限删除成功!", ''); } - $this->error("权限删除失败,请稍候再试!"); + $this->error("权限删除失败, 请稍候再试!"); } } diff --git a/application/admin/controller/Config.php b/application/admin/controller/Config.php index 6e0634aa5..67c654aa7 100644 --- a/application/admin/controller/Config.php +++ b/application/admin/controller/Config.php @@ -57,12 +57,9 @@ class Config extends BasicAdmin { * 文件存储配置 */ public function file() { - $this->assign('alert', [ - 'type' => 'success', - 'title' => '操作提示', - 'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!' - ]); $this->title = '文件存储配置'; + $alert = ['type' => 'success', 'title' => '操作提示', 'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!']; + $this->assign('alert', $alert); return $this->index(); } diff --git a/application/admin/controller/Log.php b/application/admin/controller/Log.php index 197239ecd..2997fc97e 100644 --- a/application/admin/controller/Log.php +++ b/application/admin/controller/Log.php @@ -38,14 +38,15 @@ class Log extends BasicAdmin { */ public function index() { $this->title = '系统操作日志'; - $this->assign('actions', Db::name($this->table)->group('action')->column('action')); - $db = Db::name($this->table)->order('id desc'); $get = $this->request->get(); + $actions = Db::name($this->table)->group('action')->column('action'); + $db = Db::name($this->table)->order('id desc'); foreach (['action', 'content', 'username'] as $key) { if (isset($get[$key]) && $get[$key] !== '') { $db->where($key, 'like', "%{$get[$key]}%"); } } + $this->assign('actions', $actions); return parent::_list($db); } @@ -58,7 +59,7 @@ class Log extends BasicAdmin { foreach ($data as &$vo) { $result = $ip->btreeSearch($vo['ip']); $vo['isp'] = isset($result['region']) ? $result['region'] : ''; - $vo['isp'] = str_replace(['|0|0|0|0', '|'], ['', ' '], $vo['isp']); + $vo['isp'] = str_replace(['|0|0|0|0', '0', '|'], ['', '', ' '], $vo['isp']); } } @@ -67,9 +68,9 @@ class Log extends BasicAdmin { */ public function del() { if (DataService::update($this->table)) { - $this->success("日志删除成功!", ''); + $this->success("日志删除成功!", ''); } - $this->error("日志删除失败,请稍候再试!"); + $this->error("日志删除失败, 请稍候再试!"); } }