ResolveController.class.php
2.93 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
<?php
/**
* 【考试中心-手机端】查看答案解析接口
* ResolveController.class.php
* @author: 蔡建华
* @date: 2017-05-23
*/
namespace Api\Controller\Answer;
use Common\Service\PaperService;
use Common\Service\AnswerService;
use Common\Service\AnswerDetailService;
class ResolveController extends AbstractController
{
public function Index_post()
{
// 接收post参数
$params = I('post.');
// 答卷id
$ea_id = intval($params['ea_id']);
// 答卷id为空,返回提示"答卷ID不能为空"
if (!$ea_id) {
E('_EMPTY_EA_ID');
}
// 实例化答卷service
$answer_s = new AnswerService();
// 根据答卷id获取答卷数据
$answer_info = $answer_s->get($ea_id);
// 答卷数据为空,返回提示"试卷信息不存在"
if (empty($answer_info)) {
E('_EMPTY_PAPER_DATA');
}
// 判断分页参数是否为空,为空赋默认值
$page = !empty($params['page']) ? intval($params['page']) : self::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : self::DEFAULT_LIMIT_ONE;
// 分页
list($start, $limit) = page_limit($page, $limit);
// 答题状态
$type = intval($params['type']);
// 查询条件:答卷id
$conditions = [
'ea_id' => $ea_id,
];
// 答题状态为答题通过
if (AnswerService::MY_PASS == $type) {
// 查询条件追加答题状态:未作答、未通过
$conditions['is_pass'] = [AnswerService::MY_PASS, AnswerService::MY_PASS_INIT];
}
// 实例化答卷详情service
$answer_detail_s = new AnswerDetailService();
// 根据答卷id,获取未作答和未通过的答卷总数
$total = $answer_detail_s->count_by_conds($conditions);
$list = [];
// 总数不为空:数据存在
if ($total) {
// 排序:序号正序
$order_option['order_num'] = 'ASC';
// 根据答卷id,查询未作答和未通过的答卷详情数据列表
$list = $answer_detail_s->list_by_conds($conditions, [$start, $limit], $order_option);
}
// 实例化试卷service
$paper_s = new PaperService();
// 根据试卷id获取试卷详情
$paper = $paper_s->get($answer_info['ep_id']);
// 格式化返回数据
$list_data = $answer_detail_s->question_list_format($list, $paper['marking_type'],
AnswerDetailService::ANSWER_FRONTEND_ANALYSIS);
// 返回结果
$this->_result = [
'total' => intval($total),
'limit' => intval($limit),
'ep_name' => $paper['ep_name'],
'ep_id' => $paper['ep_id'],
'ea_id' => $answer_info['ea_id'],
'page' => intval($page),
'list' => $list_data
];
}
}