ListController.class.php
1.78 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
<?php
/**
* ListController.class.php
* 收藏列表
* @author Deepseath
* @version $Id$
*/
namespace Api\Controller\Collection;
use Common\Service\CommonCollectionService;
class ListController extends AbstractController
{
// 默认分页参数
const DEFAULT_LIMIT = 15;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
return true;
}
/**
* 获取收藏列表
*
* @return array
*/
public function Index()
{
$params = I('post.');
// 每页条数
$limit = empty($params['limit']) ? self::DEFAULT_LIMIT : intval($params['limit']);
$page = empty($params['page']) ? 1 : $params['page'];
list($start, $limit, $page) = page_limit($page, $limit);
// 分页参数
$page_option = array($start, $limit);
// 排序参数
$order_option = ['c_time'=>'DESC'];
$collectionService = new CommonCollectionService();
// 组装查询条件
$where['uid'] = $this->uid;
// 查询指定应用
if (!empty($params['app'])) {
$where['app_dir'] = $params['app'];
}
if (!empty($params['title'])) {
$where['title like ?'] = "%" . $params['title'] . "%";
}
// 查询总数
$total = $collectionService->count_by_conds($where);
// 获取列表
$list = $collectionService->list_by_conds($where, $page_option, $order_option);
$list = $collectionService->formate_list($list);
// 返回数据
$this->_result = array(
'page' => $page,
'limit' => $limit,
'total' => intval($total),
'list' => $list,
);
return true;
}
}