ListController.class.php
2.35 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
<?php
/**
* 【考试中心-手机端】考试作答情况列表接口
* ListController.class.php
* @author: 蔡建华
* @date: 2017-05-23
*/
namespace Api\Controller\Answer;
use Common\Service\AnswerDetailService;
class ListController extends AbstractController
{
public function Index_post()
{
// 接收post参数
$params = I('post.');
// 类型
$type = intval($params['type']);
// 答卷id
$ea_id = intval($params['ea_id']);
// 答卷id为空,返回提示"答卷ID不能为空"
if (!$ea_id) {
E('_EMPTY_EA_ID');
}
// 实例化答卷详情service
$answer_detail_s = new AnswerDetailService();
// 查询条件:答卷id
$detail_conds['ea_id'] = $ea_id;
// 根据答卷id查询总数
$total = $answer_detail_s->count_by_conds($detail_conds);
// 初始化未答题数
$un_answer_num = 0;
$data = [];
// 答题数据不为空,获取答卷数据
if ($total) {
// 根据答卷id获取答卷详情列表数据
$data_detail = $answer_detail_s->list_by_conds($detail_conds);
// 答卷详情数据为空,返回提示"暂无信息"
if (empty($data_detail)) {
E('_ERR_DATA_NOT_EXIST');
}
// 未答题查询条件:答卷id,作答状态:未作答
$un_detail_conds = [
'ea_id' => $ea_id,
'is_status' => AnswerDetailService::DO_PASS_STATE
];
// 根据答卷id查询未答题的数量
$un_answer_num = $answer_detail_s->count_by_conds($un_detail_conds);
// 获取试题状态列表
$data = $answer_detail_s->get_answer_detail($data_detail, $type);
} else {
// 返回提示"试卷信息不存在"
E('_EMPTY_PAPER_DATA');
}
// 类型为错题解析,统计总数
if (AnswerDetailService::ANSWER_TYPE_ERR_ANALYSIS == $type) {
$total = count($data);
}
// 返回结果
$this->_result = [
'total' => intval($total),
'unanswer_num' => intval($un_answer_num), // 未答题总数
'answer_num' => $total - intval($un_answer_num), // 答题总数
'list' => $data
];
}
}