ListController.class.php
5.15 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
<?php
/**
* Created by PhpStorm.
* User: yingcai
* Date: 2018/4/4
* Time: 上午10:20
*/
namespace Apicp\Controller\Check;
use Common\Common\User;
use Common\Service\AnswerService;
use Common\Service\PaperService;
class ListController extends AbstractController
{
protected $_require_login = false;
// 阅卷列表类型:待批阅
const CHECK_TYPE_MARKING_FALSE = 1;
// 阅卷列表类型:已批阅
const CHECK_TYPE_MARKING_TRUE = 2;
// 阅卷列表类型
const CHECK_TYPE_MARKING = [
self::CHECK_TYPE_MARKING_FALSE,
self::CHECK_TYPE_MARKING_TRUE
];
public function Index_post()
{
$params = I('post.');
$ep_id = intval($params['ep_id']);
$type = intval($params['type']);
// 试卷ID不能为空
if (!$ep_id) {
E('_EMPTY_EP_ID');
}
// 批阅类型不能为空
if (!$type) {
E('_EMPTY_CHECK_TYPE');
}
// 无效的批阅类型
if (!in_array($type, self::CHECK_TYPE_MARKING)) {
E('_ERR_CHECK_TYPE_INVALID');
}
$paper_serv = new PaperService();
// 试卷详情
$paper = $paper_serv->get($ep_id);
// 试卷不存在
if (empty($paper)) {
E('_ERR_PAPER_NOT_FOUND');
}
// 组装查询条件
$answer_serv = new AnswerService();
// 查询条件初始化
$conditions = [
'ep_id' => $ep_id,
'my_time > ?' => 0,
];
if (self::CHECK_TYPE_MARKING_FALSE == $type) {
// 待批阅
$conditions['answer_status'] = AnswerService::READ_WAITING;
} else {
// 已批阅
$conditions['answer_status'] = AnswerService::READ_OVER;
// 阅卷人不能为空
$conditions['marking_uid<>?'] = '';
}
// 根据部门、岗位、角色、员工名称获取用户的uid集合
$djr_uids = $answer_serv->get_dp_job_role_uids($params, $ep_id);
if (!empty($djr_uids)) {
$conditions['uid'] = $djr_uids;
}
// 交卷时间
if ($params['begin_time'] && $params['end_time']) {
$conditions['my_begin_time >= ?'] = $params['begin_time'];
$conditions['my_end_time <= ?'] = $params['end_time'];
}
// 初始化返回列表
$list = [];
// 统计列表总数
$total = $answer_serv->count_by_conds($conditions);
// 分页默认值
$page = !empty($params['page']) ? intval($params['page']) : PaperService::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : PaperService::DEFAULT_LIMIT_ADMIN;
if ($total) {
// 分页
list($start, $limit) = page_limit($page, $limit);
// 分页参数
$page_option = [$start, $limit];
// 发布时间倒序
$order_option = ['ea_id' => 'DESC'];
// 需要查询的字段
$fields = 'ea_id,my_score,my_end_time,uid,marking_uid,marking_name';
$list = $answer_serv->list_by_conds($conditions, $page_option, $order_option, $fields);
$uids = array_column($list, 'uid');
// 获取用户信息
$user = User::instance();
$user_list = $user->listUsersAll(['memUids' => $uids]);
// 组装用户信息
foreach ($list as &$v) {
$uid = $v['uid'];
$dp_arr = array_column($user_list[$uid]['dpName'], 'dpName');
$v['username'] = $user_list[$uid]['memUsername'];
$v['dpName'] = implode(',', $dp_arr);
$v['memJob'] = $user_list[$uid]['memJob'];
$v['memRole'] = $user_list[$uid]['memRole'];
if ($v['marking_name'] || $v['marking_uid']) {
if (!$v['marking_name']) {
$marking_user_info = $user->getByUid($v['marking_uid']);
$v['marking_name'] = $marking_user_info['memUsername'];
}
} else {
$v['marking_name'] = '系统';
}
}
}
// 计算已批阅数和未批阅数
if (self::CHECK_TYPE_MARKING_FALSE == $type) {
$un_total = $total;
// 已批阅
$conditions['answer_status'] = AnswerService::READ_OVER;
// 阅卷人不能为空
$conditions['marking_uid<>?'] = '';
// 获取已批阅试卷总和
$check_total = $answer_serv->count_by_conds($conditions);
} else {
$check_total = $total;
// 已批阅
$conditions['answer_status'] = AnswerService::READ_WAITING;
unset($conditions['marking_uid<>?']);
// 获取待批阅试卷总和
$un_total = $answer_serv->count_by_conds($conditions);;
}
$this->_result = [
'check_total' => intval($check_total),
'un_total' => intval($un_total),
'limit' => $limit,
'page' => $page,
'list' => $list,
];
return true;
}
}