Car.php
30.6 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
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
<?php
namespace app\serviceapi\controller;
use app\serviceapi\validate\Car as CarValidate;
use app\serviceapi\model\CarMember as CarMemberModel;
use app\serviceapi\model\Car as CarModel;
use app\serviceapi\model\CarOrder as CarOrderModel;
use app\serviceapi\model\CarInsurance as CarInsuranceModel;
use think\Request;
use util\MCurl;
use think\Cache;
use think\Log;
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
* 华安车险
* Created by PhpStorm.
* User: niuyongqing
* Date: 2020/7/20
* Time: 11:37
*/
class Car extends PingAn
{
// 第三次给的账号密码
private $mediaSource = 'YONGBAO_C';
private $user = 'izPX/JY0sZHXkCR+PwOYJQ==';
private $passWord = 'te23Tk+8U0d5VdLfsKB2Tg==';
private $cityCode = '360100';
//生产环境
// private $mediaSource = 'YONGBAO_C';
// private $user = 'izPX/JY0sZHXkCR+PwOYJQ==';
// private $passWord = 'izPX/JY0sZHXkCR+PwOYJQ==';
// private $cityCode = '360100';
/**
* 函数功能描述 车险订单
* Date: 2020/8/06
* Time: 10:00
* @author nyq
*/
public function carOrder()
{
$data = $this->request->post();
$where['staff_id']=$data['id'];
//时间搜索
if (isset($data['start']) && !empty($data['start']) && isset($data['end']) && !empty($data['end'])) {
$start_time = strtotime($data['start']);
$end_time = strtotime($data['end']);
$where['createTime'] = ['between', [$start_time, $end_time]];
} else if (isset($data['start']) && !empty($data['start']) && isset($data['end']) == false) {
$start_time = strtotime($data['start']);
$where['createTime'] = ['egt', $start_time];
} else if (isset($data['start']) == false && isset($data['end']) && !empty($data['end'])) {
$end_time = strtotime($data['end']);
$where['createTime'] = ['elt', $end_time];
}
//姓名
if (isset($data['name']) && !empty($data['name'])) {
$where['drvOwner'] = $data['name'];
}
//电话
if (isset($data['tel']) && !empty($data['tel'])) {
$where['certiTel'] = $data['tel'];
}
$user_model = new CarMemberModel();
$carOrder = $user_model->getMemberList($where, $data['offset'], $data['rows']);
return $carOrder;
}
/**
* 函数功能描述 车险订单详情
* Date: 2020/8/06
* Time: 16:00
* @author nyq
*/
public function carOrderDetail()
{
$id = $this->request->post();
$where['number_id']=$id;
$user_model = new CarOrderModel();
$carOrder = $user_model->getCarOrderList($where);
return $carOrder;
}
/**
* 函数功能描述 查询会员详情
* Date: 2020/8/11
* Time: 11:00
* @author nyq
*/
public function selMember()
{
$data = $this->request->post();
$where['id']=$data['id'];
$user_model = new CarMemberModel();
$user_info = $user_model->getUserByCode($where);
return $user_info;
}
/**
* 函数功能描述 支付前订单信息查询
* Date: 2020/8/11
* Time: 10:00
* @author nyq
*/
public function pay()
{
$data = $this->request->post();
$where['number_id']=$data['id'];
$user_model = new CarOrderModel();
$carOrder = $user_model->getCarOrderList($where);
return $carOrder;
}
/**
* 函数功能描述 车型查询
* Date: 2020/7/20
* Time: 14:12
* @author nyq
*/
public function carmodel()
{
$license = $this->request->post();
//进行数据验证
$validator = new CarValidate();
$res = $validator->scene("get_carmodel")->check($license);
if ($res === false) {
return $this->renderError($validator->getError());
}
$data = [
'head'=>[
// 请求渠道编码
'mediaSource'=>$this->mediaSource,
// 验证用户名
'user'=>$this->user,
// 验证用户密码
'passWord'=>$this->passWord,
// 交易标识号
'svcseqNo'=>'',
// 流程标识号
'flowId'=>'',
// 交易日期
'transDate'=>date("Y-m-d"),
],
'vhlInfo'=>[
// 车牌号
'vehicleNo'=>$license['vehicleNo'],
// 车架号
'frameNo'=>$license['frameNo'],
// 车型代码
'vehicleCode'=>'',
// 车型名称
'vehicleName'=>$license['vehicleName'],//'海马HMC7161',
// 行政区域代码
'cityCode'=>$license['cityCode'],
// 投保产品
'insuredProduct'=>'',
]
];
$file = ROOT_PATH . '/application/serviceapi/json/hua_an_1/carmodel.json';
if (!file_exists($file)) {
return $this->renderError("carmodel.json not found");
}
$json = json_decode(file_get_contents($file), true);
// head
$json['head'] = $this->clearData($json['head'], $data['head']);
// vhlInfo
$json['vhlInfo'] = $this->clearData($json['vhlInfo'], $data['vhlInfo']);
$json = json_encode($data);
$res = MCurl::instance($this->getUrl('carmodel'))->addHeaderIsJson()->post($json);
$res = json_decode($res, true);
//dump($res);
if ($res['head']['responseCode'] == 'C00000000') {
Cache::set('HuanAn_flowId', $res['head']['flowId'], 3600);
}
return $res;
}
/**
* 函数功能描述 车险保费计算
* Date: 2020/7/21
* Time: 09:12
* @author nyq
*/
public function premium()
{
$flowId = $this->getFlowId();
if (!$flowId) {
return $this->renderError("flowId error");
}
$default = [
'head'=>[
'mediaSource'=>$this->mediaSource,
'user'=>$this->user,
'passWord'=>$this->passWord,
'svcseqNo'=>'',
'flowId'=>$flowId,
'transDate'=>date('Y-m-d')
],
'base'=>[
'joinFlag'=>'1',
'cityCode'=>'420500',
'salesCode'=>'zhangjun13@sinosafe.com.cn'
//'channelCode'=> 'B011711875'
]
];
$data = $this->request->post('data');
//json数据中 特殊符号转义
$data = html_entity_decode($data);
//数据特殊符号转义
$data = htmlspecialchars_decode($data);
$data = json_decode($data, true);
$default['base']['cityCode'] = $data['cityCode'];
$data = array_merge($default, $data);
$file = ROOT_PATH . '/application/serviceapi/json/hua_an_1/premium.json';
if (!file_exists($file)) {
return $this->renderError('premium.json not found');
}
$json = json_decode(file_get_contents($file), true);
// head
$json['head'] = $this->clearData($json['head'], $data['head']);
//dump($json['head']);
// base
$json['base'] = $this->clearData($json['base'], $data['base']);
//dump($json['base']);
// vhl
$json['vhl'] = $this->clearData($json['vhl'], $data['vhl']);
//dump($json['vhl']);
// owner
$json['owner'] = $this->clearData($json['owner'], $data['owner']);
//dump($json['owner']);
// applacation
$json['applacation'] = $this->clearData($json['applacation'], $data['applacation']);
//dump($json['owner']);
// insured
$json['insured'] = $this->clearData($json['insured'], $data['insured']);
//dump($json['insured']);
$list = [];
foreach($data['riskList'] as $key=>$item) {
$riskList = $json['riskList'][0];
$coverageList = $riskList['coverageList'][0];
$tax = $riskList['tax'];
unset($riskList['coverageList']);
unset($riskList['tax']);
// 开始运算
$riskList = $this->clearData($riskList);
foreach($item as $key=>$val) {
if (!is_array($val)) {
$riskList[$key] = $val;
}
}
// tax
$riskList['tax'] = (object)$this->clearData($tax);
if (isset($item['tax'])) {
foreach($item['tax'] as $taxKey=>$taxItem) {
$riskList['tax'][$taxKey] = $taxItem;
}
}
// coverageList
$coverageList_arr = [];
if (isset($item['coverageList'])) {
foreach($item['coverageList'] as $listIndex=>$listItem) {
$coverageList = $this->clearData($coverageList);
foreach($listItem as $clKey=>$clItem) {
$coverageList[$clKey] = $clItem;
}
array_push($coverageList_arr, $coverageList);
}
}
$riskList['coverageList'] = $coverageList_arr;
array_push($list, $riskList);
}
$json['riskList'] = $list;
//进行数据整理多为变一维
$arr=$this->premiumArray($json);
//进行数据校验
$validator = new CarValidate();
$res = $validator->scene("get_premium")->check($arr);
if ($res === false) {
return $this->renderError($validator->getError());
}
//TODO 判断当前车辆信息是否存在
$where['frameNo'] = $json['vhl']['frameNo'];
// $sel=Db::name('car')->where($where)->find();
$car_model = new CarModel();
$car_info = $car_model->getCar($where);
if($car_info){
$where1['number_id'] = $car_info['number_id'];
//$ss=Db::name('order') ->where($where1)->select();
$carOrder_model = new CarOrderModel();
$carOrder_info = $carOrder_model->getCarOrderList($where1);
if($carOrder_info){
if($carOrder_info[0]['status'] ==9 && $carOrder_info[1]['status'] ==9){
$default = [
'head'=>[
'errorCode'=>'c999999999',
'responseCode'=>'c999999999',
'responseMsg'=>'车险订单已存在,无需重复下单',
]
];
return $default;
}
}
}
//TODO 执行添加用户基本信息的操作
//todo 这里获取到当前操作员的id
$staff_id=2;
$member = $this->member($json,$staff_id);
//$member=13;
$json = json_encode($json);
$res = MCurl::instance($this->getUrl('premium'))->addHeaderIsJson()->post($json);
$arr=json_decode($res, true);
//TODO 通过计算报价的返回信息,添加车辆,订单,险种信息
if($arr['head']['responseCode']=='C00000000'){
$car = $this->car($arr,$json,$member);
}
return $arr;
}
/**
* 函数功能描述 整理车险检验信息
* Date: 2020/7/21
* Time: 11:12
* @author nyq
*/
public function premiumArray($arr){
//车主信息
$owner=$arr['owner'];
//投保人
$applacation=$arr['applacation'];
//被保人
$insured=$arr['insured'];
//车辆信息
$vhl=$arr['vhl'];
//base
$base=$arr['base'];
$data=array_merge($owner,$applacation,$insured,$vhl,$base);
//险种信息
if(count($arr['riskList'])>1){
if($arr['riskList'][0]['riskCode'] != '' && $arr['riskList'][1]['riskCode'] != ''){
$data['xz']='true';
}else{
$data['xz']='';
}
}else{
$data['xz']='';
}
return $data;
}
/**
* 函数功能描述 车辆信息 订单信息 险种信息入库
* @param $data //华安返回的订单信息
* @param $json // 请求的基本信息
* @param $id // 用户id
* Date: 2020/7/21
* Time: 14:12
* @author nyq
*/
public function car($data,$json,$id){
//整理保存车辆信息
$arr=json_decode($json, true);
$car['number_id']=$id;
$car['licenseNo']=$arr['vhl']['licenseNo'];
$car['frameNo']=$arr['vhl']['frameNo'];
$car['engNo']=$arr['vhl']['engNo'];
$car['brndCode']=$arr['vhl']['brndCode'];
$car['registerDate']=$arr['vhl']['registerDate'];
$car['chgownerFlag']=$arr['vhl']['chgownerFlag'];
$car['transferDate']=$arr['vhl']['transferDate'];
$car['actualVal']=$data['vhl']['actualVal'];
$car['vhlVal']=$data['vhl']['vhlVal'];
$car['brndName']=$data['vhl']['brndName'];
$car['extMsr']=$data['vhl']['extMsr'];
$car['power']=$data['vhl']['power'];
$car['setNum']=$data['vhl']['setNum'];
$car['belongType']=$data['vhl']['belongType'];
$car['drvOwner']=$data['vhl']['drvOwner'];
$car['useType']=$data['vhl']['useType'];
$where['frameNo'] = $car['frameNo'];
$where['number_id'] = $id;
//判断当前用户车辆信息是否存在
$car_model = new CarModel();
$car_info = $car_model->getCar($where);
//$sel=Db::name('car')->where($where)->find();
if($car_info){
$car_model->updateCar($where,$car);
//Db::name('car') ->where($where)-> update($car);
}else{
$car_model->addCar($car);;
}
//todo 执行添加保险订单 交强险 其中包含车船税
$base=$data['jqBase'];
$tax=$data['jqBase']['tax'];
unset($base['ilogInfos'],$base['jqAdjust'],$base['coverageList'],$base['tax']);
$jqbase= array_merge($base,$tax);
$jqdata['number_id']=$id;
$jqdata['amount']=$jqbase['jqAmount'];
$jqdata['insrncStaTm']=$jqbase['jqBgnTm'];
$jqdata['calAppNo']=$jqbase['jqCalAppNo'];
$jqdata['demand']=$jqbase['jqDemand'];
$jqdata['insrncEndTm']=$jqbase['jqEndTm'];
$jqdata['premium']=$jqbase['jqPremium'];
$jqdata['currentTax']=$jqbase['currentTax'];
$jqdata['formerTax']=$jqbase['formerTax'];
$jqdata['lateFee']=$jqbase['lateFee'];
$jqdata['minusTaxAmt']=$jqbase['minusTaxAmt'];
$jqdata['sumUpTax']=$jqbase['sumUpTax'];
$jqdata['taxType']=$jqbase['taxType'];
$jqdata['taxVhlType']=$jqbase['taxVhlType'];
$jqdata['operDate']=time();
$jqdata['riskCode']='0301';
$where1['demand'] = $jqdata['demand'];
//CarOrderModel
$carOrder_model = new CarOrderModel();
$carOrder_info = $carOrder_model->getCarOrder($where1);
//$sel=Db::name('order')->where($where1)->find();
if($carOrder_info){
$carOrder_model->getCarOrderUpdate($where1,$jqdata);
//Db::name('order') ->where($where1)-> update($jqdata);
$jqid=$carOrder_info['id'];
}else{
$jqid=$carOrder_model->addCarOrder($jqdata);
// $jqid=Db::name('order') -> insertGetId($jqdata);
}
//TODO 执行添加订单信息 商业险
$base1=$data['syBase'];
unset($base1['ilogInfos'],$base1['syAdjust'],$base1['coverageList'],$base1['tax']);
$sydata['number_id']=$id;
$sydata['amount']=$base1['syAmount'];
$sydata['insrncStaTm']=$base1['syBgnTm'];
$sydata['calAppNo']=$base1['syCalAppNo'];
$sydata['demand']=$base1['syDemand'];
$sydata['insrncEndTm']=$base1['syEndTm'];
$sydata['premium']=$base1['syPremium'];
$sydata['riskCode']='0302';
$sydata['operDate']=time();
$where2['demand'] = $sydata['demand'];
$carOrder_info = $carOrder_model->getCarOrder($where2);
if($carOrder_info){
$carOrder_model->getCarOrderUpdate($where2,$sydata);
$syid=$carOrder_info['id'];
}else{
$syid=$carOrder_model->addCarOrder($sydata);
}
//todo 险种信息
//判断当前选择的险种是否存在(如果当前险种存在,就证明存在修改险种的可能,就删除原有险种,新增)
$sy_jq_id=$jqid.','.$syid;
$where3="order_id in (".$sy_jq_id.")";
$carinsurance_model = new CarInsuranceModel();
$carInsurance_info = $carinsurance_model->getCarInsurance($where3);
if(count($carInsurance_info)>0){
$carinsurance_model->getCarInsuranceDel($where3);
}
$jq=$data['jqBase']['coverageList'];
foreach ($jq as $key=>$val){
$jq[$key]['order_id']=$jqid;
$jq[$key]['franchiseFlag']=0;
}
$sy=$data['syBase']['coverageList'];
foreach ($sy as $key=>$val){
$sy[$key]['order_id']=$syid;
unset($sy[$key]['rate']);
}
$jq_sy_add= array_merge($jq,$sy);
for($i=0;$i<count($jq_sy_add);$i++){
$carinsurance_model->addCarInsurance($jq_sy_add[$i]);
// Db::name('insurance') -> insert($jq_sy_add[$i]);
}
}
/**
* 函数功能描述 用户信息入库
* @param $data
* Date: 2020/7/21
* Time: 09:30
* @author nyq
*/
public function member($data,$staff_id){
$owner['staff_id']=$staff_id;
//车主信息
$owner['drvOwner']=$data['owner']['drvOwner'];
$owner['certiTel']=$data['owner']['certiTel'];
$owner['certiCode']=$data['owner']['certiCode'];
$owner['certiType']=$data['owner']['certiType'];
$owner['drvSex']=$data['owner']['drvSex'];
$owner['drvownerAge']=$data['owner']['drvownerAge'];
//投保人
$owner['appName']=$data['applacation']['appName'];
$owner['appTel']=$data['applacation']['appTel'];
$owner['appCertType']=$data['applacation']['appCertType'];
$owner['appCertNo']=$data['applacation']['appCertNo'];
$owner['appSex']=$data['applacation']['appSex'];
$owner['appAge']=$data['applacation']['appAge'];
//被保人
$owner['insuredName']=$data['insured']['insuredName'];
$owner['insuredTel']=$data['insured']['insuredTel'];
$owner['insuredCertType']=$data['insured']['insuredCertType'];
$owner['insuredCertNo']=$data['insured']['insuredCertNo'];
$owner['insuredSex']=$data['insured']['insuredSex'];
$owner['insuredAge']=$data['insured']['insuredAge'];
$owner['cityCode']=$data['base']['cityCode'];
$owner['salesCode']=$data['base']['salesCode'];
$owner['joinFlag']=$data['base']['joinFlag'];
$owner['createTime']=time();
//根据用户身份证判断用户是否存在
$user_model = new CarMemberModel();
$where['certiCode'] = $owner['certiCode'];
$where['insuredCertNo'] = $owner['insuredCertNo'];
$user_info = $user_model->getUserByCode($where);
if($user_info){
$user = $user_model->getUpdateByCode($owner['certiCode'],$owner);
$sql=$user_info['id'];
}else{
$sql = $user_model->addMember($owner);
//$sql=Db::name('member') -> insertGetId($owner);
}
return $sql;
}
/**
* 函数功能描述 车险提交核保
* Date: 2020/7/22
* Time: 09:30
* @author nyq
*/
public function underwrite()
{
$flowId = $this->getFlowId();
if (!$flowId) {
return 'flowId error';
}
$head = [
'mediaSource'=>$this->mediaSource,
'user'=>$this->user,
'passWord'=>$this->passWord,
'svcseqNo'=>'KJ12033265123601',
'flowId'=>$flowId,
'transDate'=>date('Y-m-d')
];
$file = ROOT_PATH . '/application/serviceapi/json/hua_an_1/underwrite.json';
if (!file_exists($file)) {
return $this->renderError('underwrite.json not found');
}
$json = json_decode(file_get_contents($file), true);
$base = $this->request->post('data');
//json数据中 特殊符号转义
$base = html_entity_decode($base);
$base = htmlspecialchars_decode($base);
$base = json_decode($base, true);
//进行数据校验
$validator = new CarValidate();
$res = $validator->scene("get_underwrite")->check($base);
if ($res === false) {
return $this->renderError($validator->getError());
}
$data = [
'head'=>$head,
'base'=>$base
];
//反洗钱规则,新增投保被保人身份证有效期,地址
$data['base']['appIdentifyExpiry']='2028-08-08';
$data['base']['insrntIdentifyExpiry']='2028-08-08';
$data['base']['appProvinceCode']='420000';
$data['base']['appCityCode']='420500';
$data['base']['appDistrictCode']='420525';
$data['base']['insrntProvinceCode']='420000';
$data['base']['insrntCityCode']='420500';
$data['base']['insrntDistrictCode']='420525';
unset($data['base']['appntList']);
// head
$json['head'] = $this->clearData($json['head'], $data['head']);
// base
$json['base'] = $this->clearData($json['base'], $data['base']);
$appntList = $json['appntList'][0];
$parameterList = $appntList['parameterList'][0];
unset($json['appntList']);
unset($appntList['parameterList']);
if (count($base['appntList']) > 0) {
// 手动特约参数信息1
$parameterList = $this->clearData($parameterList);
$parameterList['paramterKey'] = 'HA0012N_Name';
$parameterList['paramterName'] = '受益人';
$appntList['parameterList'][] = $parameterList;
// 手动特约参数信息2
$parameterList = $this->clearData($parameterList);
$parameterList['paramterKey'] = 'HA0012N_Name2';
$parameterList['paramterName'] = '第二受益人';
$appntList['parameterList'][] = $parameterList;
// 特别约定
$appntList = $this->clearData($appntList);
$appntList['prodNo'] = '301';
$appntList['appntCode'] = 'H000001';
$appntList['appntName'] = '测试使用';
$appntList['appntDtl'] = '测试使用';
$json['appntList'][] = $appntList;
}
$json = json_encode($json);
$res = MCurl::instance($this->getUrl('underwrite'))->addHeaderIsJson()->post($json);
//TODO 通过计算报价的返回信息,给订单添加 订单号,状态,保险查询码
$res=json_decode($res, true);
if(isset($res['resultList'])){
$this->update_order($res['resultList']);
}
return $res;
}
/**
* 函数功能描述 保存核保订单信息
* Date: 2020/7/22
* Time: 10:30
* @author nyq
*/
public function update_order($res){
$data=[];
foreach($res as $key=>$val){
$data[$key]['appNo']=$val['appNo'];
$data[$key]['status']=$val['status'];
$data[$key]['demand']=$val['demandNo'];
}
$where3="demand in ('".$res[0]['demandNo']."','".$res[1]['demandNo']."')";
//根据返回的查询码,进行订单数据修改
$carOrder_model = new CarOrderModel();
$carOrder_info = $carOrder_model->getCarOrderList($where3);
//$sy_jq_sel=Db::name('order')->where($where3)->select();
if(count($carOrder_info)>0){
for($i=0;$i<count($data);$i++){
$where=['demand'=>$data[$i]['demand']];
$carOrder_model->getCarOrderUpdate($where,$data[$i]);
//Db::name('order')->where(['demand'=>$data[$i]['demand']])->update($data[$i]);
}
}
}
/**
* 函数功能描述 支付申请接口
* Date: 2020/7/22
* Time: 11:30
* @author nyq
*/
public function payment()
{
$flowId = $this->getFlowId();
if (!$flowId) {
return 'flowId error';
}
$data = [
'head'=>[
'mediaSource'=>$this->mediaSource,
'user'=>$this->user,
'passWord'=>$this->passWord,
'flowId'=>$flowId,
'transDate'=>date('Y-m-d')
]
];
$file = ROOT_PATH . '/application/sapi/json/hua_an_1/payment.json';
if (!file_exists($file)) {
throw new Exception('payment.json not found');
}
$json = json_decode(file_get_contents($file), true);
// head
$json['head'] = $this->clearData($json['head'], $data['head']);
// base
$base = $json['base'][0];
unset($json['base']);
// 基本信息2
//$base = $this->clearData($base);
$base = $this->request->post('data');
//json数据中 特殊符号转义
$base = html_entity_decode($base);
$base = htmlspecialchars_decode($base);
$base=json_decode($base, true);
//进行数据校验
$validator = new CarValidate();
$res = $validator->scene("get_pay")->check($base);
if ($res === false) {
return $this->renderError($validator->getError());
}
$base=[
[
'applicantNo'=>$base['syAppNo'],
'amount'=>$base['syAmount'],
'applicantName'=>$base['syAppName']
],[
'applicantNo'=>$base['jqAppNo'],
'amount'=>$base['jqAmount'],
'applicantName'=>$base['jqAppName']
]
];
$json['base'] = $base;
$json = json_encode($json);
$res = MCurl::instance($this->getUrl('payment'))->addHeaderIsJson()->post($json);
//$res="{\"head\":{\"errorCode\":\"C0000000\",\"flowId\":\"A0NCNK1KD1SHFNY5\",\"responseCode\":\"C00000000\",\"responseMsg\":\"成功!\",\"svcseqNo\":\"\"},\"resultInfo\":{\"payAddress\":\"https://mtest.sinosafe.com.cn/eb-web/pay/m/index.html?sysCode=07&applyNo=207002102227\",\"payAppNo\":\"207002102227\",\"remark\":\"\"}}";
$res=json_decode($res, true);
return $res;
}
/**
* 清理并充填数据
*/
private function clearData($obj, $data = [])
{
foreach($obj as $key=>$item) {
if (!is_array($item)) {
$obj[$key] = '';
if (isset($data[$key])) {
$obj[$key] = $data[$key];
}
}
}
return $obj;
}
/**
* 获取地址
*/
private function getUrl($interface)
{
//return 'http://agent.sinosafe.com.cn/eauto_open/' . $interface;
return 'http://agenttest.sinosafe.com.cn/eauto_open/' . $interface;
}
/**
* 函数功能描述 人工核保回调接口
* Date: 2020/7/22
* Time: 14:00
* @author nyq
*
* TODO 转 notify/car/artificial_callback
*
*/
public function artificial_callback()
{
$data = $this->request->get();
log::write($data);
$jq_base['jq_ply_app_no']=$data['jq_ply_app_no'];
$jq_base['jq_udr_mrk']=$data['jq_udr_mrk'];
$jq_base['jq_udr_msg']=$data['jq_udr_msg'];
$sy_base['sy_ply_app_no']=$data['sy_ply_app_no'];
$sy_base['sy_udr_mrk']=$data['sy_udr_mrk'];
$sy_base['sy_udr_msg']=$data['sy_udr_msg'];
$json['jq_base']=$jq_base;
$json['sy_base']=$sy_base;
//TODO 人工核保回调 入库
$num=[0,3,7];
$carOrder_model = new CarOrderModel();
if(in_array($sy_base['sy_udr_mrk'],$num)){
file_put_contents('callback/'.$data['sy_ply_app_no'].'.json',json_encode($json['sy_base'],true));
// $sy_data['appNo']=$data['sy_ply_app_no'];
// $sy_data['status']=$data['sy_udr_mrk'];
//
// //Db::name('order')->where(['appNo'=>$data['sy_ply_app_no']])->update($sy_data);
//
// $where=['appNo'=>$data['sy_ply_app_no']];
// $carOrder_model->getCarOrderUpdate($where,$sy_data);
}
if(in_array($jq_base['jq_udr_mrk'],$num)){
file_put_contents('callback/'.$data['jq_ply_app_no'].'.json',json_encode($json['jq_base'],true));
// $jq_data['appNo']=$data['jq_ply_app_no'];
// $jq_data['status']=$data['jq_udr_mrk'];
//
// // Db::name('order')->where(['appNo'=>$data['jq_ply_app_no']])->update($jq_data);
//
// $where=['appNo'=>$data['jq_ply_app_no']];
// $carOrder_model->getCarOrderUpdate($where,$jq_data);
}
$res = [
'svcseqNo'=>'',
'flowId'=>'',
'responseCode'=>'C00000000', //'C00000000 成功返回;C99999999 失败;E00000000 异常',
'responseMsg'=>'',
];
return $res;
}
/**
* 支付/核保回调状态查询
*
*/
public function get_status()
{
$base = $this->request->post();
$jq_file = ROOT_PATH . '/public/callback/'.$base['jq'].'.json';
$sy_file = ROOT_PATH . '/public/callback/'.$base['sy'].'.json';
if (!file_exists($jq_file) && !file_exists($sy_file)) {
return [];
}else{
$jq_json = json_decode(file_get_contents($jq_file), true);
$sy_json = json_decode(file_get_contents($sy_file), true);
$json['jq_ply_app_no']=$jq_json["jq_ply_app_no"];
$json['jq_udr_mrk']=$jq_json['jq_udr_mrk'];
$json['jq_udr_msg']=$jq_json['jq_udr_msg'];
$json['sy_ply_app_no']=$sy_json['sy_ply_app_no'];
$json['sy_udr_mrk']=$sy_json['sy_udr_mrk'];
$json['sy_udr_msg']=$sy_json['sy_udr_msg'];
if($json['jq_udr_mrk'] == $json['sy_udr_mrk']){
$res[0]['appNo']=$json['jq_ply_app_no'];
$res[0]['status']=$json['jq_udr_mrk'];
$res[1]['appNo']=$json['sy_ply_app_no'];
$res[1]['status']=$json['jq_udr_mrk'];
$data=[];
foreach($res as $key=>$val){
$data[$key]['appNo']=$val['appNo'];
$data[$key]['status']=$val['status'];
}
$where3="appNo in ('".$res[0]['appNo']."','".$res[1]['appNo']."')";
$sy_jq_sel=Db::name('order')->where($where3)->select();
if(count($sy_jq_sel)>0){
for($i=0;$i<count($data);$i++){
Db::name('order')->where(['appNo'=>$data[$i]['appNo']])->update($data[$i]);
}
}
}
//unlink($sy_file);
//unlink($jq_file);
}
return $json;
}
/**
* 函数功能描述 支付回调接口
* Date: 2020/7/22
* Time: 14:00
* @author nyq
*
* TODO 转 notify/car/pay_callback
*
*/
public function pay_callback()
{
$data = $this->request->get();
log::write($data);
$base['result']=$data['result'];
$base['jq_ply_no']=$data['jq_ply_no'];
$base['sy_ply_no']=$data['sy_ply_no'];
$base['pay_app_no']=$data['pay_app_no'];
$base['jq_app_ply_no']=$data['jq_app_ply_no'];
$base['sy_app_ply_no']=$data['sy_app_ply_no'];
$json['base']=$base;
if($base['result']==0){
file_put_contents('callback/'.$data['jq_ply_no'].'.json',json_encode($json,true));
$sta = ['status'=>9];
}else{
$sta = ['status'=>8];
}
$wheres = [$data['jq_app_ply_no'],$data['sy_app_ply_no']];
$res = Db::name('order')->whereIn('appNo',$wheres)->update($sta);
$base['call_back']=time();
Db::name('callback')->insert($base);
$res = [
'svcseqNo'=>'',
'flowId'=>'',
'responseCode'=>'C00000000',
'responseMsg'=>'',
];
return $res;
}
/**
* 生成FlowId接口
*/
public function getFlowId()
{
$flowId = Cache::get('HuanAn_flowId');
if($flowId !== false) {
return $flowId;
}
$data = [
'head'=>[
'mediaSource'=>$this->mediaSource,
'user'=>$this->user,
'passWord'=>$this->passWord,
'transDate'=>date('Y-m-d')
]
];
//dump($data);
$data = json_encode($data);
$res = MCurl::instance($this->getUrl('getFlowId'))->addHeaderIsJson()->post($data);
$res = json_decode($res, true);
//dump($res);
if ($res['head']['responseCode'] == 'C00000000') {
$flowId = $res['data']['flowId'];
Cache::set('HuanAn_flowId', $flowId, 3600);
}
return $flowId;
}
}