Browse Source

菜单筛选优化

wufeng 2 years ago
parent
commit
5b464effa5
1 changed files with 17 additions and 9 deletions
  1. 17 9
      app/admin/controller/Menu.php

+ 17 - 9
app/admin/controller/Menu.php

@@ -61,6 +61,8 @@ class Menu extends Base
     public function list()
     {
         $post = $this->request->filter('trim')->post();
+
+        $level = $post['level'] ?? $this->level;
 //        $uid = $this->uid;
 //        if ($uid == '') {
 //            return error_show(101, '未找到用户信息');
@@ -69,27 +71,33 @@ class Menu extends Base
         //相关权限等以后重新梳理
 //        $role = $this->checkRole();
 
-        if ($this->level == 1) {
-            //超管,获取所有
+        $where = [['status', '=', 1], ['cstatus', '=', 1], ['is_display', '=', 1]];
+
+        if ($level == 1) {
+            //超管,能看到等级为012的菜单
             $role['action_conllect'] = Db::name('action')
                 ->where(['is_del' => 0, 'status' => 1])
                 ->column('id');
-        } else $role['action_conllect'] = Db::name('user_role')
-            ->alias('a')
-            ->leftJoin('role_action b', 'b.role_id=a.roleid')
-            ->where(['a.uid' => $this->uid, 'a.is_del' => 0, 'a.companyNo' => $post['relaComNo']])
-            ->value('b.action_conllect');
+            $where[] = ['level', 'in', [0, 1, 2]];
+        } else {
+            $role['action_conllect'] = Db::name('user_role')
+                ->alias('a')
+                ->leftJoin('role_action b', 'b.role_id=a.roleid')
+                ->where(['a.uid' => $this->uid, 'a.is_del' => 0, 'a.companyNo' => $post['relaComNo']])
+                ->value('b.action_conllect');
+
+            $where[] = ['level', '=', $level];
+        }
 
 //        if (empty($role['action_conllect'])) {
 //            return app_show(0, "获取成功", []);
 //        }
 
-        $where = [['status', '=', 1], ['cstatus', '=', 1], ['is_display', '=', 1]];
 //        if (!empty($role['action_conllect'])) $where[] = ['aid', 'in', $role['action_conllect']];
 
         $data = Db::name("view_menu")
             ->where($where)
-            ->whereIn('aid',$role['action_conllect'])
+            ->whereIn('aid', $role['action_conllect'])
             ->order("weight desc,id asc,cweight desc,cid asc")
             ->select()
             ->toArray();