ListController.class.php
4.24 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
<?php
/**
* 【考试中心-手机端】批阅列表接口
* ListController.class.php
* @author: 蔡建华
* @date: 2017-06-19
*/
namespace Api\Controller\Marking;
use Common\Service\AnswerService;
use Common\Service\PaperService;
use Common\Service\RightService;
class ListController extends AbstractController
{
/** @var PaperService 实例化试卷对象 */
protected $paper_service;
/** @var AnswerService 实例化答卷表对象 */
protected $answer_service;
/** @var RightService 实例化权限表对象 */
protected $right_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->paper_service = new PaperService();
$this->answer_service = new AnswerService();
$this->right_service = new RightService();
return true;
}
public function Index_post()
{
// 接收post参数
$params = I('post.');
$mk_type = rintval($params['mk_type']);
if ($mk_type != PaperService::READ_WAITING) {
$mk_type = PaperService::READ_OVER;
}
if (!in_array($mk_type, [PaperService::READ_WAITING, PaperService::READ_OVER])) {
// 无效的批阅类型
E('_ERR_MARK_TYPE_INTEGRAL');
}
$page = !empty($params['page']) ? intval($params['page']) : self::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : self::DEFAULT_LIMIT;
// 查询条件
$conds = [];
// 排序
$order_option = [];
// 分页
list($start, $limit) = page_limit($page, $limit);
$page_option = [$start, $limit];
// 待阅卷
if (PaperService::READ_WAITING == $mk_type) {
// 获取当前登陆用户有权限批阅的试卷 ep_id 集合
$conds = [
'er_type' => RightService::RIGHT_MARKING,
'uid' => $this->uid,
];
$right = $this->right_service->list_by_conds($conds, [], [], 'epc_id');
$right_ep_ids = array_column($right, 'epc_id');
if (empty($right_ep_ids)) {
// 没有可批阅的试卷
return true;
}
$conds = [
'answer_status' => PaperService::READ_WAITING,
'ep_id' => $right_ep_ids,
];
}
// 已批阅
if (PaperService::READ_OVER == $mk_type) {
$conds = [
'answer_status' => PaperService::READ_OVER,
'marking_uid' => $this->uid,
];
}
$mark_list = $this->answer_service->list_marking_paper($conds, [], $order_option);
// 批阅列表为空时,直接返回
if (empty($mark_list)) {
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => 0,
'list' => [],
];
return true;
}
$mark_list = array_combine_by_key($mark_list, 'ep_id');
// 获取试卷名称、考试时间、参加人数
$ep_ids = array_column($mark_list, 'ep_id');
$conds = ['ep_id' => $ep_ids, 'cate_status' => PaperService::EC_OPEN_STATES];
$total = $this->paper_service->count_by_conds($conds);
$list = [];
if ($total) {
$fields = 'ep_id,ep_name,begin_time,end_time,join_count,exam_status';
$paper_list = $this->paper_service->list_by_conds($conds, $page_option, ['last_time' => 'DESC'], $fields);
// 组装数据
foreach ($paper_list as $v) {
$res = $mark_list[$v['ep_id']];
$res['ep_name'] = $v['ep_name'];
$res['join_count'] = $v['join_count'];
// 转换考试状态
$res['paper_status'] = $this->paper_service->paper_status($v['exam_status'], $v['begin_time'], $v['end_time']);
$res['end_time'] = $v['end_time'];
$list[] = $res;
}
}
// 返回结果
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => $total,
'list' => $list,
];
return true;
}
}