ProductController.php
32.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
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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/3/26
* Time: 8:11
*/
namespace api\wxapp\controller;
use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
/**
* @title 产品模块
* @description 产品管理模块
*/
class ProductController extends RestBaseController
{
/**
* @title 获取产品列表(筛选)
* @description 产品
* @url /wxapp/product/getList
* @method POST
*
* @header name:XX-Token type:string require:1 default:abc other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:user_id type:string require:1 other: desc:业务员id
* @param name:company type:string require:0 other: desc:公司信息(这是公司名称下拉列表吗。不懂)
* @param name:policy type:string require:0 other: desc:保单信息1有0无
* @param name:car type:string require:0 other: desc:车辆信息1全款车0无
* @param name:page type:string require:0 other: desc:页码
* @param name:per_page type:string require:0 other: desc:每页数据量
*
* @return total:总数据量
* @return per_page:每页数据量
* @return current_page:当前页
* @return last_page:尾页
* @return data:对象信息@!
* @data id:产品id name:产品名称 logo:产品logo upper_limit:额度范围上限 lower_limit:额度范围下限 rate:月费率 loan_time:放款时间 loan_period:贷款期限 company:公司名称
*/
public function getList() {
$validate = new Validate([
'user_id' => 'require',
'policy' => 'in:0,1',
'car' => 'in:0,1',
]);
$validate->message([
'user_id.require' => '参数user_id必须!',
'policy.in' => '参数policy只能为0,1!',
'car.in' => '缺少参数car只能为0,1!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$per_page = $data['per_page'] ? : config('per_page');
$condition['p.type'] = 1;//上架产品
$condition['c.user_id'] = $data['user_id'];
if ($data['policy']) {
$condition['p.policy'] = $data['policy'];
}
if ($data['car']) {
$condition['p.car'] = $data['car'];
}
$result = Db::name('product')
->alias('p')
->join('user u','p.user_id=u.id','left')
->join('card c','p.user_id=c.user_id','left')
->where($condition)
->field('p.id,p.name,p.logo,p.upper_limit,p.lower_limit,p.rate,p.loan_time,p.loan_period,c.company')
->order('p.create_time desc')
->paginate($per_page);
if ($result === false) {
$this->error(['code'=>'40000','msg'=>'获取失败']);
}
$this->success('获取成功',$result);
}
/**
* @title 获取产品详情
* @description 产品
* @url /wxapp/product/getDetails
* @method POST
*
* @header name:XX-Token type:string require:1 default:abc other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:id type:string require:1 other: desc:产品id
*
* @return id:产品id
* @return name:产品名称
* @return logo:产品logo
* @return upper_limit:额度范围上限
* @return lower_limit:额度范围下限
* @return rate:月费率
* @return loan_time:放款时间
* @return loan_period:贷款期限
* @return loan_flow:贷款流程
* @return fee_explain:费用说明
* @return refund_explain:还款说明
* @return company:公司名称
* @return job:工作信息 1上班 2做生意
* @return policy:保单信息 1有 0无
* @return house:房产信息 1全款房 2分期房 0无
* @return car:车辆信息 1全款车 0无
* @return is_apply:是否申请该产品贷款(1已申请0未申请)
*/
public function getDetails() {
$validate = new Validate([
'id' => 'require',
]);
$validate->message([
'id.require' => '参数id必须!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$result = Db::name('product')
->alias('p')
->join('user u','p.user_id=u.id','left')
->join('card c','p.user_id=c.user_id','left')
->where(['p.id' => $data['id']])
->field('p.id,p.name,p.logo,p.upper_limit,p.lower_limit,p.rate,p.loan_time,p.loan_period,p.loan_flow,p.fee_explain,p.refund_explain,c.company,p.job,p.policy,p.house,p.car')
->find();
if ($result === false) {
$this->error(['code'=>'40000','msg'=>'获取失败']);
}
if (!empty($result)) {
$check = Db::name('loans_apply')->where(['product_id' => $result['id'],'user_id' => $this->userId])->find();
if ($check) {
$result['is_apply'] = 1;
} else {
$result['is_apply'] = 0;
}
}
$this->success('获取成功',$result);
}
/**
* @title 添加产品
* @description 产品
* @url /wxapp/product/addProduct
* @method POST
*
* @header name:XX-Token type:string require:1 default:def other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:name type:int require:1 other: desc:产品名称
* @param name:logo type:int require:1 other: desc:产品logo
* @param name:upper_limit type:int require:1 other: desc:额度范围上限
* @param name:lower_limit type:int require:1 other: desc:额度范围下限
* @param name:rate type:int require:1 other: desc:月费率
* @param name:loan_period type:int require:1 other: desc:贷款期限
* @param name:loan_time type:int require:1 other: desc:放款时间
* @param name:job type:int require:1 other: desc:工作信息1上班2做生意
* @param name:policy type:int require:1 other: desc:保单信息1有0无
* @param name:house type:int require:1 other: desc:房产信息1全款房2分期房0无
* @param name:information type:int require:1 other: desc:个人信息
* @param name:car type:int require:1 other: desc:车辆信息1全款车0无
* @param name:loan_flow type:int require:1 other: desc:贷款流程
* @param name:fee_explain type:int require:1 other: desc:费用说明
* @param name:refund_explain type:int require:1 other: desc:还款说明
*
*/
public function addProduct() {
$validate = new Validate([
'name' => 'require',
'logo' => 'require',
'upper_limit' => 'require',
'lower_limit' => 'require',
'rate' => 'require',
'loan_period' => 'require',
'loan_time' => 'require',
'job' => 'require',
'policy' => 'require',
'house' => 'require',
'information' => 'require',
'car' => 'require',
'loan_flow' => 'require',
'fee_explain' => 'require',
'refund_explain' => 'require',
]);
$validate->message([
'name.require' => '缺少参数name!',
'logo.require' => '缺少参数logo!',
'upper_limit.require' => '缺少参数upper_limit!',
'lower_limit.require' => '缺少参数lower_limit!',
'rate.require' => '缺少参数rate!',
'loan_period.require' => '缺少参数loan_period!',
'loan_time.require' => '缺少参数loan_time!',
'job.require' => '缺少参数job!',
'policy.require' => '缺少参数policy!',
'house.require' => '缺少参数house!',
'information.require' => '缺少参数information!',
'car.require' => '缺少参数car!',
'loan_flow.require' => '缺少参数loan_flow!',
'fee_explain.require' => '缺少参数fee_explain!',
'refund_explain.require' => '缺少参数refund_explain!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$arr = [
'name' => $data['name'],
'logo' => $data['logo'],
'upper_limit' => $data['upper_limit'],
'lower_limit' => $data['lower_limit'],
'rate' => $data['rate'],
'loan_period' => $data['loan_period'],
'loan_time' => $data['loan_time'],
'job' => $data['job'],
'policy' => $data['policy'],
'house' => $data['house'],
'information' => $data['information'],
'car' => $data['car'],
'loan_flow' => $data['loan_flow'],
'fee_explain' => $data['fee_explain'],
'refund_explain' => $data['refund_explain'],
'user_id' => $this->userId,
];
$result = Db::name('product')->insert($arr);
if ($result === false) {
$this->error(['code'=>'40000','msg'=>'操作失败']);
}
$this->success('操作成功');
}
/**
* @title 编辑产品
* @description 产品
* @url /wxapp/product/editProduct
* @method POST
*
* @header name:XX-Token type:string require:1 default:def other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:id type:int require:1 other: desc:产品id
* @param name:name type:int require:1 other: desc:产品名称
* @param name:logo type:int require:1 other: desc:产品logo
* @param name:upper_limit type:int require:1 other: desc:额度范围上限
* @param name:lower_limit type:int require:1 other: desc:额度范围下限
* @param name:rate type:int require:1 other: desc:月费率
* @param name:loan_period type:int require:1 other: desc:贷款期限
* @param name:loan_time type:int require:1 other: desc:放款时间
* @param name:job type:int require:1 other: desc:工作信息1上班2做生意
* @param name:policy type:int require:1 other: desc:保单信息1有0无
* @param name:house type:int require:1 other: desc:房产信息1全款房2分期房0无
* @param name:information type:int require:1 other: desc:个人信息
* @param name:car type:int require:1 other: desc:车辆信息1全款车0无
* @param name:loan_flow type:int require:1 other: desc:贷款流程
* @param name:fee_explain type:int require:1 other: desc:费用说明
* @param name:refund_explain type:int require:1 other: desc:还款说明
*
*/
public function editProduct() {
$validate = new Validate([
'id' => 'require',
'name' => 'require',
'logo' => 'require',
'upper_limit' => 'require',
'lower_limit' => 'require',
'rate' => 'require',
'loan_period' => 'require',
'loan_time' => 'require',
'job' => 'require',
'policy' => 'require',
'house' => 'require',
'information' => 'require',
'car' => 'require',
'loan_flow' => 'require',
'fee_explain' => 'require',
'refund_explain' => 'require',
]);
$validate->message([
'id.require' => '缺少参数id!',
'name.require' => '缺少参数name!',
'logo.require' => '缺少参数logo!',
'upper_limit.require' => '缺少参数upper_limit!',
'lower_limit.require' => '缺少参数lower_limit!',
'rate.require' => '缺少参数rate!',
'loan_period.require' => '缺少参数loan_period!',
'loan_time.require' => '缺少参数loan_time!',
'job.require' => '缺少参数job!',
'policy.require' => '缺少参数policy!',
'house.require' => '缺少参数house!',
'information.require' => '缺少参数information!',
'car.require' => '缺少参数car!',
'loan_flow.require' => '缺少参数loan_flow!',
'fee_explain.require' => '缺少参数fee_explain!',
'refund_explain.require' => '缺少参数refund_explain!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$arr= [
'id' => $data['id'],
'name' => $data['name'],
'logo' => $data['logo'],
'upper_limit' => $data['upper_limit'],
'lower_limit' => $data['lower_limit'],
'rate' => $data['rate'],
'loan_period' => $data['loan_period'],
'loan_time' => $data['loan_time'],
'job' => $data['job'],
'policy' => $data['policy'],
'house' => $data['house'],
'information' => $data['information'],
'car' => $data['car'],
'loan_flow' => $data['loan_flow'],
'fee_explain' => $data['fee_explain'],
'refund_explain' => $data['refund_explain'],
'user_id' => $this->userId,
];
$result = Db::name('product')->update($arr);
if ($result === false) {
$this->error(['code'=>'40000','msg'=>'操作失败']);
}
$this->success('操作成功');
}
/**
* @title 删除产品
* @description 产品
* @url /wxapp/product/delProduct
* @method POST
*
* @header name:XX-Token type:string require:1 default:def other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:ids type:int require:1 other: desc:产品id(以英文,相隔的产品id字符串)
*
*/
public function delProduct() {
$validate = new Validate([
'ids' => 'require',
]);
$validate->message([
'ids.require' => '缺少参数ids!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$result = Db::name('product')
->where('user_id','=',$this->userId)
->where('id','in',$data['ids'])
->delete();
if ($result === false) {
$this->error(['code'=>'40000','msg'=>'操作失败']);
}
$this->success('操作成功');
}
/**
* @title 通过业务员id获取产品列表
* @description 产品
* @url /wxapp/product/getListByUserID
* @method POST
*
* @header name:XX-Token type:string require:1 default:def other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:user_id type:int require:1 other: desc:业务员id
* @param name:company type:int require:0 other: desc:工作信息1上班2做生意0不限
* @param name:policy type:int require:0 other: desc:保单信息1有0无2不限
* @param name:car type:int require:0 other: desc:车辆信息1全款车0无2不限
* @param name:page type:int require:0 other: desc:页码
* @param name:per_page type:int require:0 other: desc:每页数据量
*
* @return total:总数据量
* @return total_page:总页数
* @return data:对象信息@!
* @data id:产品id id name:产品名称 logo:产品logo upper_limit:额度范围上限 lower_limit:额度范围下限 rate:月费率 loan_time:放款时间 loan_period:贷款期限 company:公司 is_apply:是否申请该产品贷款(1已申请0未申请)
*/
public function getListByUserID() {
$validate = new Validate([
'user_id' => 'require',
]);
$validate->message([
'user_id.require' => '缺少参数user_id!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$condition['p.type'] = 1;//上架产品
$condition['p.user_id'] = $data['user_id'];
if (!empty($data['company'])) {
$condition['p.job'] = $data['company'];
}
if (isset($data['policy']) && $data['policy'] !=null && $data['policy'] !=2) {
$condition['p.policy'] = $data['policy'];
}
if (isset($data['car']) && $data['car'] !=null && $data['car'] !=2) {
$condition['p.car'] = $data['car'];
}
$list = Db::name('product')
->alias('p')
->join('user u','p.user_id=u.id','left')
->join('card c','p.user_id=c.user_id','left')
->where($condition)
->field('p.id,p.name,p.logo,p.upper_limit,p.lower_limit,p.rate,p.loan_time,p.loan_period,c.company')
->order('p.create_time desc')
->select()->toArray();
if ($list === false) {
$this->error(['code'=>'40000','msg'=>'获取失败']);
}
if (!empty($list)) {
foreach ($list as $k => $v) {
$check = Db::name('loans_apply')->where(['product_id' => $v['id'],'user_id' => $this->userId])->find();
if ($check) {
$list[$k]['is_apply'] = 1;
} else {
$list[$k]['is_apply'] = 0;
}
}
}
$arrResult = [];
foreach ($list as $v) {
$arrResult[] = $v;
}
$perPage = !empty($data['per_page']) ? $data['per_page'] : config('per_page');
$page = isset($data['page']) ? $data['page'] : 1;
$resultWithPage = array_slice($arrResult, ($page - 1) * $perPage, $perPage);
$qinCount = count($arrResult);
$totalPage = ceil($qinCount / $perPage);
if ($arrResult) {
$return['data'] = $resultWithPage;
$return['total_page'] = $totalPage;
$return['total'] = $qinCount;
} else {
$return['data'] = $resultWithPage;
$return['total_page'] = 0;
$return['total'] = 0;
}
$this->success('获取成功',$return);
}
/**
* @title 申请贷款
* @description 产品
* @url /wxapp/product/applyLoans
* @method POST
*
* @header name:XX-Token type:string require:1 default:def other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:id type:int require:1 other: desc:产品id
*
*/
public function applyLoans() {
$validate = new Validate([
'id' => 'require',
]);
$validate->message([
'id.require' => '缺少参数id!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
//校验 是否已申请
$check = Db::name('loans_apply')->where(['product_id' => $data['id'],'user_id'=>$this->userId])->field('id')->find();
if ($check) {
$this->error(['code'=>'40006','msg'=>'该产品您已申请']);
}
$cardID = Db::name('product')
->alias('p')
->join('card c','p.user_id =c.user_id')
->where(['p.id' =>$data['id']])
->value('c.id');
if (!$cardID) {
$this->error(['code'=>'40011','msg'=>'该产品不存在']);
}
//排除业务员自己 不能申请自己产品
if ($this->userType == 3) {
$card_id = Db::name('card')->where(['user_id' => $this->userId])->value('id');
if ($cardID == $card_id) {
$this->error(['code'=>'40014','msg'=>'不能申请自己的产品']);
}
}
//添加该名片的被浏览记录 产品 入口
$is_exist = Db::name('browse_log')
->where(['topic_id' => $data['id'],'user_id' => $this->userId,'type' =>2])
->field('id')
->find();
if (!$is_exist) {
Db::name('browse_log')->insert(['topic_id' => $cardID,'user_id' => $this->userId,'type'=>2]);
}
//插入申请表
$result = Db::name('loans_apply')->insert(['product_id' => $data['id'],'user_id'=>$this->userId]);
if ($result === false) {
$this->error(['code'=>'40000','msg'=>'操作失败']);
}
$this->success('操作成功');
}
/**
* @title 匹配产品(普通用户)
* @description 产品
* @url /wxapp/product/matchingCard
* @method POST
*
* @header name:XX-Token type:string require:1 default:def other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:mobile type:int require:1 other: desc:电话
* @param name:age type:int require:1 other: desc:年龄
* @param name:job type:int require:1 other: desc:工作信息1上班2做生意3不限
* @param name:house type:int require:1 other: desc:房产信息1全款房2分期房0无
* @param name:policy type:int require:1 other: desc:保单信息1有0无2不限
* @param name:car type:int require:1 other: desc:车辆信息1全款车0无2不限
* @param name:page type:string require:0 other: desc:页码
* @param name:per_page type:string require:0 other: desc:每页数据量
*
* @return lower_total:总额度(最低)
* @return upper_total:总额度(最高)
* @return product_list:对象信息@!
* @product_list id:名片id name:名片名称 avatar:头像 position:职称 company:公司 tel:电话 email:邮箱 upper_limit:额度范围上限 lower_limit:额度范围下限
*/
public function matchingCard() {
$validate = new Validate([
'mobile' => 'require',
'age' => 'require',
'job' => 'require|in:1,2,3',
'house' => 'require|in:0,1,2',
'policy' => 'require|in:0,1,2',
'car' => 'require|in:0,1,2',
]);
$validate->message([
'mobile.require' => '缺少参数mobile!',
'age.require' => '缺少参数age!',
'job.require' => '缺少参数job!',
'job.in' => '参数job范围1-3!',
'house.require' => '缺少参数house!',
'house.in' => '参数house范围0-2!',
'policy.require' => '缺少参数policy!',
'policy.in' => '参数policy范围0-2!',
'car.require' => '缺少参数car!',
'car.in' => '参数car范围0-2!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
//保存用户数据到用户表
$arr = [
'mobile' => $data['mobile'],
'age' => $data['age'],
'job' => $data['job'],
'house' => $data['house'],
'policy' => $data['policy'],
'car' => $data['car']
];
Db::name('user')->where(['id' => $this->userId])->update($arr);
$per_page = $data['per_page'] ? : config('per_page');
if (isset($data['job']) && $data['job'] !=null && $data['job'] != 3) {
$condition['p.job'] = $data['job'];
}
if (isset($data['policy']) && $data['policy'] !=null && $data['policy'] != 2) {
$condition['p.policy'] = $data['policy'];
}
if (isset($data['car']) && $data['car'] !=null && $data['car'] != 2) {
$condition['p.car'] = $data['car'];
}
//加分享过的名片
$ids = Db::name('card_log')->where(['user_id' => $this->userId])->column('card_id');
$condition['c.id'] = ['in',$ids];//加分享过的名片
$condition['p.type'] = 1;//上架产品
$condition['p.house'] = $data['house'];
$list = Db::name('product')
->alias('p')
->join('user u','p.user_id=u.id','left')
->join('card c','p.user_id=c.user_id','left')
->where($condition)
->group('c.id')
->field('c.id,c.name,u.avatar,c.company,c.position,c.tel,c.email')
->order('p.create_time desc')
->paginate($per_page);
if ($list === false) {
$this->error(['code'=>'40000','msg'=>'获取失败']);
}
$result =[];
$result['product_list'] = $list;
//获取满足条件的 总额度
$result['lower_total'] = Db::name('product')
->alias('p')
->join('user u','p.user_id=u.id','left')
->join('card c','p.user_id=c.user_id','left')
->where($condition)
->sum('lower_limit');
$result['upper_total'] = Db::name('product')
->alias('p')
->where($condition)
->join('user u','p.user_id=u.id','left')
->join('card c','p.user_id=c.user_id','left')
->sum('upper_limit');
$this->success('获取成功',$result);
}
/**
* @title 匹配产品(信贷员)
* @description 产品
* @url /wxapp/product/matchingProduct
* @method POST
*
* @header name:XX-Token type:string require:1 default:def other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:mobile type:int require:1 other: desc:电话
* @param name:age type:int require:1 other: desc:年龄
* @param name:job type:int require:1 other: desc:工作信息1上班2做生意3不限
* @param name:house type:int require:1 other: desc:房产信息1全款房2分期房0无
* @param name:policy type:int require:1 other: desc:保单信息1有0无2不限
* @param name:car type:int require:1 other: desc:车辆信息1全款车0无2不限
* @param name:page type:string require:0 other: desc:页码
* @param name:per_page type:string require:0 other: desc:每页数据量
*
* @return lower_total:总额度(最低)
* @return upper_total:总额度(最高)
* @return product_list:对象信息@!
* @product_list id:产品id name:产品名称 logo:产品logo upper_limit:额度范围上限 lower_limit:额度范围下限 rate:月费率 loan_time:放款时间 is_apply:是否申请该产品贷款(1已申请0未申请)
*/
public function matchingProduct() {
$validate = new Validate([
'mobile' => 'require',
'age' => 'require',
'job' => 'require|in:1,2,3',
'house' => 'require|in:0,1,2',
'policy' => 'require|in:0,1,2',
'car' => 'require|in:0,1,2',
]);
$validate->message([
'mobile.require' => '缺少参数mobile!',
'age.require' => '缺少参数age!',
'job.require' => '缺少参数job!',
'job.in' => '参数job范围1-3!',
'house.require' => '缺少参数house!',
'house.in' => '参数house范围0-2!',
'policy.require' => '缺少参数policy!',
'policy.in' => '参数policy范围0-2!',
'car.require' => '缺少参数car!',
'car.in' => '参数car范围0-2!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
//保存用户数据到用户表
$arr = [
'mobile' => $data['mobile'],
'age' => $data['age'],
'job' => $data['job'],
'house' => $data['house'],
'policy' => $data['policy'],
'car' => $data['car']
];
Db::name('user')->where(['id' => $this->userId])->update($arr);
$per_page = $data['per_page'] ? : config('per_page');
//todo 个人信息 条件接收名片
//todo 个人信息 条件接收名片 新增全部
if (isset($data['job']) && $data['job'] !=null && $data['job'] != 3) {
$condition['p.job'] = $data['job'];
}
if (isset($data['policy']) && $data['policy'] !=null && $data['policy'] != 2) {
$condition['p.policy'] = $data['policy'];
}
if (isset($data['car']) && $data['car'] !=null && $data['car'] != 2) {
$condition['p.car'] = $data['car'];
}
$condition['p.type'] = 1;//上架产品
$condition['p.house'] = $data['house'];
$list = Db::name('product')
->alias('p')
->join('user u','p.user_id=u.id','left')
->join('card c','p.user_id=c.user_id','left')
->where($condition)
->field('p.id,p.name,p.logo,p.upper_limit,p.lower_limit,p.rate,p.loan_time,p.loan_period,c.company')
->order('p.create_time desc')
->paginate($per_page)->toArray();
if ($list === false) {
$this->error(['code'=>'40000','msg'=>'获取失败']);
}
if (count($list) > 0) {
foreach ($list['data'] as $k => $v) {
$check = Db::name('loans_apply')->where(['product_id' => $v['id'],'user_id' => $this->userId])->find();
if ($check) {
$list['data'][$k]['is_apply'] = 1;
} else {
$list['data'][$k]['is_apply'] = 0;
}
}
}
$result =[];
$result['product_list'] = $list;
//获取满足条件的 总额度
$result['lower_total'] = Db::name('product')->alias('p')->where($condition)->sum('lower_limit');
$result['upper_total'] = Db::name('product')->alias('p')->where($condition)->sum('upper_limit');
$this->success('获取成功',$result);
}
/**
* @title 获取公司列表信息(通过业务员id)
*
* @description 名片/产品列表公司信息下拉数据
* @url /wxapp/product/getCompanyByUserID
* @method POST
*
* @header name:XX-Token type:string require:1 default:abc other: desc:登录标识
* @header name:XX-Device-Type type:string require:0 default:wxapp other: desc:设备类型
*
* @param name:user_id type:string require:0 other: desc:业务员id
*
* @return data:对象信息@!
* @data id:名片id id avatar:头像 name:姓名 position:职称 tel:电话 home_tel:座机 email:邮箱 company:公司
*/
public function getCompanyByUserID() {
$validate = new Validate([
'user_id' => 'require',
]);
$validate->message([
'user_id.require' => '缺少参数user_id!',
]);
$data = $this->request->param();
$condition['p.user_id'] = $data['user_id'];
$result = Db::name('product')
->alias('p')
->join('user u','p.user_id=u.id','left')
->join('card c','p.user_id=c.user_id','left')
->where($condition)
->group('p.user_id')
->field('c.id,c.company')
->order('p.create_time desc')
->select();
if ($result === false) {
$this->error(['code'=>'40000','msg'=>'获取失败']);
}
$this->success('获取成功',$result);
}
}