Explorar o código

超管用户获取全部菜单

wufeng %!s(int64=2) %!d(string=hai) anos
pai
achega
f5ed100555
Modificáronse 3 ficheiros con 76 adicións e 61 borrados
  1. 70 58
      app/admin/controller/Base.php
  2. 5 2
      app/admin/controller/Menu.php
  3. 1 1
      app/admin/controller/Role.php

+ 70 - 58
app/admin/controller/Base.php

@@ -71,75 +71,87 @@ class Base extends \app\BaseController
 
     public function checkRole()
     {
+        if($this->level==1){
+            return [
+                'action_conllect'=>'',
+                'write'=>[],
+                'platform'=>[],
+                'roleid'=>$this->roleid
+            ];
 
-        $uid = Db::name("user_role")->where(['uid' => $this->uid, "is_del" => 0, "status" => 1])->find();
-        if ($uid == false) {
-            return [];
-        }
-        $action = [];
-        $this->roleid = $uid['roleid'];
-        $role = Db::name("role_action")->where(["role_id" => $uid['roleid'], "status" => 1])->find();
-        $action['action_conllect'] = isset($role['action_conllect']) ? $role['action_conllect'] : '';
-        $action['write'][] = $this->uid;
-        $group = [];
-        $group = Db::name("role_group")->where("FIND_IN_SET($this->uid,group_user) > 0")->column("id");
-        $where = "to_user=$this->uid";
-        if (!empty($group)) {
-            $where .= "  or to_group in (" . implode(",", $group) . ")";
-        }
+        }else {
+
+
+            $uid = Db::name("user_role")->where(['uid' => $this->uid, "is_del" => 0, "status" => 1])->find();
+            if ($uid == false) {
+                return [];
+            }
+            $action = [];
+            $this->roleid = $uid['roleid'];
+            $role = Db::name("role_action")->where(["role_id" => $uid['roleid'], "status" => 1])->find();
+            $action['action_conllect'] = isset($role['action_conllect']) ? $role['action_conllect'] : '';
+            $action['write'][] = $this->uid;
+            $group = [];
+            $group = Db::name("role_group")->where("FIND_IN_SET($this->uid,group_user) > 0")->column("id");
+            $where = "to_user=$this->uid";
+            if (!empty($group)) {
+                $where .= "  or to_group in (" . implode(",", $group) . ")";
+            }
 
-        $paltform = Db::name("user_platform")->where(["uid" => $this->uid, "is_del" => 0])->find();
-        $action['platform'] = $paltform != false ? explode(",", $paltform['platform']) : [];
-        $share = Db::name("role_share")->where(["is_del" => 0, "status" => 1])->where($where)->select();
-        if (!empty($share)) {
-            foreach ($share as $value) {
-                if ($value['action'] == 1) {
-                    if ($value['share_user'] != "") {
-                        $action['write'][] = $value['share_user'];
-                        $user = Db::name("user_role")->where(['uid' => $value['share_user'], "is_del" => 0, "status" => 1])->find();
-                        if ($user != false) {
-                            $role = Db::name("role_action")->where(["role_id" => $user['roleid'], "status" => 1])->find();
-                            if ($role != false) {
-                                $conlect = Db::name("action")->where(['menuid' => explode(",", $value['action_collect'])])->column("id");
-                                $shar = explode(",", $value['action_collect']);
-                                $wish = array_intersect($conlect, $shar);
-                                $action['action_conllect'] .= empty($wish) ? "" : "," . implode(",", $wish);
+            $paltform = Db::name("user_platform")->where(["uid" => $this->uid, "is_del" => 0])->find();
+            $action['platform'] = $paltform != false ? explode(",", $paltform['platform']) : [];
+            $share = Db::name("role_share")->where(["is_del" => 0, "status" => 1])->where($where)->select();
+            if (!empty($share)) {
+                foreach ($share as $value) {
+                    if ($value['action'] == 1) {
+                        if ($value['share_user'] != "") {
+                            $action['write'][] = $value['share_user'];
+                            $user = Db::name("user_role")->where(['uid' => $value['share_user'], "is_del" => 0, "status" => 1])->find();
+                            if ($user != false) {
+                                $role = Db::name("role_action")->where(["role_id" => $user['roleid'], "status" => 1])->find();
+                                if ($role != false) {
+                                    $conlect = Db::name("action")->where(['menuid' => explode(",", $value['action_collect'])])->column("id");
+                                    $shar = explode(",", $value['action_collect']);
+                                    $wish = array_intersect($conlect, $shar);
+                                    $action['action_conllect'] .= empty($wish) ? "" : "," . implode(",", $wish);
+                                }
                             }
-                        }
 
+                        }
                     }
-                }
-                if ($value['action'] === 0) {
-                    if ($value['share_user'] != "") $action['write'][] = $value['share_user'];
-                    if ($value['action_collect'] != '') {
-                        $act = Db::name("action")->where(['menuid' => explode(",", $value['action_collect']), "action_code" => '001'])->column("id");
-                        $action['action_conllect'] .= empty($act) ? "" : "," . implode(",", $act);
+                    if ($value['action'] === 0) {
+                        if ($value['share_user'] != "") $action['write'][] = $value['share_user'];
+                        if ($value['action_collect'] != '') {
+                            $act = Db::name("action")->where(['menuid' => explode(",", $value['action_collect']), "action_code" => '001'])->column("id");
+                            $action['action_conllect'] .= empty($act) ? "" : "," . implode(",", $act);
+                        }
                     }
-                }
-                if ($value['action'] === '') {
-                    if ($value['share_user'] != "") $action['write'][] = $value['share_user'];
-                    if ($value['action_collect'] != '') {
-                        $act = Db::name("action")->where(['menuid' => explode(",", $value['action_collect']), "action_code" => '001'])->column("id");
-                        $action['action_conllect'] .= empty($act) ? "" : "," . implode(",", $act);
+                    if ($value['action'] === '') {
+                        if ($value['share_user'] != "") $action['write'][] = $value['share_user'];
+                        if ($value['action_collect'] != '') {
+                            $act = Db::name("action")->where(['menuid' => explode(",", $value['action_collect']), "action_code" => '001'])->column("id");
+                            $action['action_conllect'] .= empty($act) ? "" : "," . implode(",", $act);
+                        }
                     }
                 }
             }
-        }
-        //离职交接权限
-        $resgin = Db::name("resign_info")->where([["hand_uid", "=", $this->uid], ["is_del", "=", 0], ['status', "=", 4]])
-            ->column(['resign_uid']);
-        if (!empty($resgin)) {
-            $action['write'] = array_unique(array_merge($action['write'], $resgin));
-        }
+            //离职交接权限
+            $resgin = Db::name("resign_info")->where([["hand_uid", "=", $this->uid], ["is_del", "=", 0], ['status', "=", 4]])
+                ->column(['resign_uid']);
+            if (!empty($resgin)) {
+                $action['write'] = array_unique(array_merge($action['write'], $resgin));
+            }
 
-        // 超级管理员看到所有人的数据
-        if ($uid['roleid'] == 1 || $uid['roleid'] == 33) {
-            $action['write'] = [];
-        }
-        $action['roleid'] = $uid['roleid'];
-        $action['action_conllect'] = implode(",", array_unique(explode(",", $action['action_conllect'])));
-        return $action;
+            // 超级管理员看到所有人的数据
+//        if ($uid['roleid'] == 1 || $uid['roleid'] == 33) {
+//            $action['write'] = [];
+//        }
 
+
+            $action['roleid'] = $uid['roleid'];
+            $action['action_conllect'] = implode(",", array_unique(explode(",", $action['action_conllect'])));
+            return $action;
+        }
     }
 
 

+ 5 - 2
app/admin/controller/Menu.php

@@ -69,9 +69,12 @@ class Menu extends Base
         if (empty($role)) {
             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('aid', "in", explode(",", $role['action_conllect']))
-            ->where(['status' => 1, "cstatus" => 1, "is_display" => 1])
+            ->where($where)
             ->order("weight desc,id asc,cweight desc,cid asc")
             ->select()
             ->toArray();

+ 1 - 1
app/admin/controller/Role.php

@@ -161,7 +161,7 @@ class Role extends Base
         $info = Db::name("role")
             ->alias("a")
             ->leftJoin("role_action t", "a.id=t.role_id")
-            ->field("a.*,t.action_conllect,t.action_data,t.private_data")
+            ->field("a.*,t.action_conllect,t.action_data,t.private_data,t.private_field")
             ->where("a.id", "=", $roleid)
             ->find();
         if (!$info) {