ListController.class.php
2.87 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
100
101
102
103
104
105
106
<?php
/**
* ListController.class.php
* 同事圈列表
* User: 代军
* Date: 2017-04-24
*/
namespace Apicp\Controller\Topic;
use Common\Common\Constant;
use Common\Service\CircleService;
use Common\Service\SettingService;
class ListController extends AbstractController
{
/**
* @var CircleService 帖子信息表
*/
protected $_circle_serv;
/**
* @var SettingService 同事圈配置表
*/
protected $settingServ;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化信息同事圈帖子信息表
$this->_circle_serv = new CircleService();
// 实例化同事圈配置表
$this->settingServ = new SettingService();
return true;
}
public function Index_post()
{
// 接收参数
$params = I('post.');
// 如果状态值为空或者状态值不符合规范
if ((empty($params['audit_state']) &&
!is_numeric($params['audit_state'])) || (intval($params['audit_state']) > CircleService::CIRCLE)) {
$this->_set_error('_ERR_AUDIT_STATE');
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);
// 分页参数
$page_option = array($start, $limit);
// 排序参数
$order_option = array('id' => 'DESC');
// 组装查询条件
$where = $this->_circle_serv->get_where_conds($params);
$where['type']=Constant::CIRCLE_TOPIC_TYPE;
// 查询总数
$total = $this->_circle_serv->count_by_conds($where);
// 待审核数
$pendingReview = $this->_circle_serv->count_by_conds(
array_merge(
$where,
[
'audit_state' => CircleService::AUDIT_ING
]
));
// 获取列表
$list = [];
if ($total > 0) {
$feild = " *,case when audit_time>0 then audit_time else created end as a_time";
$list = $this->_circle_serv->list_by_conds($where, $page_option, $order_option, $feild);
// 格式化列表数据
$this->_circle_serv->format_list_data($list);
}
// 加入是否开启审核信息
$is_open_check = $this->settingServ->get_by_conds(['key' => 'is_topic_check']);
// 返回数据
$this->_result = array(
'page' => $page,
'limit' => $limit,
'total' => intval($total),
'list' => $list,
'pending_review' => $pendingReview,
'is_open_check' => rintval($is_open_check['value']),
);
return true;
}
}