CircleModel.class.php
5.45 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/**
* 同事圈信息表
* User: 代军
* Date: 2017-04-24
*/
namespace Common\Model;
use Common\Common\Constant;
class CircleModel extends AbstractModel
{
// 有附件
const ATTACH = 1;
// 无附件
const NOT_ATTACH = 0;
// 标识
const CIRCLE_PID = 0;
//帖子标识
const CIRCLE_MATE = 0;
//话题标识
const CIRCLE_TOPIC =1;
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 获取帖子列表的评论数据
* @param array $ids 帖子ID集合
* @param int $audit_state 评论数据的状态
* @param null $page_option 分页数据
* @param array $order_option 排序数据
* @return array|bool
*/
public function get_comment_num($ids=[], $audit_state, $page_option = null, $order_option = [])
{
$where = ' domain=? AND status<? AND pid in(?) AND audit_state=? ';
$params = array(QY_DOMAIN, self::ST_DELETE, $ids, $audit_state);
$sql = 'SELECT pid, COUNT( * ) as total FROM __TABLE__ WHERE ' . $where . " GROUP BY pid ";
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
// 排序
$order_by = '';
if (!$this->_order_by($order_by, $order_option)) {
return false;
}
return $this->_m->fetch_array($sql . $order_by . $limit, $params);
}
/**
* 【微信端】 获取评论列表根据点赞倒序
* @param array $conditions 查询条件
* @param array $page_option 分页参数
* @param array $order_by 排序字段
* @param string $file 默认搜索字段
* @return mixed
*/
public function list_by_comment($conditions = [], $page_option = [], $order_option = [], $file = '*')
{
$sql = "SELECT {$file},(SELECT COUNT(*) from oa_workmate_like WHERE cid=`id` AND domain=? AND status<? ) as like_total FROM __TABLE__ WHERE ";
// 初始化like_total条件
$params[] = QY_DOMAIN;
$params[] = self::ST_DELETE;
// 如果状态存在
if (is_numeric($conditions['audit_state'])) {
$where[] = 'audit_state=?';
$params[] = $conditions['audit_state'];
}
$where[] = 'pid=?';
$params[] = $conditions['pid'];
$where[] = 'domain=?';
$where[] = 'status<?';
$params[] = QY_DOMAIN;
$params[] = self::ST_DELETE;
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
// 默认排序
$order = array(
'like_total' => 'DESC',
'audit_time' => 'DESC',
'created' => 'DESC'
);
// 如果有其他排序
if (!empty($order_option)) {
$order = array_merge($order, $order_option);
}
// 排序
$order_by = '';
if (!$this->_order_by($order_by, $order)) {
return false;
}
return $this->_m->fetch_array($sql . implode(' AND ', $where) . $order_by . $limit, $params);
}
/**
* 【微信端】 获取评论列表根据点赞倒序
* @param array $conditions 查询条件
* @return mixed
*/
public function topic_count_by_conds($conditions = [])
{
list($where,$params)=$this->get_topic_where($conditions);
$sql = "SELECT COUNT(*) as total FROM __TABLE__ WHERE ";
return $this->_m->fetch_row($sql. implode(' AND ', $where) , $params);
}
/**
* 【微信端】 获取评论列表根据点赞倒序
* @param array $conditions 查询条件
* @param array $page_option 分页参数
* @param array $order_by 排序字段
* @param string $file 默认搜索字段
* @return mixed
*/
public function topic_list_by_conds($conditions = [], $page_option = [], $order_option = [], $file = '*')
{
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
// 排序
$order_by = '';
if (!$this->_order_by($order_by, $order_option)) {
return false;
}
list($where,$params)=$this->get_topic_where($conditions);
$sql = "SELECT {$file} FROM __TABLE__ WHERE ";
return $this->_m->fetch_array($sql . implode(' AND ', $where) . $order_by . $limit, $params);
}
/**
* 组装话题搜索条件
* @param $conditions
* @return array
*/
protected function get_topic_where($conditions){
// 如果状态存在
if (isset($conditions['audit_state'])) {
$where[] = 'audit_state=?';
$params[] = $conditions['audit_state'];
}
// 上级ID
if(isset($conditions['pid'])){
$where[] = 'pid=?';
$params[] = $conditions['pid'];
}
// 类型
if(!empty($conditions['type'])) {
$where[] = 'type=?';
$params[] = $conditions['type'];
}
// 如果存在数据
if(!empty($conditions['id'])){
$where[] = '(is_all=1 OR id in (?))';
$params[] = $conditions['id'];
}else{
$where[] = 'is_all=?';
$params[] = '1';
}
$where[] = 'domain=?';
$where[] = 'status<?';
$params[] = QY_DOMAIN;
$params[] = self::ST_DELETE;
return [$where,$params];
}
}