ListController.class.php
1.9 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
<?php
/**
* 【考试中心-手机端】12-考试排名列表接口
* ListController.class.php
* @author: 蔡建华
* @date: 2017-05-23
*/
namespace Api\Controller\Rank;
use Common\Service\AnswerService;
class ListController extends AbstractController
{
public function Index_post()
{
// 接收post参数
$params = I('post.');
// 试卷id
$ep_id = intval($params['ep_id']);
// 试卷id为空,返回提示"试卷ID不能为空"
if (!$ep_id) {
E('_EMPTY_EP_ID');
}
// 答卷id
$ea_id = 0;
if (isset($params['ea_id']) && $params['ea_id']) {
$ea_id = intval($params['ea_id']);
}
// 实例化答卷service
$answer_s = new AnswerService();
// 答卷id不为空
if ($ea_id) {
// 答卷详情
$answer_info = $answer_s->get($ea_id);
// 答卷用户id
$uid = $answer_info['uid'];
} else {
// 答卷id为空,取当前用户id
$uid = $this->uid;
}
// 判断分页参数是否为空,为空赋默认值
$page = !empty($params['page']) ? intval($params['page']) : self::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : self::DEFAULT_LIMIT;
// 查询用户试卷的排名记录
$data = $answer_s->answer_list_all($ep_id, $uid, $page, $limit);
// 记录总数
$total = $data['total'];
// 数据为空,返回提示"暂无信息"
if (!$total) {
E('_ERR_DATA_NOT_EXIST');
}
// 返回数据
$this->_result = [
'ranking' => $data['ranking'],
'memFace' => $data['memFace'],
'page' => intval($page),
'limit' => intval($limit),
'total' => intval($total),
'list' => $data['list']
];
}
}