UserListController.class.php
2.52 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
<?php
/**
* 考生列表接口
* User: yingcai
* Date: 2018/4/11
* Time: 下午2:05
*/
namespace Api\Controller\Marking;
use Common\Common\User;
use Common\Service\AnswerService;
class UserListController extends AbstractController
{
public function Index_post()
{
// 接收post参数
$params = I('post.');
$ep_id = intval($params['ep_id']);
if (!$ep_id) {
E('_EMPTY_EP_ID');
}
$page = !empty($params['page']) ? intval($params['page']) : self::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : self::DEFAULT_LIMIT;
// 查询条件
$conds = [
'ep_id' => $ep_id,
'marking_uid' => $this->uid,
];
// 【员工名称】
if (isset($params['username']) && $params['username']) {
$user_conds = ['memUsername' => $params['username']];
$user = User::instance();
// 查询
$sel_users = $user->listAll($user_conds);
$memUserids = '';
// 检索员工存在
if (!empty($sel_users)) {
// 员工id
$memUserids = array_column($sel_users, 'memUid');
}
$conds['uid'] = $memUserids;
}
// 排序
$order_option = ['my_end_time' => 'ASC'];
// 分页
list($start, $limit) = page_limit($page, $limit);
$page_option = [$start, $limit];
// 查询的字段
$fields = 'ea_id,uid,my_score,my_is_pass,my_end_time,is_makeup';
$answer_serv = new AnswerService();
// 统计总数
$total = $answer_serv->count_by_conds($conds);
// 初始化列表数据
$list = [];
if ($total) {
// 获取列表
$list = $answer_serv->list_by_conds($conds, $page_option, $order_option, $fields);
// 考生UID列表
$uids = array_column($list, 'uid');
// 获取考试信息
$user = User::instance();
$users_info = $user->listUsersAll([
'memUids' => $uids,
'memAll' => 1,
]);
// 组装用户信息
foreach ($list as &$val) {
$val['username'] = $users_info[$val['uid']]['memUsername'];
}
}
// 返回数据
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => $total,
'list' => $list,
];
return true;
}
}