MockJoinListController.class.php
5.73 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* 【考试中心-后台】获取模拟考试统计详情已参与列表接口
* MockJoinListController.class.php
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-24 15:18:25
* @version $Id$
*/
namespace Apicp\Controller\Answer;
use Common\Common\User;
use Common\Service\PaperService;
use Common\Service\RightService;
use Common\Service\AnswerService;
class MockJoinListController extends AbstractController
{
// 成绩升序
const SORT_ASC = 2;
/** @var PaperService */
protected $paper_serv;
/** @var RightService */
protected $right_serv;
/** @var AnswerService */
protected $answer_serv;
public function before_action($action = '')
{
if (parent::before_action($action) === false) {
return false;
}
// 实例化试卷service
$this->paper_serv = new PaperService();
// 实例化权限service
$this->right_serv = new RightService();
// 实例化答卷service
$this->answer_serv = new AnswerService();
// 用户信息初始化
$this->user = User::instance();
return true;
}
public function Index_post()
{
// 接收post参数
$params = I('post.');
// 参数为空,返回提示"参数不能为空"
if (empty($params)) {
E('_ERR_PARAMS_NOT_NULL');
}
// 获取试卷ID
$ep_id = rintval($params['ep_id']);
if (empty($ep_id)) {
E('_EMPTY_EP_ID');
}
// 试卷详情
$paper = $this->paper_serv->get($ep_id);
// 试卷不存在
if (empty($paper)) {
E('_ERR_PAPER_NOT_FOUND');
}
// 试卷类型不是模拟试卷
if ($paper['paper_type'] != PaperService::SIMULATION_PAPER_TYPE) {
E('_ERR_PAPER_TYPE_EVALUATION');
}
// 获取未参加人数
$un_total = $this->answer_serv->get_un_total($ep_id, $paper, $params);
// 默认值
$page = !empty($params['page']) ? intval($params['page']) : PaperService::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : PaperService::DEFAULT_LIMIT_ADMIN;
// 分页
list($start, $limit) = page_limit($page, $limit);
$page_option = [$start, $limit];
// 排序
$sort = $params['sort'];
// 成绩升序
if (self::SORT_ASC == $sort) {
$order_by = [
'my_max_score' => 'ASC',
'my_time' => 'ASC'
];
} else { // 成绩降序
$order_by = [
'my_max_score' => 'DESC',
'my_time' => 'ASC'
];
}
// 组装查询条件
$conds = $this->answer_serv->get_conditions($paper, $params);
// 【考试完成时间】
if (isset($params['end_time']) && !empty($params['end_time']) && is_array($params['end_time'])) {
$end_time = $params['end_time'];
$end_time1 = $end_time[0];
$end_time2 = $end_time[1];
if ($end_time1 && $end_time2) {
$conds['my_end_time>=?'] = $end_time1;
$conds['my_end_time<=?'] = $end_time2;
}
}
// 统计参与的人数
$total = $this->answer_serv->count_mock_answer($conds);
$join = [];
if ($total) {
// 返回字段
$fields = 'uid,my_score,my_time,ea_id,my_begin_time,my_end_time';
// 参与这场考试的人员的考试信息
$join = $this->answer_serv->get_mock_join_list($conds, $page_option, $order_by, $fields);
if (!empty($join)) {
// 参与考试的所有人的UID
$uids = array_column($join, 'uid');
// 参与考试的人员的详细信息列表
$user_list = $this->answer_serv->getUser($uids);
// 格式化返回字段信息
foreach ($join as $key => &$val) {
$val['ranking'] = ($page - 1) * $limit + ($key + 1);
$val['username'] = $user_list[$val['uid']]['memUsername'];
// 获取用户部门信息
$dpNames = '';
if($user_list[$val['uid']]['dpName']){
$res_dpNames = array_column($user_list[$val['uid']]['dpName'], 'dpName');
if (!empty($res_dpNames)) {
$dpNames = implode(';', $res_dpNames);
}
}
$val['dpName'] = $dpNames;
$val['memJob'] = $user_list[$val['uid']]['memJob'];
$val['memRole'] = $user_list[$val['uid']]['memRole'];
$val['memTag'] = $user_list[$val['uid']]['memTag'];
$val['begin_time'] = $val['my_begin_time'];
$val['end_time'] = $val['my_end_time'];
}
}
}
// 去除条件
unset(
$params['page'],
$params['limit'],
$params['ep_id'],
$params['sort']
);
if (count(array_filter($params)) == 0 && ($un_total != $paper['unjoin_count'] || $total['join_count'] != $paper['join_count'])) {
// 更新试卷表中缓存的未参与人数
$this->paper_serv->update_by_conds(['ep_id' => $ep_id],
[
'unjoin_count' => $un_total,
'join_count' => $total
]
);
}
$this->_result = [
'join_total' => (int)$total,
'un_total' => (int)$un_total,
'limit' => (int)$limit,
'page' => (int)$page,
'list' => $join
];
}
}