ith5 5 mēneši atpakaļ
vecāks
revīzija
fce300b412
1 mainītis faili ar 27 papildinājumiem un 25 dzēšanām
  1. 27 25
      app/v1/controller/CommonController.php

+ 27 - 25
app/v1/controller/CommonController.php

@@ -166,37 +166,39 @@ class CommonController extends BaseController
         unset($dept);
 
         // 递归格式化输出
-        function formatDeptTree($depts) {
-            $result = [];
-            foreach ($depts as $dept) {
-                $item = [
-                    'id' => 'dept_id_'.$dept['id'],
-                    'name' => $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);
+
+        $result = $this->formatDeptTree($tree);
     
         
         return $this->success($result);
     }
 
+    public function formatDeptTree($depts) {
+        $result = [];
+        foreach ($depts as $dept) {
+            $item = [
+                'id' => 'dept_id_'.$dept['id'],
+                'name' => $dept['name'],
+            ];
+            // 先加用户
+            if (!empty($dept['users'])) {
+                $item['children'] = $dept['users'];
+            }
+            // 再加子部门
+            if (!empty($dept['children'])) {
+                $children = $this->formatDeptTree($dept['children']);
+                if (!empty($item['children'])) {
+                    $item['children'] = array_merge($item['children'], $children);
+                } else {
+                    $item['children'] = $children;
+                }
+            }
+            $result[] = $item;
+        }
+        return $result;
+    }
+
 
     /**
      * 设计归属人列表Options