UserListController.class.php
4.91 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Created by IntelliJ IDEA.
* 勋章列表
* User: zhoutao
* Reader: zhoutao 2017-05-31 10:07:35
* Date: 2017-05-24 15:43:49
*/
namespace Apicp\Controller\Medal;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\Integral;
use Common\Common\User;
use Common\Service\MedalService;
use Common\Service\MemberMedalService;
class UserListController extends AbstractController
{
/**
* UserList
* @author tangxingguo
* @desc 列表接口
* @param Array dp_ids 组织ID
* @param Array job_ids 岗位ID
* @param Array role_ids 角色ID
* @param String username 用户名
* @return Array
array(
'page' => 1, // 当前页
'limit' => 20, // 当前页条数
'total' => 100, // 总条数
'list' => array(
'mem_uid' => '3E31DE477F00000120C5EBDB2D6696BE', // 用户ID
'mem_username' => '老王', // 用户名
'dp_name' => array('组织1'), // 组织
'job_name' => '岗位', // 岗位
'role_name' => '角色', // 角色
'madel' => array(
array(
'name' => '学习楷模',
'num' => 2
)
)
)
);
*/
public function index()
{
$rules = [
'dp_ids' => 'array',
'job_ids' => 'array',
'role_ids' => 'array',
'username' => 'max:64',
'page' => 'integer',
'limit' => 'integer',
];
// 验证请求数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// 分页
$page = $postData['page'] ?? Constant::PAGING_DEFAULT_PAGE;
$limit = $postData['limit'] ?? Constant::PAGING_DEFAULT_LIMIT;
list($start, $perpage) = page_limit($page, $limit);
// 条件
$conds = [];
if (isset($postData['username'])) {
$conds['mem_username like ?'] = '%' . $postData['username'] . '%';
}
// 组织、岗位、角色转UID
$condUids = &Integral::instance()->getUids($postData);
if (!empty($postData['dp_ids']) || !empty($postData['job_ids']) || !empty($postData['role_ids'])) {
if (empty($condUids)) {
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => 0,
'list' => []
];
return true;
}
}
$conds['mem_uid'] = $condUids;
$medalServ = new MemberMedalService();
$list = $medalServ->list_by_conds($conds,null);
$all_uids = array_unique(array_filter(array_column($list, 'mem_uid')));
$page_uids=array_slice($all_uids,$start,$perpage);
// 去重列表
$unList = [];
// 按人员列表排序后的列表
$orderList = [];
if (!empty($list)) {
// 用户信息
$users = &User::instance()->listAll(['memUids' => $all_uids]);
$users = array_combine_by_key($users, 'memUid');
// 所有勋章
$medalModel = new MedalService();
$medalList = $medalModel->list_all();
$medalList = array_combine_by_key($medalList, 'im_id');
// 组织、岗位、角色、勋章
foreach ($list as $v) {
// 勋章
if (isset($medalList[$v['im_id']])) {
if (isset($unList[$v['mem_uid']])) {
$unList[$v['mem_uid']]['madel'][] = [
'name' => $medalList[$v['im_id']]['name'],
'num' => $v['im_total']
];
} else {
// 组织、岗位、角色
if (isset($users[$v['mem_uid']])) {
$dpInfo = $users[$v['mem_uid']]['dpName'];
$v['dp_name'] = array_column($dpInfo, 'dpName');
$v['job_name'] = $users[$v['mem_uid']]['memJob'];
$v['role_name'] = $users[$v['mem_uid']]['memRole'];
}
$v['madel'][] = [
'name' => $medalList[$v['im_id']]['name'],
'num' => $v['im_total']
];
$unList[$v['mem_uid']] = $v;
}
}
}
foreach ($page_uids as $uid) {
$orderList[] = $unList[$uid];
}
}
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => count($all_uids),
'list' => $orderList
];
return true;
}
}