liuhairui 5 horas atrás
pai
commit
a585ea7aab
1 arquivos alterados com 29 adições e 22 exclusões
  1. 29 22
      application/api/controller/Staff.php

+ 29 - 22
application/api/controller/Staff.php

@@ -23,47 +23,54 @@ class Staff extends Api
     /**
      * 获取部门列表
      */
-    public function getDepartment(){
-        if (Request::instance()->isGet() == false){
+    /**
+     * 获取部门列表
+     * 固定排序:裁剪、车缝、手工、大烫、总检、包装、其他
+     */
+    public function getDepartment()
+    {
+        if (Request::instance()->isGet() == false) {
             $this->error('非法请求');
         }
 
-        // 1. 查询所有有效人员(按部门+工序分组)
+        // 1. 查询数据
         $list = db('人员_基本资料')
-            ->field('dept_name as 所在部门, big_process as 生产工序, COUNT(*) AS count')
+            ->field('big_process, dept_name, COUNT(*) AS count')
             ->whereNull('mod_rq')
-            ->group('所在部门, 生产工序')
-            ->order('id asc')
+            ->group('big_process, dept_name')
             ->select();
 
-        // 2. 构建 部门 → 工序 二级结构
+        // 2. 构建树形结构
         $tree = [];
         foreach ($list as $item) {
-            $dept = $item['所在部门'];
-            $process = $item['生产工序'];
+            $process = $item['big_process'] ?: '其他'; // 空工序 = 其他
+            $dept = $item['dept_name'];
             $count = $item['count'];
 
-            // 初始化部门
-            if (!isset($tree[$dept])) {
-                $tree[$dept] = [
-                    'label' => $dept,
+            if (!isset($tree[$process])) {
+                $tree[$process] = [
+                    'label' => $process,
                     'count' => 0,
                     'children' => []
                 ];
             }
 
-            // 总数量累加
-            $tree[$dept]['count'] += $count;
+            $tree[$process]['count'] += $count;
+            $tree[$process]['children'][] = [
+                'label' => $dept,
+                'count' => $count
+            ];
+        }
 
-            // 有生产工序 → 加入二级
-            if (!empty($process)) {
-                $tree[$dept]['children'][] = [
-                    'label' => $process,
-                    'count' => $count
-                ];
+        // 3. 固定排序:裁剪、车缝、手工、大烫、总检、包装、其他
+        $sortList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装', '其他'];
+        $result = [];
+        foreach ($sortList as $item) {
+            if (isset($tree[$item])) {
+                $result[] = $tree[$item];
             }
         }
-        $result = array_values($tree);
+
         $this->success('获取部门数据', $result);
     }