Kaynağa Gözat

公司初始化

cqp 1 ay önce
ebeveyn
işleme
2268455b29

+ 1 - 1
app/Service/EmployeeService.php

@@ -318,7 +318,7 @@ class EmployeeService extends Service
 
         $model = Employee::TopClear($user,$data);
         $model = $model->where('del_time',0)
-            ->where('is_admin', '<>', Employee::IS_ADMIN_TWO)
+            ->where('is_admin', '<=', Employee::IS_ADMIN_ONE)
             ->select($field)
             ->orderBy('id','desc');
 

+ 5 - 5
app/Service/LoginService.php

@@ -167,16 +167,16 @@ class LoginService extends Service
     }
 
     public static function getPersonRoleAndPermissions($employee) {
-        // 1. 初始化返回结构
+        // 初始化返回结构
         $result = [
             'role_ids'    => [],
             'menu_permissions' => []
         ];
 
-        // 2. 是管理员账户
-        if ($employee['is_admin'] == Employee::IS_ADMIN_TWO) {
-            return $result;
-        }
+//        // 2. 是管理员账户
+//        if ($employee['is_admin'] == Employee::IS_ADMIN_TWO) {
+//            return $result;
+//        }
 
         $role_ids = EmployeeRole::where('del_time', 0)
             ->where('employee_id', $employee['id'])

+ 1 - 1
app/Service/StatisticService.php

@@ -1460,7 +1460,7 @@ class StatisticService extends StatisticCommonService
     public function enterpriseRdManStatistic($data, $user){
         $model = Employee::TopClear($user,$data);
         $model = $model->where('del_time',0)
-            ->where('is_admin', '<>', Employee::IS_ADMIN_TWO)
+            ->where('is_admin', '<=', Employee::IS_ADMIN_ONE)
             ->select(Employee::$report_field)
             ->orderBy('id','desc');
 

+ 57 - 3
app/Service/SysMenuService.php

@@ -264,12 +264,12 @@ class SysMenuService extends Service
         return [true,''];
     }
 
-    public function fillMenuButton($button, $menu, $user, $type = 1)
+    public function fillMenuButton1($button, $menu, $user, $type = 1)
     {
         // 1. 预处理所有按钮池(合并配置中的特殊按钮)
         $allButtons = collect($button)->concat(config('specialButton') ?? [])->groupBy('menu_id');
 
-        // 2. 获取权限基础数据(如果是超管,这两个值为空,逻辑依然兼容)
+        // 2. 获取权限基础数据
         $isSuper = ($user['is_admin'] == Employee::IS_ADMIN_TWO);
         $roleButtons = $isSuper ? [] : (new EmployeeService())->fillRoleButton($user['role_ids'] ?? []);
         $allowedMenuIds = $isSuper ? [] : $this->getMenuIDByRoleInList($user);
@@ -310,7 +310,48 @@ class SysMenuService extends Service
         return $result;
     }
 
-    private function returnTwo($sysList, $user){
+    public function fillMenuButton($button, $menu, $user, $type = 1)
+    {
+        // 1. 预处理所有按钮池(合并配置中的特殊按钮)
+        $allButtons = collect($button)->concat(config('specialButton') ?? [])->groupBy('menu_id');
+
+        // 2. 获取权限基础数据
+        $roleButtons = (new EmployeeService())->fillRoleButton($user['role_ids'] ?? []);
+        $allowedMenuIds = $this->getMenuIDByRoleInList($user);
+
+        $result = [];
+
+        foreach ($menu as $m) {
+            $menuId = $m['id'];
+
+            // 权限过滤:不在权限内,跳过
+            if (!in_array($menuId, $allowedMenuIds)) continue;
+
+            // 计算当前菜单拥有的按钮
+            // 只返回该角色拥有的按钮数据
+            $myBtnIds = $roleButtons[$menuId] ?? [];
+            $btnPool = collect($allButtons->get($menuId))->keyBy('id');
+            $btns = collect($myBtnIds)->map(fn($id) => $btnPool->get($id))->filter()->values();
+
+            // 3. 根据 type 返回不同的数据结构
+            if ($type == 1) {
+                // 完整模式:保留原菜单所有字段
+                $m['button'] = $btns;
+                $result[] = $m;
+            } else {
+                // 精简模式:只给前端路由用的字段
+                $result[] = [
+                    'id'     => $menuId,
+                    'uri'    => $m['uri'] ?? '',
+                    'button' => $btns,
+                ];
+            }
+        }
+
+        return $result;
+    }
+
+    private function returnTwo1($sysList, $user){
         //人员所拥有的菜单
         $menu = $this->getMenuIDByRoleInList($user);
 
@@ -323,6 +364,19 @@ class SysMenuService extends Service
         return $this->set_sort_circle($return);;
     }
 
+    private function returnTwo($sysList, $user){
+        //人员所拥有的菜单
+        $menu = $this->getMenuIDByRoleInList($user);
+
+        foreach ($sysList as $key => $value){
+            if($value['state'] <= 0) unset($sysList[$key]);
+            if(! in_array($value['id'], $menu)) unset($sysList[$key]);
+        }
+        $list = array_values($sysList);
+        $return = $this->makeTree(0,$list);
+        return $this->set_sort_circle($return);;
+    }
+
     //通过角色获取菜单ID
     public function getMenuIDByRoleInList($user){
         $role_id = $user['role_ids'] ?? [];