MyListController.class.php
3.88 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
<?php
/**
* 【考试中心-手机端】34-我的考试列表接口
* MyListController.class.php
* @author: wanghuan
* @date: 2017-09-21
*/
namespace Api\Controller\Paper;
use Common\Service\PaperService;
use Common\Service\AnswerService;
class MyListController extends AbstractController
{
// 已参与
const JOIN_TYPE_JOINED = 1;
public function Index_post()
{
// 接收post参数
$params = I('post.');
$answer_serv = new AnswerService();
// 查询当前用户的答卷记录:条件1-》当前用户,条件2-》常规考试
$answer_list = $answer_serv->list_by_conds(['uid' => $this->uid, 'obj_id' => 0], null, [], 'ep_id');
if (empty($answer_list)) {
E('_ERR_DATA_NOT_EXIST');
}
// 已参加考试ep_id集合
$ep_ids = array_filter(array_unique(array_column($answer_list, 'ep_id')));
unset($answer_list);
// 实例化试卷service
$paper_s = new PaperService();
$conds = [
'exam_type' => PaperService::NOMAL_TYPE, // 试卷类型:常规试卷
'cate_status' => PaperService::EC_OPEN_STATES, // 分类未被禁用
'exam_status' => [PaperService::PAPER_PUBLISH, PaperService::PAPER_STOP], // 状态为已发布或者已终止
'ep_id' => $ep_ids
];
// 获取记录总数
$total = $paper_s->count_by_conds($conds);
$list = [];
// 记录总数不为空:有数据
if ($total) {
// 判断分页参数是否为空,为空赋默认值
$page = !empty($params['page']) ? intval($params['page']) : self::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : self::DEFAULT_LIMIT;
// 分页
list($start, $limit) = page_limit($page, $limit);
$conds['uid'] = $this->uid;
$conds['join_type'] = self::JOIN_TYPE_JOINED; // 参与类型(0:未参与,1:已参与)
// 分页参数
$page_option = [$start, $limit];
// 排序:最后更新时间倒序
$order_option = [
'last_time' => 'DESC'
];
// 获取列表数据
$list = $paper_s->paper_api_list($conds, $page_option, $order_option);
} else {
// 没有数据,返回提示"暂无信息"
E('_ERR_DATA_NOT_EXIST');
}
// 返回数据不为空
if (!empty($list)) {
// 格式化
$list = $paper_s->paper_format($list, self::JOIN_TYPE_JOINED, $this->uid);
}
// 实例化答卷service
$answer_s = new AnswerService();
// 统计数据查询条件
$conditions = [
'uid' => $this->uid,
'my_time > ?' => 0,
'obj_id' => 0
];
// 【参与考试次数】(模拟试卷可以多次参与)
$join_count = $answer_s->count_by_conds($conditions);
// 追加查询条件:考试通过
$conditions['my_is_pass'] = AnswerService::PASS;
// 【通过考试次数】
$pass_count = $answer_s->count_by_conds($conditions);
// 追加查询条件:已批阅
$conditions['answer_status'] = AnswerService::READ_OVER;
unset($conditions['my_is_pass']);
// 已批阅答卷列表
$done_list = $answer_s->list_by_conds($conditions);
// 【完成试卷数】(统计试卷数,模拟试卷去重处理)
$done_count = count(array_unique(array_column($done_list, 'ep_id')));
// 返回结果
$this->_result = [
'join_count' => intval($join_count),
'pass_count' => intval($pass_count),
'done_count' => intval($done_count),
'page' => intval($page),
'limit' => intval($limit),
'total' => intval($total),
'list' => $list
];
}
}