|
|
@@ -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
|