ListController.class.php
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* 基础版本邀请人员组件
* @author: daijun
* @date : 2018-05-18 10:18:44
*/
namespace Api\Controller\Mem;
use Common\Common\Department;
use Common\Common\User;
use Common\Service\TeacherService;
class ListController extends AbstractController
{
/**
* List
* @author
* @desc 邀请人员通用组件
* @param String dp_id 部门ID
* @param String memUsername 搜索用户名
* @return array 邀请人员列表
array(
'dp_name' => 'A部门', // 当前部门名称
'dp_id' => 1, // 当前部门ID
'user_total'=>22, 1, // 当前部门人数
'user_list' => array(
array(
'memUsername'=>'张三', //用户名
'memUid'=>'', // 用户名称
'memFace'=>'', // 用户图像
)
),
'dp_list' => array(
array(
'dpId'=>'', // 部门ID
'dpName'=>'', // 部门名称
)
)
)
*/
public function Index_post()
{
$params = I('post.');
$dp_id = $params['dp_id'];
$memUsername = $params['memUsername'];
$deaprtment =& Department::instance();
// 如果上级部门ID为空
if (empty($dp_id)) {
// 获取顶级部门
$deaprtment->get_top_dpId($top_dp_id);
$dp_info = $deaprtment->getById($top_dp_id[0]);
} else {
$dp_info = $deaprtment->getById($dp_id);
}
$dp_result_list = [];
// 查询当前部门的子部门列表(不递归)
$dp_ids = $deaprtment->list_childrens_by_cdid([$dp_info['dpId']], false, false);
sort($dp_ids);
if (empty($memUsername)) {
$dp_list = $deaprtment->listById($dp_ids);
foreach ($dp_list as $v) {
$dp_result_list[] = [
'dpId' => $v['dpId'],
'dpName' => $v['dpName'],
];
}
}
$user_serv = &User::instance();
$conds = [];
if ($dp_id) {
// 如果传入了dp_id
$conds = [
'dpIdList' => [$dp_id],
'departmentChildrenFlag' => 1,
];
if (!empty($memUsername)) {
// 如果姓名不为空
$conds['memUsername'] = $memUsername;
}
} elseif (!empty($dp_ids)) {
// 如果是搜索的所有部门
if(!empty($top_dp_id)){
$dp_ids[]=$top_dp_id[0];
}
// 如果当前部门子部门存在
$conds = [
'dpIdList' => $dp_ids,
'departmentChildrenFlag' => 1,
];
if (!empty($memUsername)) {
// 如果姓名不为空
$conds['memUsername'] = $memUsername;
}
}
$user_list_total = 0;
$user_list = [];
if ($conds) {
// 查询当前部门子部门下的用户数量(递归)
$user_list = $user_serv->listBasicByConds($conds, 1, 1);
$user_list_total = $user_list['total'];
$user_list = $user_serv->listAllBasic($conds);
}
// 组织返回数据
$this->_result = [
'dp_name' => $dp_info['dpName'],
'dp_id' => $dp_info['dpId'],
'user_list' => $user_list,
'dp_list' => $dp_result_list,
'user_total' => $user_list_total
];
}
}