UserneedController.php
27.8 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
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use api\portal\model\UserNeedModel;
use api\portal\model\PortalPostModel;
use cmf\controller\RestBaseController;
use think\Db;
use think\Request;
use think\Loader;
use think\Config;
use think\captcha\Captcha;
use think\Url;
use SmsDemo;
//use think\Route;
/**
* @title 用户需求接口
* @description 接口说明
* @group 接口分组
*/
class UserneedController extends CommonController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
/**
* @title 用户发布需求时保证金金额(填完地区,小区调用;每次修改重新调用)(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/payMoney
* @method POST
* @param name:token type:varchar require:1 default: other: desc:token
* @param name:city type:int require:1 default: other: desc:地区
* @param name:area type:int require:1 default: other: desc:面积
*/
public function payMoney(Request $request){
$data = $request->param();
if(!$data['city'] || !$data['area'] ){
$this->apiResponse('0','城市、面积不能为空');
}
// 保证金
$city = $data['city'];
$area = $data['area'];
// 查询地区
$count_where = 0;
$where_area['id'] = 1;
$city_name = Db::name('MoneyRule')->where($where_area)->field('city_name')->find();
$findcity_arr = explode('、',$city_name['city_name']);
foreach ($findcity_arr as $fca_k=>$fca_v){
if(strpos($city,$fca_v) !== false){
$count_where = 1;
$where_money['city_name'] = array('like',"%".$fca_v.'%');
}else{
$count_where += 0;
}
}
if($count_where == 0){
$where_money['type'] = 2;
}else{
$where_money['type'] = 1;
}
$where_money['status'] = 1;
$where_money['low_area'] = array('lt',$area);
$where_money['height_area'] = array('egt',$area);
$money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
if($money){
$final['pay_money'] = $money['money'];
$this->apiResponse('1','成功',$final);
}else{
$this->apiResponse('0','保证金获取失败');
}
}
/**
* @title 用户发布需求验证(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/judge
* @method POST
* @param name:name type:varchar require:1 default: other: desc:联系人姓名
* @param name:tel type:varchar require:1 default: other: desc:联系人电话
* @param name:code type:int require:1 default: other: desc:验证码
* @param name:token type:varchar require:1 default: other: desc:token
* @return data:''
*/
public function judge(Request $request){
$data = $request->param();
if(empty($data['name'])){
$this->apiResponse('0','联系人姓名不能为空');
}
if(empty($data['tel'])){
$this->apiResponse('0','联系人电话不能为空');
}
if(empty($data['code'])){
$this->apiResponse('0','验证码不能为空');
}else{
$code = $data['code'];
}
$where_code['tel'] = $data['tel'];
$where_code['type'] = 3;
$where_code['status'] = 1;
$where_code['create_time'] = array('egt',(time()-300));
$find_code = Db::name('Code')->where($where_code)->order('create_time')->field('code')->find();
if(!$find_code){
$this->apiResponse('0','验证码错误,请重新获取');
}
if($code != $find_code['code']){
$this->apiResponse('0','验证码错误,请重新获取');
}else{
$updateCode['status'] = 9;
Db::name('Code')->where($where_code)->update($updateCode);
$this->apiResponse('1','成功');
}
}
/**
* @title 用户发布需求中间层(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/sendMiddle
* @method POST
* @param name:city type:varchar require:1 default: other: desc:地区(省-市-区)
* @param name:quarters type:varchar require:1 default: other: desc:小区
* @param name:room type:varchar require:1 default: other: desc:具体房号(1-1-1)
* @param name:floor type:int require:1 default: other: desc:楼层
* @param name:house_type type:varchar require:1 default: other: desc:户型
* @param name:renovation type:varchar require:1 default: other: desc:装修
* @param name:area type:varchar require:1 default: other: desc:建筑面积
* @param name:is_first type:tinyint require:1 default: other: desc:是否首套房(1->首套房,2->两套及以上)
* @param name:loan type:tinyint require:1 default: other: desc:贷款(1->贷款,2->全款)
* @param name:contract type:tinyint require:1 default: other: desc:是否是包干价(1->是,2->否)
* @param name:quotation_time type:int require:1 default: other: desc:报价时间
* @param name:name type:varchar require:1 default: other: desc:联系人姓名
* @param name:tel type:varchar require:1 default: other: desc:联系人电话
* @param name:code type:int require:1 default: other: desc:验证码
* @param name:gener type:int require:1 default: other: desc:类型(1->PC,2->手机)
* @param name:else type:int require:1 default: other: desc:备注
* @param name:token type:varchar require:1 default: other: desc:token
* @return data:''@
* @data type:'1->包干价,2->问答'
* @data need_id:'需求id'
*/
public function sendMiddle(Request $request)
{
Db::startTrans();
if($request->Post('token') && $request->Post('area')){
// $data = $request->param();
// 判空,处理
$validate = Loader::validate('UserNeed');
if(!$validate->check($_POST)){
$this->apiResponse('0',$validate->getError());
}
// 加数据库
$data = $request->Post();
// 省市区不能为空判断
$num = 0;
if(empty($data['city'])){
$this->apiResponse('0','城市不能为空');
}else{
$expFirst = explode('-',$data['city']);
if(count($expFirst) < 3){
$this->apiResponse('0','省市区不能为空');
}else{
foreach ($expFirst as $ek=>$ev){
if(empty($ev)){
$num +=1;
}else{
$num +=0;
}
}
if($num >0){
$this->apiResponse('0','省市区不能为空');
}
}
}
// 验证码判断
if(empty($data['gener'])){
$this->apiResponse('0','请传类型');
}else{
if($data['gener'] == 2){
if(empty($data['code'])){
Db::rollback();
$this->apiResponse('0','验证码不能为空');
}else{
$code = $data['code'];
}
$where_code['tel'] = $data['tel'];
$where_code['type'] = 3;
$where_code['status'] = 1;
$where_code['create_time'] = array('egt',(time()-300));
$find_code = Db::name('Code')->where($where_code)->order('create_time')->field('code')->find();
if(!$find_code){
Db::rollback();
$this->apiResponse('0','验证码错误,请重新获取');
}
if($code != $find_code['code']){
Db::rollback();
$this->apiResponse('0','验证码错误,请重新获取');
}else{
$updateCode['status'] = 9;
Db::name('Code')->where($where_code)->update($updateCode);
}
}
}
// 保证金
$city = $data['city'];
$area = $data['area'];
// 查询地区
$count_where = 0;
$where_area['id'] = 1;
$city_name = Db::name('MoneyRule')->where($where_area)->field('city_name')->find();
$findcity_arr = explode('、',$city_name['city_name']);
foreach ($findcity_arr as $fca_k=>$fca_v){
if(strpos($city,$fca_v) !== false){
$count_where = 1;
$where_money['city_name'] = array('like',"%".$fca_v.'%');
}else{
$count_where += 0;
}
}
if($count_where == 0){
$where_money['type'] = 2;
}else{
$where_money['type'] = 1;
}
$where_money['status'] = 1;
$where_money['low_area'] = array('lt',$area);
$where_money['height_area'] = array('egt',$area);
$money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
if($money){
$data['pay_money'] = $money['money'];
}else{
Db::rollback();
$this->apiResponse('0','保证金获取失败');
}
$where_mem['token'] = $data['token'];
$mem_id = Db::name('Member')->where($where_mem)->field('id')->find();
$data['user_id'] = $mem_id['id'];
$model = new UserNeedModel();
// 添加
if($data['gener'] == 2){
unset($data['code']);
}
unset($data['gener']);
unset($data['connect']);
unset($data['token']);
$data['status'] = 15;
$save = $model->save($data);
if($save){
$final['userNeed_id'] = $model->getLastInsID();
$final['money'] = $data['pay_money'];
Db::commit();
$this->apiResponse('1','添加成功',$final);
}else{
Db::rollback();
$this->apiResponse('0','添加失败');
}
}else{
// 问答内容
$where_pro['status'] = 1;
$list = Db::name('NeedAnswer')->where($where_pro)->order("update_time desc")->field("title,content,id,type")->select()->toArray();
foreach ($list as $lk=>$lv){
$list[$lk]['content'] = htmlspecialchars_decode($lv['content']);
}
if($list){
$final['answer'] = $list;
$this->apiResponse('1','成功',$final);
}else{
$this->apiResponse('0','暂无内容');
}
}
}
/**
* @title 用户发布需求查询(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/findSend
* @method POST
* @param name:middle_id type:varchar require:1 default: other: desc:需求id
* @param name:token type:varchar require:1 default: other: desc:token
* @return data:''
*/
public function findSend(){
$data = $this->request->param();
$where_token['token'] = $data['token'];
$where_token['status'] = array('neq',9);
$member = Db::name('Member')->where($where_token)->field('id')->find();
$where_middle['id'] = $data['middle_id'];
$where_middle['status'] = 15;
$where_middle['user_id'] = $member['id'];
$is_middle = Db::name('UserNeed')->where($where_middle)->find();
if($is_middle){
$this->apiResponse('1','成功',$is_middle);
}else{
$this->apiResponse('0','需求错误');
}
}
/**
* @title 用户发布需求(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/send
* @method POST
* @param name:middle_id type:varchar require:1 default: other:确认页面后传,只传此值即可 desc:需求id
* @param name:city type:varchar require:1 default: other: desc:地区(省-市-区)
* @param name:quarters type:varchar require:1 default: other: desc:小区
* @param name:room type:varchar require:1 default: other: desc:具体房号(1-1-1)
* @param name:floor type:int require:1 default: other: desc:楼层
* @param name:house_type type:varchar require:1 default: other: desc:户型
* @param name:renovation type:varchar require:1 default: other: desc:装修
* @param name:area type:varchar require:1 default: other: desc:建筑面积
* @param name:is_first type:tinyint require:1 default: other: desc:是否首套房(1->首套房,2->两套及以上)
* @param name:loan type:tinyint require:1 default: other: desc:贷款(1->贷款,2->全款)
* @param name:contract type:tinyint require:1 default: other: desc:是否是包干价(1->是,2->否)
* @param name:quotation_time type:int require:1 default: other: desc:报价时间
* @param name:name type:varchar require:1 default: other: desc:联系人姓名
* @param name:tel type:varchar require:1 default: other: desc:联系人电话
* @param name:code type:int require:1 default: other: desc:验证码
* @param name:gener type:int require:1 default: other: desc:类型(1->PC,2->手机)
* @param name:else type:int require:1 default: other: desc:备注
* @param name:token type:varchar require:1 default: other: desc:token
* @return data:''@
* @data type:'1->包干价,2->问答'
* @data need_id:'需求id'
*/
public function send(Request $request)
{
Db::startTrans();
$data = $request->Post();
if((!empty($data['token']) && !empty($data['area'])) || !empty($data['middle_id'])){
if(empty($data['middle_id'])){
// 判空,处理
$validate = Loader::validate('UserNeed');
if(!$validate->check($_POST)){
$this->apiResponse('0',$validate->getError());
}
// 加数据库
// 省市区不能为空判断
$num = 0;
if(empty($data['city'])){
$this->apiResponse('0','城市不能为空');
}else{
$expFirst = explode('-',$data['city']);
if(count($expFirst) < 3){
$this->apiResponse('0','省市区不能为空');
}else{
foreach ($expFirst as $ek=>$ev){
if(empty($ev)){
$num +=1;
}else{
$num +=0;
}
}
if($num >0){
$this->apiResponse('0','省市区不能为空');
}
}
}
// 验证码判断
if(empty($data['gener'])){
$this->apiResponse('0','请传类型');
}else{
if($data['gener'] == 2){
if(empty($data['code'])){
Db::rollback();
$this->apiResponse('0','验证码不能为空');
}else{
$code = $data['code'];
}
$where_code['tel'] = $data['tel'];
$where_code['type'] = 3;
$where_code['status'] = 1;
$where_code['create_time'] = array('egt',(time()-300));
$find_code = Db::name('Code')->where($where_code)->order('create_time')->field('code')->find();
if(!$find_code){
Db::rollback();
$this->apiResponse('0','验证码错误,请重新获取');
}
if($code != $find_code['code']){
Db::rollback();
$this->apiResponse('0','验证码错误,请重新获取');
}else{
$updateCode['status'] = 9;
Db::name('Code')->where($where_code)->update($updateCode);
}
}
}
// 保证金
$city = $data['city'];
$area = $data['area'];
// 查询地区
$count_where = 0;
$where_area['id'] = 1;
$city_name = Db::name('MoneyRule')->where($where_area)->field('city_name')->find();
$findcity_arr = explode('、',$city_name['city_name']);
foreach ($findcity_arr as $fca_k=>$fca_v){
if(strpos($city,$fca_v) !== false){
$count_where = 1;
$where_money['city_name'] = array('like',"%".$fca_v.'%');
}else{
$count_where += 0;
}
}
if($count_where == 0){
$where_money['type'] = 2;
}else{
$where_money['type'] = 1;
}
$where_money['status'] = 1;
$where_money['low_area'] = array('lt',$area);
$where_money['height_area'] = array('egt',$area);
$money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
if($money){
$data['pay_money'] = $money['money'];
}else{
Db::rollback();
$this->apiResponse('0','保证金获取失败');
}
$where_mem['token'] = $data['token'];
$mem_id = Db::name('Member')->where($where_mem)->field('id')->find();
$data['user_id'] = $mem_id['id'];
$model = new UserNeedModel();
// 添加
if($data['gener'] == 2){
unset($data['code']);
}
unset($data['gener']);
unset($data['connect']);
unset($data['token']);
$save = $model->save($data);
if($save){
$final['userNeed_id'] = $model->getLastInsID();
$final['money'] = $data['pay_money'];
Db::commit();
$this->apiResponse('1','添加成功',$final);
}else{
Db::rollback();
$this->apiResponse('0','添加失败1');
}
}else{
$where_middle['id'] = $data['middle_id'];
$where_middle['status'] = 15;
$is_middle = Db::name('UserNeed')->where($where_middle)->find();
if($is_middle){
$update_middle['status'] = 1;
$update_middle['update_time'] = time();
$update = Db::name('UserNeed')->where($where_middle)->update($update_middle);
if($update){
Db::commit();
$final['userNeed_id'] = $data['middle_id'];
$final['money'] = $is_middle['pay_money'];
$this->apiResponse('1','添加成功',$final);
}else{
Db::rollback();
$this->apiResponse('0','添加失败2');
}
}else{
Db::rollback();
$this->apiResponse('0','添加失败3');
}
}
}else{
// 问答内容
$where_pro['status'] = 1;
$list = Db::name('NeedAnswer')->where($where_pro)->order("update_time desc")->field("title,content,id,type")->select()->toArray();
foreach ($list as $lk=>$lv){
$list[$lk]['content'] = htmlspecialchars_decode($lv['content']);
}
if($list){
$final['answer'] = $list;
$this->apiResponse('1','成功',$final);
}else{
$this->apiResponse('0','暂无内容');
}
}
}
/**
* @title 用户修改需求(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/changesend
* @method POST
* @param name:city type:varchar require:1 default: other: desc:地区(省-市-区)
* @param name:quarters type:varchar require:1 default: other: desc:小区
* @param name:room type:varchar require:1 default: other: desc:具体房号(1-1-1)
* @param name:floor type:int require:1 default: other: desc:楼层
* @param name:house_type type:varchar require:1 default: other: desc:户型
* @param name:renovation type:varchar require:1 default: other: desc:装修
* @param name:area type:varchar require:1 default: other: desc:建筑面积
* @param name:is_first type:tinyint require:1 default: other: desc:是否首套房(1->首套房,2->两套及以上)
* @param name:loan type:tinyint require:1 default: other: desc:贷款(1->贷款,2->全款)
* @param name:contract type:tinyint require:1 default: other: desc:是否是包干价(1->是,2->否)
* @param name:quotation_time type:int require:1 default: other: desc:报价时间
* @param name:name type:varchar require:1 default: other: desc:联系人姓名
* @param name:tel type:varchar require:1 default: other: desc:联系人电话
* @param name:code type:int require:1 default: other: desc:验证码
* @param name:else type:int require:1 default: other: desc:备注
* @param name:need_id type:int require:1 default: other:修改需求时传 desc:需求id
* @param name:token type:varchar require:1 default: other: desc:token
* @return data:''@
* @data type:'1->包干价,2->问答'
* @data need_id:'需求id'
*/
public function changeSend(Request $request)
{
if($request->Post('token') && $request->Post('name')){
// $data = $request->param();
// 判空,处理
$validate = Loader::validate('UserNeed');
if(!$validate->check($_POST)){
return json(array('code'=>0,'msg'=>$validate->getError()));
}
// 加数据库
$data = $request->Post();
if(empty($data['code'])){
$this->apiResponse('0','验证码不能为空');
}else{
$code = $data['code'];
}
$where_code['tel'] = $data['tel'];
$where_code['type'] = 3;
$where_code['status'] = 1;
$where_code['create_time'] = array('egt',(time()-300));
$find_code = Db::name('Code')->where($where_code)->order('create_time ')->field('code')->find();
if(!$find_code){
$this->apiResponse('0','验证码错误,请重新获取');
}
if($code != $find_code['code']){
$this->apiResponse('0','验证码错误,请重新获取');
}else{
$updateCode['status'] = 9;
Db::name('Code')->where($where_code)->update($updateCode);
}
// 保证金
$city = $data['city'];
$area = $data['area'];
// 查询地区
$where_area['area_name'] = array('like',"%$city%");
$city_id = Db::name('Areas')->where($where_area)->field('area_id')->find();
$where_money['city'] = array('like',"%".$city_id['area_id'].'%');
$where_money['status'] = 1;
$where_money['low_area'] = array('lt',$area);
$where_money['height_area'] = array('egt',$area);
$money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
if(!$money){
$where_elsemoney['city'] = 0;
$where_elsemoney['status'] = 1;
$where_elsemoney['low_area'] = array('lt',$area);
$where_elsemoney['height_area'] = array('egt',$area);
$elsemoney = Db::name('MoneyRule')->where($where_elsemoney)->field('money')->find();
if($elsemoney){
$data['pay_money'] = $elsemoney['money'];
}else{
$this->apiResponse('0','保证金获取失败');
}
}else{
$data['pay_money'] = $money['money'];
}
$where_mem['token'] = $data['token'];
$mem_id = Db::name('Member')->where($where_mem)->field('id')->find();
$data['user_id'] = $mem_id['id'];
$model = new UserNeedModel();
// 修改
$where_need['id'] = $request->param('need_id');
$where_need['status'] = array('in','1,2');
$need = Db::name('UserNeed')->where($where_need)->find();
if(!$need){
$this->apiResponse('0','该需求不可修改');
}else{
unset($data['code']);
unset($data['connect']);
unset($data['token']);
$data['id'] = $data['need_id'];
if($need['status'] == 2){
unset($data['pay_money']);
}
$save = $model->isUpdate(true)->allowField(true)->save($data);
}
if($save){
$final['need_id'] = $model->id;
$this->apiResponse('1','修改成功',$final);
}else{
$this->apiResponse('0','修改失败');
}
}else{
$data = $request->param();
if(empty($data['need_id'])){
$this->apiResponse('0','需求id不可為空');
}
$where_need['id'] = $request->param('need_id');
$where_need['status'] = array('in','1,2');;
$where_mem['token'] = $data['token'];
$mem_id = Db::name('Member')->where($where_mem)->field('id')->find();
$where_need['user_id'] = $mem_id['id'];
$list['need'] = Db::name('UserNeed')->where($where_need)->find();
if(!$list['need']){
$this->apiResponse('0','该需求不可修改');
}
// 问答内容
$where_pro['status'] = 1;
$answer = Db::name('NeedAnswer')->where($where_pro)->order("update_time desc")->field("title,content,id,type")->select()->toArray();
foreach ($answer as $lk=>$lv){
$answer[$lk]['content'] = htmlspecialchars_decode($lv['content']);
}
$list['answer'] = $answer;
if($list){
$this->apiResponse('1','成功',$list);
}else{
$this->apiResponse('0','暂无内容');
}
}
}
}