HouseBoard.php
12.3 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/7/10
* Time: 17:32
*/
namespace app\api\controller;
use app\common\controller\Api;
use think\Cache;
use think\Db;
use think\Validate;
/**
* 社区公告
*/
class HouseBoard extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (社区公告-首页)
* @ApiSummary (社区公告-首页)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"is_binding"://是否绑定1已绑定2未绑定
"house_name"://社区名称
"is_have"://是否有社区公告1有2没有
"title"://社区公告标题
"is_new"://是否是新 1是2否
"content"://公告内容
"look_num"://浏览人数
"createtime"://时间
}
})
*/
public function index()
{
$user_id = $this->auth->id;
$data = Db::name('user')->where('id',$user_id)->field('id,house_id')->find();
if(empty($data['house_id'])){
$info['is_binding'] = 2;
}else{
$info['is_binding'] = 1;
/*小区信息*/
$house = Db::name('house')
->where('id',$data['house_id'])
->field('image,name,thumbnail,bindnum')
->find();
// 消息红点
$message = Db::name('message')
->where('house_id',$data['house_id'])
->where('to_user_id',$user_id)
->where('is_read',2)
->field('id')
->find();
$house['have_message'] = !empty($message) ? 1 : 2;
$house['image'] = cdnurl($house['image'],true);
/*最新公告信息*/
$house_board = Db::name('house_board')
->where('house_id',$data['house_id'])
->order('createtime desc')
->field('id,title,content,look_num,createtime')
->find();
if(!empty($house_board)){
$house_board['createtime'] = date('Y-m-d',$house_board['createtime']);
// 查询是否已读
$is_read = Db::name('house_board_detail')
->where('user_id',$user_id)
->where('house_board_id',$house_board['id'])
->find();
$house_board['is_new'] = !empty($is_read) ? 1 : 2;
}
$info = array_merge($info,compact('house','house_board'));
}
$this->success('success',$info);
}
/**
* @ApiTitle (社区公告-业主信息)
* @ApiSummary (社区公告-业主信息)
* @ApiMethod (POST)
* @ApiRoute (/api/house/avatar)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_board_id", type="inter", required=true, description="公告id")
*
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://用户id
"avatar"://用户头像
}
})
*/
public function avatar()
{
(new House)->avatar();
}
/**
* @ApiTitle (社区公告-轮播图)
* @ApiSummary (社区公告-轮播图)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_banner)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://id
"image"://图片
"url"://跳转地址
"typeswitch"://开关0关1开
"createtime"://创建时间
}
})
*/
public function banner()
{
$qiniu = get_addon_config('qiniu')['cdnurl'];
$data = Db::name('advertising')->field('updatetime',true)->order('createtime desc')->select();
foreach ($data as &$v){
$v['image'] = $qiniu.$v['image'];
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (公告列表)
* @ApiSummary (公告列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_board_list)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_board_id", type=inter, required=true, description="社区id")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://公告id
"title"://社区公告标题
"content"://公告内容
"look_num"://浏览人数
"createtime"://时间
"avatar"://用户头像
]
}
})
*/
public function house_board_list()
{
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$user_id = $this->auth->id;
$house_id = $this->request->param('house_board_id');
if(empty($house_id)){
$this->error('社区id不能为空');
}
$data['total_num'] = Db::name('house_board')
->where('house_id',$house_id)
->count();
$data['info'] = Db::name('house_board')
->where('house_id',$house_id)
->order('weigh desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
$v['createtime'] = date('Y-m-d',$v['createtime']);
//查询用户是否在已读公告详情中
$house_board_detail = Db::name('house_board_detail')
->where('user_id',$user_id)
->where('house_board_id',$v['id'])
->find();
if(empty($house_board_detail)){
$info['user_id'] = $user_id;
$info['house_board_id'] = $v['id'];
$info['createtime'] = time();
Db::name('house_board_detail')->insertGetId($info);
Db::name('house_board')->where('id',$v['id'])->setInc('look_num');
}
$v['avatar'] = Db::name('house_board_detail')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.house_board_id',$v['id'])
->field('b.avatar,b.id')
->limit(6)
->select();
}
$this->success('success',$data);
}
/**
* @ApiTitle (社区服务电话)
* @ApiSummary (社区服务电话)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_phone)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_id", type="string", required=true, description="小区id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://id
"name"://电话名称
"phone"://电话
}
})
*/
public function house_phone()
{
$user_id = $this->auth->id;
$house_id = $this->request->param('house_id');
if(empty($house_id)){
$this->error('缺少必要参数');
}
$data = Db::name('house_phone')->field('id,name,phone')->where('house_id',$house_id)->select();
$this->success('success',$data);
}
/**
* @ApiTitle (社区物业管理员列表)
* @ApiSummary (社区物业管理员列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_admin_list)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_id", type="string", required=true, description="小区id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://id
"user_id"://用户id
"avatar"://管理员头像
"nickname"://昵称
"is_have"://是否带有红标签 1有2没有
}
})
*/
public function house_admin_list()
{
$user_id = $this->auth->id;
$house_id = $this->request->param('house_id');
if(empty($house_id)){
$this->error('缺少必要参数');
}
$data = Db::name('house_admin')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.house_id',$house_id)
->field('a.id,a.user_id,b.avatar,b.nickname')
->order('a.is_direct')
->select();
foreach ($data as &$v){
$mes = Db::name('message')
->where('house_id',$house_id)
->where('user_id',$v['user_id'])
->where('to_user_id',$user_id)
->where('is_read',2)
->find();
if(empty($mes)){
$v['is_have'] = 2;
}else{
$v['is_have'] = 1;
}
}
$this->success('success',$data);
}
/**
* @ApiTitle (聊天记录列表)
* @ApiSummary (聊天记录列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/chat_record)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_id", type="inter", required=true, description="社区id")
* @ApiParams (name="user_id", type="inter", required=true, description="社区物业管理员用户id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://id
"user_id"://发送者id
"house_id"://社区id
"to_user_id"://接收者用户id
"type"://消息类型1文字类型2图片类型
"content"://文字消息
"image"://图片消息
"is_read"://是否已读1已读2未读
"createtime"://创建时间
"updatetime"://修改时间
"nickname"://昵称
"is_have"://是否带有红标签 1有2没有
"is_left"://是否在右边 1是2否
}
})
*/
public function chat_record()
{
$qiniu = get_addon_config('qiniu')['cdnurl'];
$user_id = $this->auth->id; //当前登录用户id
$house_id = $this->request->param('house_id'); //社区id
$wuye_user_id = $this->request->param('user_id'); //物业用户id
if(empty($house_id) || empty($wuye_user_id)){
$this->error('缺少必要参数');
}
$house_admin = Db::name('house_admin')->where('user_id',$wuye_user_id)->where('house_id',$house_id)->find();
if(empty($house_admin)){
$this->error('参数有误,社区与管理员id不匹配');
}
$data = Db::name('message')
->where('house_id',$house_id)
->where('user_id',$user_id)
->where('to_user_id',$wuye_user_id)
->order('createtime desc')
->select();
foreach ($data as &$v){
$v['is_right'] = 1;
if($v['type'] == 2){
$v['image'] = $qiniu.$v['image'];
}
}
$arr = Db::name('message')
->where('house_id',$house_id)
->where('user_id',$wuye_user_id)
->where('to_user_id',$user_id)
->order('createtime desc')
->select();
foreach ($arr as &$v){
$v['is_right'] = 2;
if($v['type'] == 2){
$v['image'] = $qiniu.$v['image'];
}
}
$info = array_merge($data,$arr);
array_multisort(array_column($info,'createtime'),SORT_DESC,$info);
foreach ($info as &$val){
$val['createtime'] = date('Y-m-d H:i:s',$val['createtime']);
}
$this->success('success',$info);
}
}