diff --git a/app/admin/common.php b/app/admin/common.php index 05f81aa..939a580 100644 --- a/app/admin/common.php +++ b/app/admin/common.php @@ -188,38 +188,6 @@ function get_article_cate() return $cate; } -//读取指定分类下的文章列表 -function get_article($cate_id = "") -{ - $where = array(); - if (!empty($cate_id)) { - $where['article_cate_id'] = $cate_id; - } - $article = \think\facade\Db::name('article')->where($where)->order('create_time desc')->paginate( get_config(app . page_size))->toArray(); - return $article; -} - -//读取指定文章的详情 -function get_article_info($id) -{ - $article = \think\facade\Db::name('article')->where(['id' => $id])->find(); - if (empty($article)) { - return $this->error('文章不存在'); - } - $keywrod_array = \think\facade\Db::name('ArticleKeywords') - ->field('i.aid,i.keywords_id,k.title') - ->alias('i') - ->join('keywords k', 'k.id = i.keywords_id', 'LEFT') - ->order('i.create_time asc') - ->where(array('i.aid' => $id, 'k.status' => 1)) - ->select()->toArray(); - - $article['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id')); - $article['keyword_names'] = implode(',', array_column($keywrod_array, 'title')); - return $article; -} - - /** * 管理员操作日志 * @param string $type 操作类型 login add edit view delete diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index dfc9a6c..7dfb66c 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -125,7 +125,7 @@ class Article extends BaseController $id = empty(get_params('id')) ? 0 : get_params('id'); View::assign('id', $id); if ($id > 0) { - $article = get_article_info($id); + $article = (new ArticleList())->detail($id); View::assign('article', $article); return view('edit'); } diff --git a/app/admin/middleware/Auth.php b/app/admin/middleware/Auth.php index edc478d..1c87c16 100644 --- a/app/admin/middleware/Auth.php +++ b/app/admin/middleware/Auth.php @@ -49,54 +49,49 @@ class Auth protected function checkAuth($controller, $pathInfo, $action, $uid) { //Cache::delete('RulesSrc' . $uid); - if ($uid == 1) { - // id=1的管理员默认拥有所有权限 - return true; - } else { - if (!Cache::get('RulesSrc' . $uid) || !Cache::get('RulesSrc0')) { - //用户所在权限组及所拥有的权限 - // 执行查询 - $user_groups = Db::name('admin_group_access') - ->alias('a') - ->join("admin_group g", "a.group_id=g.id", 'LEFT') - ->where("a.uid='{$uid}' and g.status='1'") - ->select() - ->toArray(); - $groups = $user_groups ?: []; + if (!Cache::get('RulesSrc' . $uid) || !Cache::get('RulesSrc0')) { + //用户所在权限组及所拥有的权限 + // 执行查询 + $user_groups = Db::name('admin_group_access') + ->alias('a') + ->join("admin_group g", "a.group_id=g.id", 'LEFT') + ->where("a.uid='{$uid}' and g.status='1'") + ->select() + ->toArray(); + $groups = $user_groups ?: []; - $ids = []; //保存用户所属用户组设置的所有权限规则id - foreach ($groups as $g) { - $ids = array_merge($ids, explode(',', trim($g['rules'], ','))); - } - $ids = array_unique($ids); - //读取所有权限规则 - $rules_all = Db::name('admin_rule')->field('src')->select(); - //读取用户组所有权限规则 - $rules = Db::name('admin_rule')->where('id', 'in', $ids)->field('src')->select(); - //循环规则,判断结果。 - $auth_list_all = []; - $auth_list = []; - foreach ($rules_all as $rule_all) { - $auth_list_all[] = strtolower($rule_all['src']); - } - foreach ($rules as $rule) { - $auth_list[] = strtolower($rule['src']); - } - //规则列表结果保存到Cache - Cache::tag('adminRules')->set('RulesSrc0', $auth_list_all, 36000); - Cache::tag('adminRules')->set('RulesSrc' . $uid, $auth_list, 36000); - } else { - $auth_list_all = Cache::get('RulesSrc0'); - $auth_list = Cache::get('RulesSrc' . $uid); - } - if (!in_array((string) $controller . '/' . $pathInfo, $auth_list_all)) { - return true; - } - else{ - if (!in_array((string) $controller . '/' . $pathInfo, $auth_list)) { - return false; - } - } - } + $ids = []; //保存用户所属用户组设置的所有权限规则id + foreach ($groups as $g) { + $ids = array_merge($ids, explode(',', trim($g['rules'], ','))); + } + $ids = array_unique($ids); + //读取所有权限规则 + $rules_all = Db::name('admin_rule')->field('src')->select(); + //读取用户组所有权限规则 + $rules = Db::name('admin_rule')->where('id', 'in', $ids)->field('src')->select(); + //循环规则,判断结果。 + $auth_list_all = []; + $auth_list = []; + foreach ($rules_all as $rule_all) { + $auth_list_all[] = strtolower($rule_all['src']); + } + foreach ($rules as $rule) { + $auth_list[] = strtolower($rule['src']); + } + //规则列表结果保存到Cache + Cache::tag('adminRules')->set('RulesSrc0', $auth_list_all, 36000); + Cache::tag('adminRules')->set('RulesSrc' . $uid, $auth_list, 36000); + } else { + $auth_list_all = Cache::get('RulesSrc0'); + $auth_list = Cache::get('RulesSrc' . $uid); + } + + $pathUrl = $controller . '/' . $pathInfo; + if (!in_array($pathUrl , $auth_list) && !in_array($pathUrl, $auth_list_all)) { + return false; + } + else{ + return true; + } } } diff --git a/app/admin/model/Article.php b/app/admin/model/Article.php index 3e4ad31..8998977 100644 --- a/app/admin/model/Article.php +++ b/app/admin/model/Article.php @@ -3,5 +3,23 @@ namespace app\admin\model; use think\Model; class Article extends Model { - + // 获取文章详情 + public function detail($id) + { + $article = \think\facade\Db::name('article')->where(['id' => $id])->find(); + if (empty($article)) { + return $this->error('文章不存在'); + } + $keywrod_array = \think\facade\Db::name('ArticleKeywords') + ->field('i.aid,i.keywords_id,k.title') + ->alias('i') + ->join('keywords k', 'k.id = i.keywords_id', 'LEFT') + ->order('i.create_time asc') + ->where(array('i.aid' => $id, 'k.status' => 1)) + ->select()->toArray(); + + $article['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id')); + $article['keyword_names'] = implode(',', array_column($keywrod_array, 'title')); + return $article; + } } \ No newline at end of file diff --git a/app/admin/view/admin/index.html b/app/admin/view/admin/index.html index 3fccc34..4fc628f 100644 --- a/app/admin/view/admin/index.html +++ b/app/admin/view/admin/index.html @@ -110,7 +110,7 @@ return; } if (obj.event === 'del') { - layer.confirm('您确定要删除该员工', { + layer.confirm('您确定要删除该账户', { icon: 3, title: '提示' }, function (index) { diff --git a/app/install/data/gougucms.sql b/app/install/data/gougucms.sql index 5dd47f4..62a9e78 100644 --- a/app/install/data/gougucms.sql +++ b/app/install/data/gougucms.sql @@ -96,7 +96,7 @@ INSERT INTO `cms_admin_menu` VALUES (8, 1, '权限角色', 'admin/role/index', ' INSERT INTO `cms_admin_menu` VALUES (9, 1, '管 理 员', 'admin/admin/index', '', 1, 0, 0); INSERT INTO `cms_admin_menu` VALUES (10, 1, '操作日志', 'admin/admin/log', '', 1, 0, 0); INSERT INTO `cms_admin_menu` VALUES (11, 1, '数据备份', 'admin/database/database', '', 1, 0, 0); -INSERT INTO `cms_admin_menu` VALUES (12, 1, '数据还原', 'admin/database/backupList', '', 1, 0, 0); +INSERT INTO `cms_admin_menu` VALUES (12, 1, '数据还原', 'admin/database/backuplist', '', 1, 0, 0); INSERT INTO `cms_admin_menu` VALUES (13, 2, '导航设置', 'admin/nav/index', '', 1, 0, 0); INSERT INTO `cms_admin_menu` VALUES (14, 2, '网站地图', 'admin/sitemap/index', '', 1, 0, 0); INSERT INTO `cms_admin_menu` VALUES (15, 2, '轮播广告', 'admin/slide/index', '', 1, 0, 0); @@ -199,7 +199,7 @@ INSERT INTO `cms_admin_rule` VALUES (71, 70, 'admin/search/get_list', '关键字 INSERT INTO `cms_admin_rule` VALUES (72, 70, 'admin/search/delete', '关键字搜索删除', 0, 0); INSERT INTO `cms_admin_rule` VALUES (73, 3, 'admin/user/index', '用户管理', 0, 0); INSERT INTO `cms_admin_rule` VALUES (74, 73, 'admin/user/get_list', '用户管理列表', 0, 0); -INSERT INTO `cms_admin_rule` VALUES (75, 73, 'admin/user/add', '修改用户', 0, 0); +INSERT INTO `cms_admin_rule` VALUES (75, 73, 'admin/user/edit', '修改用户信息', 0, 0); INSERT INTO `cms_admin_rule` VALUES (76, 73, 'admin/user/post_submit', '用户保存', 0, 0); INSERT INTO `cms_admin_rule` VALUES (77, 73, 'admin/user/view', '用户查看', 0, 0); INSERT INTO `cms_admin_rule` VALUES (78, 73, 'admin/user/delete', '用户禁用',0, 0); @@ -219,9 +219,9 @@ INSERT INTO `cms_admin_rule` VALUES (91, 1, 'admin/database/database', '数据 INSERT INTO `cms_admin_rule` VALUES (92, 91, 'admin/database/backup', '数据表备份', 0, 0); INSERT INTO `cms_admin_rule` VALUES (93, 91, 'admin/database/optimize', '数据表优化', 0, 0); INSERT INTO `cms_admin_rule` VALUES (94, 91, 'admin/database/repair', '数据表修复', 0, 0); -INSERT INTO `cms_admin_rule` VALUES (95, 1, 'admin/database/backupList', '数据还原', 0, 0); +INSERT INTO `cms_admin_rule` VALUES (95, 1, 'admin/database/backuplist', '数据还原', 0, 0); INSERT INTO `cms_admin_rule` VALUES (96, 95, 'admin/database/import', '数据表还原', 0, 0); -INSERT INTO `cms_admin_rule` VALUES (97, 95, 'admin/database/downFile', '备份数据下载', 0, 0); +INSERT INTO `cms_admin_rule` VALUES (97, 95, 'admin/database/downfile', '备份数据下载', 0, 0); INSERT INTO `cms_admin_rule` VALUES (98, 95, 'admin/database/del', '删除备份数据', 0, 0); -- ---------------------------- -- Table structure for `cms_admin_log`