PC-202304251453\Administrator hai 5 meses
pai
achega
c1865a0f89
Modificáronse 1 ficheiros con 74 adicións e 7 borrados
  1. 74 7
      app/v1/controller/CommonController.php

+ 74 - 7
app/v1/controller/CommonController.php

@@ -1,5 +1,4 @@
 <?php
-
 namespace app\v1\controller;
 
 use app\v1\logic\advert\AgentListLogic;
@@ -8,9 +7,10 @@ use app\v1\logic\advert\GamePackageLogic;
 use app\v1\logic\advert\MediaListLogic;
 use app\v1\logic\center\GameGroupLogic;
 use app\v1\logic\center\GameLogic;
+use plugin\saiadmin\basic\BaseController;
 use app\v1\logic\center\GameMainLogic;
 use plugin\saiadmin\app\logic\system\SystemUserLogic;
-use plugin\saiadmin\basic\BaseController;
+use plugin\saiadmin\app\model\system\SystemDept;
 use support\Request;
 use support\Response;
 use support\think\Db;
@@ -56,7 +56,7 @@ class CommonController extends BaseController
     //     $data = $this->gameGroupLogic->getGameListOptions($where);
     //     return $this->success($data);
     // }
-
+    
     /**
      * 获取主游戏options列表
      * @return Response
@@ -98,6 +98,8 @@ class CommonController extends BaseController
     {
         $data = $this->mediaListLogic->getMediaOptions();
         $data = $data->toArray();
+        
+
         return $this->success($data);
     }
 
@@ -115,16 +117,81 @@ class CommonController extends BaseController
      */
     public function getAuthOptions(Request $request): Response
     {
-        $data = $this->systemUserLogic->field('id as value, username as label')->select()->toArray();
-        return $this->success($data);
+        // 获取用户列表
+        $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->group('dept_id')->select()->toArray();
+        
+        // 获取用户部门
+        $deptList = SystemDept::where('1=1')->select()->toArray();
+
+        $result = [];
+        // 将部门列表转为以id为key的数组,便于查找
+        $deptMap = [];
+        foreach ($deptList as $dept) {
+            $dept['children'] = [];
+            $dept['users'] = [];
+            $deptMap[$dept['id']] = $dept;
+        }
+
+        // 将用户分配到对应部门的users中
+        foreach ($data as $user) {
+            if (isset($deptMap[$user['dept_id']])) {
+                $deptMap[$user['dept_id']]['users'][] = [
+                    'value' => $user['value'],
+                    'label' => $user['label'],
+                ];
+            }
+        }
+
+        // 构建部门树
+        $tree = [];
+        foreach ($deptMap as $id => &$dept) {
+            if ($dept['parent_id'] && isset($deptMap[$dept['parent_id']])) {
+                $deptMap[$dept['parent_id']]['children'][] = &$dept;
+            } else {
+                $tree[] = &$dept;
+            }
+        }
+        unset($dept);
+
+        // 递归格式化输出
+        function formatDeptTree($depts) {
+            $result = [];
+            foreach ($depts as $dept) {
+                $item = [
+                    'value' => $dept['id'],
+                    'label' => $dept['name'],
+                ];
+                // 先加用户
+                if (!empty($dept['users'])) {
+                    $item['children'] = $dept['users'];
+                }
+                // 再加子部门
+                if (!empty($dept['children'])) {
+                    $children = formatDeptTree($dept['children']);
+                    if (!empty($item['children'])) {
+                        $item['children'] = array_merge($item['children'], $children);
+                    } else {
+                        $item['children'] = $children;
+                    }
+                }
+                $result[] = $item;
+            }
+            return $result;
+        }
+
+        $result = formatDeptTree($tree);
+    
+        
+        return $this->success($result);
     }
 
+
     /**
      * 设计归属人列表Options
      */
     public function getDesignAuthOptions(Request $request): Response
     {
-        $data = $this->systemUserLogic->field('id as value, username as label')->where('dept_id', 11)->select()->toArray();
+        $data = $this->systemUserLogic->field('id as value, username as label')->where('dept_id',11)->select()->toArray();
         return $this->success($data);
     }
 
@@ -153,7 +220,7 @@ class CommonController extends BaseController
      */
     public function getPayChannelOptions(Request $request): Response
     {
-        $data = Db::connect('db_center')->table('pay_channel')->where('status', 1)->select()->toArray();
+        $data = Db::connect('db_center')->table('pay_channel')->where('status',1)->select()->toArray();
         return $this->success($data);
     }