House.php
18.7 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
<?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 House extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (首页轮播图)
* @ApiSummary (首页轮播图)
* @ApiMethod (POST)
* @ApiRoute (/api/house/banner)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://id
"image"://图片
"url"://跳转地址
"typeswitch"://开关0关1开
"createtime"://创建时间
}
]
}
})
*/
public function banner()
{
$data = Db::name('banner')->field('updatetime',true)->order('createtime desc')->select();
foreach ($data as &$v){
$v['image'] = cdnurl($v['image'],true);
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (首页社区名称以及社区公告)
* @ApiSummary (首页社区名称以及社区公告)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house)
*
* @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 house()
{
$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;
$info['house_name'] = Db::name('house')->where('id',$data['house_id'])->value('name');
//查询该社区的社区公告
$house_board = Db::name('house_board')
->where('house_id',$data['house_id'])
->where('deletetime',null) //未下架
->order('createtime desc')
->find();
if(empty($house_board)){
$info['is_have'] = 2;
$info['title'] = '';
$info['content'] = '';
$info['createtime'] = '';
$info['look_num'] = '';
$info['is_new'] = 2;
$info['id'] = '';
}else{
$info['is_have'] = 1;
$info['title'] = $house_board['title'];
$info['content'] = $house_board['content'];
$info['look_num'] = $house_board['look_num'];
$info['createtime'] = date('Y-m-d',$house_board['createtime']);
$info['id'] = $house_board['id'];
//查询是否已读
$is_read = Db::name('house_board_detail')->where('user_id',$user_id)->where('house_board_id',$house_board['id'])->find();
$info['is_new'] = empty($is_read) ? 1 : 2;
}
}
$this->success('success',$info);
}
/**
* @ApiTitle (所有已绑定小区)
* @ApiSummary (所有已绑定小区)
* @ApiMethod (POST)
* @ApiRoute (/api/house/myhouse)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "success",
"time": "1598688508",
"data": [{
"id": 16, //小区ID
"name": "兴安苑", //小区名称
"is_current": 0 //是否当前小区:0=否,1=是
}]
})
*/
public function myhouse()
{
$user = $this->auth->getUser();
$list = Db::name('user_house')
->alias('uh')
->join('house h','h.id = uh.house_id')
->where('uh.user_id',$user['id'])
->where('uh.status',2)
->field("h.id,h.name")
->order('uh.status desc')
->select();
foreach($list as &$v){
$v['is_current'] = $user['house_id'] == $v['id'] ? 1 : 0;
}
$this->success('success',$list);
}
/**
* @ApiTitle (首页展开公告)
* @ApiSummary (首页展开公告)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_board_detail)
*
* @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": {
"title"://社区公告标题
"content"://公告内容
"images":[
"http://community.qiniu.brotop.cn/uploads/20200831/f83a557326743d7c271ca5e757d3e952.png"
],//公告图片
"look_num"://浏览人数
"createtime"://时间
"avatar"://用户头像
}
]
}
})
*/
public function house_board_detail()
{
$user_id = $this->auth->id;
$id = $this->request->param('house_board_id');
if(empty($id)){
$this->error('缺少必要参数');
}
$info['user_id'] = $user_id;
$info['house_board_id'] = $id;
$info['createtime'] = time();
$res = Db::name('house_board_detail')->where('user_id',$info['user_id'])->where('house_board_id',$info['house_board_id'])->find();
if(empty($res)){
Db::name('house_board_detail')->insertGetId($info);
Db::name('house_board')->where('id',$id)->setInc('look_num');
}
$data = Db::name('house_board')
->field('id,house_id,title,content,images,look_num,createtime')
->where('id',$id)
->find();
$data['createtime'] = date('Y-m-d',$data['createtime']);
// 公告图片
if(!empty($data['images'])){
$image_arr = explode(',', $data['images']);
foreach ($image_arr as &$v) {
$v = cdnurl($v,true);
}
$data['images'] = $image_arr;
}
$data['avatar'] = Db::name('house_board_detail')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.house_board_id',$id)
->field('a.user_id,b.nickname,b.avatar')
->limit(6)
->select();
foreach ($data['avatar'] as &$v) {
$v['avatar'] = cdnurl($v['avatar'],true);
}
$this->success('success',$data);
}
/**
* @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()
{
$user_id = $this->auth->id;
$id = $this->request->param('house_board_id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('house_board_detail')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.house_board_id',$id)
->field('b.id,b.avatar,b.nickname')
->order('a.createtime desc')
->select();
foreach ($data as &$v) {
$v['avatar'] = cdnurl($v['avatar'],true);
}
$this->success('success',$data);
}
/**
* @ApiTitle (好物抢购)
* @ApiSummary (好物抢购)
* @ApiMethod (POST)
* @ApiRoute (/api/house/goods)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "success",
"time": "1598620381",
"data": [
{
"goods_id": 21,
"goods_name": "小米Mix3",
"goods_price": "3299.00",
"image": "https://her-family.oss-cn-qingdao.aliyuncs.com/addons_store_uploads/20181105/ffc4440df18661948b9c2d4dd4ae419b.jpg"
}
]
})
*/
public function goods()
{
$list = Db::name('litestore_goods')
->where('is_recommend',1)
->field('goods_id,goods_name,images')
->select();
foreach($list as &$v){
$spec = Db::name('litestore_goods_spec')->where('goods_id',$v['goods_id'])->field('goods_price')->find();
$v['goods_price'] = $spec['goods_price'];
$v['image'] = cdnurl(explode(',',$v['images'])[0],true);
unset($v['images']);
}
$this->success('success',$list);
}
/**
* @ApiTitle (社区列表)
* @ApiSummary (社区列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_list)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="type", type="string", required=true, description="用户类型1=用户2=商家")
* @ApiParams (name="area", type="string", required=false, description="市区地址例如:'天津市/西青区'")
* @ApiParams (name="keyword", type="string", required=false, description="关键字")
*
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://小区id
"name"://小区名称
"area"://所在区
"address"://地址
"price"://入驻金额
"shen_status"://状态0选择1申请中2已绑定
}
]
}
})
*/
public function house_list()
{
$type = $this->request->param('type',1,'intval');
$user_id = $this->auth->id;
$area = $this->request->param('area');
$keyword = $this->request->param('keyword');
$where = [];
if(!empty($area)){
$where['area'] = ['like',"%$area%"];
}
if(!empty($keyword)){
$where['name'] = ['like',"%$keyword%"];
}
//查询该市区下的所有小区
$data = Db::name('house')
->where($where)
->field('id,name,area,address,price')
->order('createtime desc')
->select();
if($type == 2) {
//查出该用户入驻商家已绑定的和申请中的小区
$store_model = new \app\api\model\Store();
$where_s = ['user_id'=>$this->auth->id,'status'=>3];
$where = [
'where' => $where_s,
];
$store = $store_model->findOrFail($where,false);
foreach ($data as &$v){
$house_ids = explode(',',$store['house_ids']);
if(in_array($v['id'],$house_ids)){
$v['shen_status'] = 2;
}else{
$v['shen_status'] = 0;
}
}
} else {
//查出该用户已绑定的和申请中的小区
$user_house = Db::name('user_house')
->where('user_id',$user_id)
->select();
foreach ($data as &$v){
$v['shen_status'] = 0;
foreach ($user_house as &$val){
if($v['id'] == $val['house_id'] && in_array($val['status'],[1,2])) {
$v['shen_status'] = $val['status'];
}
}
}
}
$this->success('success',$data);
}
/**
* @ApiTitle (市级列表)
* @ApiSummary (市级列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/city_list)
*
* @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": {
"id"://市级id
"name"://市级名称
"children": [{
"id": //区级id
"name": //区级id
}]
}
]
}
})
*/
public function city_list()
{
$total_num = Db::name('area')->field('id,name')->where('level',2)->count();
$city_list = Db::name('area')->field('id,name')->where('level',2)->select();
foreach ($city_list as &$v) {
$v['children'] = Db::name('area')
->where('level',3)
->where('pid',$v['id'])
->field('id,name')
->select();
}
$this->success('success',compact('total_num','city_list'));
}
/**
* @ApiTitle (区级列表)
* @ApiSummary (区级列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/country_list)
*
* @ApiParams (name="id", type="string", required=true, description="市级id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://区级id
"name"://区级名称
}
]
}
})
*/
public function country_list()
{
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('area')
->where('level',3)
->where('pid',$id)
->field('id,name')
->select();
$this->success('success',$data);
}
/**
* @ApiTitle (申请加入社区)
* @ApiSummary (申请加入社区)
* @ApiMethod (POST)
* @ApiRoute (/api/house/joinhouse)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_id", type="string", required=true, description="小区id")
* @ApiParams (name="name", type="string", required=true, description="姓名")
* @ApiParams (name="phone", type="string", required=true, description="手机号")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
}
]
}
})
*/
public function joinhouse()
{
$param = $this->request->param();
$param['user_id'] = $this->auth->id;
$validate = new Validate([
'house_id' => 'require',
'name' => 'require',
'phone' => 'require'
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$info = Db::name('user_house')->where('user_id',$param['user_id'])
->where('house_id',$param['house_id'])
->where('status','in',[1,2])
->find();
if(empty($info)){
$param['createtime'] = time();
$param['updatetime'] = time();
$data = Db::name('user_house')->insertGetId($param);
if(empty($data)){
$this->error('申请失败');
}else{
Db::name('user')->where('id',$param['user_id'])->update(['mobile'=>$param['phone']]);
$this->success('成功');
}
}else{
$this->error('您已经绑定过该小区了');
}
}
/**
* @ApiTitle (获取验证码)
* @ApiSummary (获取验证码)
* @ApiMethod (POST)
* @ApiRoute (/api/house/getcode)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="mobile", type="string", required=false, description="手机号")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function getcode()
{
$phone = $this->request->param('mobile');
if (empty($phone)) {
$this->error(['code' => 40005, 'msg' => '手机号不能为空']);
}
if (!preg_match('/^1[0-9]{10}$/', $phone)) {
$this->error(['code' => 40005, 'msg' => "请输入正确的手机格式!"]);
}
//生成验证码
$number = generateCode();
//发送验证码
$data = array(
'content' => "提醒您,您的验证码是:" .$number.",十分钟之内有效,请勿向他人泄漏您的验证码。【小区焦点】",//短信内容
'mobile' => $phone,//手机号码
'productid' => '676767',//产品id
'xh' => ''//小号
);
$result = send_sms($data);
if (substr($result, 0, strpos($result, ',')) != "1") {
$this->error(['code' => 42001, 'msg' => $result]);
}
Cache::set($phone,$number,600);
$this->success('SUCCESS');
}
/**
* @ApiTitle (验证验证码)
* @ApiSummary (验证验证码)
* @ApiMethod (POST)
* @ApiRoute (/api/house/verify)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
* @ApiParams (name="code", type="string", required=true, description="验证码")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function verify()
{
$param = $this->request->param();
$validate = new Validate([
'mobile' => 'require|max:11',
'code'=>'require'
]);
if (!$validate->check($param)) {
$this->error(['code'=>40005,'msg'=>$validate->getError()]);
}
$code = Cache::get($param['mobile']);
if($param['code'] == $code){
$this->success('SUCCESS');
}else{
$this->error('验证码错误或者失效,请重新发送');
}
}
}