ListController.class.php
2.36 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
<?php
/**
* 【业绩比拼-手机端】回帖列表接口
* User: daijun
* Date: 2017-11-04
*/
namespace Api\Controller\Comment;
use Common\Service\ActivityService;
use Common\Service\CommentService;
class ListController extends \Api\Controller\AbstractController
{
/** @var ActivityService */
protected $_activity_serv;
/** @var CommentService */
protected $_comment_serv;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化活动信息表
$this->_activity_serv = new ActivityService();
// 实例化回帖信息表
$this->_comment_serv = new CommentService();
return true;
}
public function Index_get()
{
// 获取参数
$params = I('get.');
if (empty($this->uid)) {
// 判断是否外部人员
E('_EMPTY_USER_ID');
}
$ac_id = $params['ac_id'];
if (empty($ac_id)) {
// 活动id不能为空
E('_EMPTY_ACTIVITY_ID');
}
// 默认值
$page = isset($params['page']) ? intval($params['page']) : ActivityService::DEFAULT_PAGE;
$limit = isset($params['limit']) ? intval($params['limit']) : ActivityService::DEFAULT_LIMIT;
// 分页
list($start, $limit) = page_limit($page, $limit);
// 查询条件
$conds = ['ac_id' => $ac_id, 'check_status' => ActivityService::CHECK_OK];
// 查询总记录数
$total = $this->_comment_serv->count_by_conds($conds);
$list = [];
if ($total > 0) {
// 排序:发布时间倒序
$order_option = ['check_time' => 'DESC'];
// 分页
$page_option = [$start, $limit];
// 查询字段
$fields = 'comment_id,ac_id,uid,content,pic_ids,check_time,likes,replys,ext_fields';
// 查询列表
$comm_list = $this->_comment_serv->list_by_conds($conds, $page_option, $order_option, $fields);
// 格式化列表数据
$list = $this->_comment_serv->format_comment_list($comm_list, $this->uid);
}
$this->_result = [
'total' => intval($total),
'limit' => intval($limit),
'page' => intval($page),
'list' => $list
];
return true;
}
}