LikeListController.class.php
2.25 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
<?php
/**
* LikeListController.class.php
* 话题点赞列表
* User: 代军
* Date: 2018年6月28日
*/
namespace Apicp\Controller\Topic;
use Common\Service\CircleService;
use Common\Service\LikeService;
class LikeListController extends AbstractController
{
/**
* @var LikeService 点赞信息表
*/
protected $_like_serv;
/**
* @var CircleService 同事圈信息表
*/
protected $_circle_serv;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化点赞信息表
$this->_like_serv = new LikeService();
// 实例化同事圈信息表
$this->_circle_serv = new CircleService();
return true;
}
public function Index_post()
{
// 获取数据
$params = I('post.');
// 参数验证
if (empty($params['id'])) {
$this->_set_error('_EMPTY_ID');
return false;
}
// 参数有效性验证
$data = $this->_circle_serv->get($params['id']);
if (empty($data)) {
$this->_set_error('_ERR_DATA_EXIST');
return false;
}
// 每页条数
$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);
// 查询条件
$cond = array('cid' => $params['id']);
// 分页参数
$page_option = array($start, $limit);
// 排序参数
$order_option = array('like_id' => 'DESC');
// 查询总数
$total = $this->_like_serv->count_by_conds($cond);
// 获取列表
$list = [];
if ($total > 0) {
$list = $this->_like_serv->list_by_conds($cond, $page_option, $order_option, 'like_id,created,uid');
// 格式化列表数据
$this->_like_serv->format_like_data($list);
}
// 返回数据
$this->_result = array(
'page' => intval($page),
'limit' => intval($limit),
'total' => intval($total),
'list' => $list,
);
return true;
}
}