Browse Source

复数角色权限修复

sugangqiang 2 years ago
parent
commit
7c62ff15a2
1 changed files with 18 additions and 8 deletions
  1. 18 8
      app/common/api/MenuApi.php

+ 18 - 8
app/common/api/MenuApi.php

@@ -87,15 +87,20 @@ class MenuApi {
     }
 
     public static function getMenuListByRoleid($roleid) {
-        $role = Role::find($roleid);
-        $tmp = [];
-        if ($role) {
+        $roleids = explode(",", $roleid);
+        $tmpArray = [];
+        foreach ($roleids as $roleid) {
+            $role = Role::find($roleid);
             $menu_ids = $role->sysRelation->column("menuid");
+            $tmpArray = array_merge((array) $tmpArray, (array) $menu_ids);
+        }
+        $tmp = [];
+        if ($tmpArray) {
             $where[] = ["status", "=", 1];
             $where[] = ["delete", "=", 0];
             $where[] = ["ismenu", "=", 1];
             $where[] = ["new_url", "<>", ""];
-            $where[] = ["id", "in", $menu_ids];
+            $where[] = ["id", "in", $tmpArray];
             $whr[] = ["levels", "=", 1];
             $menus = Menu::whereOr([$where, $whr])->order("levels asc,num asc")->select()->toArray();
             $menus = self::buildMenu($menus);
@@ -160,11 +165,16 @@ class MenuApi {
         $menu = Menu::whereRaw("`status`=1 and (new_url=:new_url or `url`=:url)", ["new_url" => $url, "url" => $old_url])->findOrEmpty()->toArray();
         if (!$menu)
             return true;
+
         $menuid = $menu["id"];
-        $roleid = session("user")["roleid"];
-        $role = Role::find($roleid);
-        $menu_ids = $role->sysRelation->column("menuid");
-        return in_array($menuid, $menu_ids);
+        $roleids = explode(",", session("user")["roleid"]);
+        $tmpArray = [];
+        foreach ($roleids as $roleid) {
+            $role = Role::find($roleid);
+            $menu_ids = $role->sysRelation->column("menuid");
+            $tmpArray = array_merge((array) $tmpArray, (array) $menu_ids);
+        }
+        return in_array($menuid, $tmpArray);
     }
 
     public static function getEnterpriseMenuByType($type) {