InfoController.class.php
2.59 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
<?php
/**
* 【考试中心-手机端】28-获取阅卷人查看测评试卷(已参与)详情接口
* InfoController.class.php
* @author: 蔡建华
* @date: 2017-06-19
*/
namespace Api\Controller\Answer;
use Common\Service\PaperService;
use Common\Service\AnswerService;
use Common\Service\CategoryService;
class InfoController extends AbstractController
{
public function Index_post()
{
// 接收post参数
$params = I('post.');
// 试卷id
$ep_id = intval($params['ep_id']);
// 答卷id
$ea_id = intval($params['ea_id']);
// 试卷ID和答卷ID不能同时为空且不能同时大于0
if ((empty($ep_id) && empty($ea_id)) || (!empty($ep_id) && !empty($ea_id))) {
E('_ERR_EA_EP_SOME');
}
// 答卷查询条件:(当前)用户id、答卷状态(待批阅、已批阅)
$answer_conds = [
'uid' => $this->uid,
'answer_status>=?' => AnswerService::READ_WAITING // 批阅状态 0初始化 [1待批阅 2已批阅]
];
// 试卷id不为空
if ($ep_id) {
// 追加答卷查询条件:试卷id
$answer_conds['ep_id'] = $ep_id;
} else {
// 追加答卷查询条件:答卷id
$answer_conds['ea_id'] = $ea_id;
}
// 实例化答卷service
$answer_s = new AnswerService();
// 根据试卷id或答卷id查询当前用户的待批阅、已批阅的答卷
$answer = $answer_s->get_by_conds($answer_conds);
// 没有符合条件的答卷,返回提示"答卷不存在"
if (empty($answer)) {
E('_ERR_COUNT_EMPTY_FOR_VOICE');
}
// 实例化试卷service
$paper_s = new PaperService();
// 有符合条件的答卷,获取该答卷的试卷id
$ep_id = $answer['ep_id'];
// 根据试卷id获取试卷数据
$data = $paper_s->get($ep_id);
// 试卷数据不存在,返回提示"试卷信息不存在"
if (empty($data)) {
E('_EMPTY_PAPER_DATA');
}
// 试卷数据存在,该试卷所属的试卷类别被禁用,返回提示"试卷分类已经被禁用"
if (CategoryService::EC_CLOSE_STATES == $data['cate_status']) {
E('_EMPTY_CATE_DATA');
}
// 格式化试卷信息
$result = $paper_s->format_paper_detail($data,$this->uid);
// 批阅状态(1:待批阅,2:已批阅)
$result['answer_status'] = intval($answer['answer_status']);
// 返回结果
$this->_result = $result;
}
}