PaperListController.class.php
2.47 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
<?php
/**
* 【考试中心-后台】获取激励试卷列表
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-06-01 17:47:52
* @version $Id$
*/
namespace Apicp\Controller\Encourage;
use Common\Service\PaperService;
use Common\Service\CategoryService;
class PaperListController extends AbstractController
{
/** @var PaperService 实例化试卷表对象 */
protected $paper_service;
/** @var CategoryService 实例化试卷分类表对象 */
protected $cate_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->paper_service = new PaperService();
$this->cate_service = new CategoryService();
return true;
}
public function Index_post()
{
$params = I('post.');
// 每页条数
$limit = empty($params['limit']) ? 10 : intval($params['limit']);
$page = empty($params['page']) ? 1 : $params['page'];
list($start, $limit, $page) = page_limit($page, $limit);
// 分页参数
$page_option = [$start, $limit];
$conds = [
'cate_status' => PaperService::EC_OPEN_STATES,
'exam_status' => PaperService::PAPER_PUBLISH,
'end_time > ?' => MILLI_TIME
];
if (!empty($params['ec_id'])) {
// 分类id不为空
$conds['ec_id'] = intval($params['ec_id']);
}
if (!empty($params['title'])) {
// 标题关键字不为空
$conds['ep_name like ?'] = '%' . $params['title'] . '%';
}
// 查询总数
$count = $this->paper_service->count_by_conds($conds);
$paper_list = [];
if ($count) {
// 排序参数,最后更新时间倒序
$order_option = ['last_time' => 'DESC'];
// 查询列表
$paper_list = $this->paper_service->list_by_conds($conds, $page_option, $order_option, 'ep_id,ep_name,ec_id');
}
$cate_list = $this->cate_service->list_all();
$cate_list = array_combine_by_key($cate_list, 'ec_id');
foreach ($paper_list as &$v) {
$v['ep_id'] = intval($v['ep_id']);
$v['ec_name'] = $cate_list[$v['ec_id']]['ec_name'];
}
$this->_result = [
'page' => intval($page),
'limit' => intval($limit),
'total' => $count,
'list' => $paper_list
];
return true;
}
}