puzhibing
2023-08-01 98bc380ae322eaac2ee7e21d0c565e30eacce2b5
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
package com.stylefeng.guns.modular.smallLogistics.server.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.smallLogistics.dao.OrderLogisticsMapper;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogisticsSpread;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsSpreadService;
import com.stylefeng.guns.modular.system.dao.RegionMapper;
import com.stylefeng.guns.modular.system.dao.SensitiveWordsMapper;
import com.stylefeng.guns.modular.system.dao.SysIntegralMapper;
import com.stylefeng.guns.modular.system.dao.SystemPriceMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
 
 
@Service
public class OrderLogisticsServiceImpl extends ServiceImpl<OrderLogisticsMapper, OrderLogistics> implements IOrderLogisticsService {
 
    @Resource
    private SystemPriceMapper systemPriceMapper;
 
    @Resource
    private OrderLogisticsMapper orderLogisticsMapper;
 
    @Resource
    private SensitiveWordsMapper sensitiveWordsMapper;
 
    @Autowired
    private ICompanyCityService companyCityService;
 
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
 
    @Autowired
    private DateUtil dateUtil;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
    @Autowired
    private IPushOrderService pushOrderService;
 
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private PushUtil pushUtil;
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Autowired
    private IPaymentRecordService paymentRecordService;
 
//    @Autowired
//    private ICBCPayUtil icbcPayUtil;
 
    @Resource
    private SysIntegralMapper sysIntegralMapper;
 
    @Autowired
    private ITransactionDetailsService transactionDetailsService;
 
    @Autowired
    private ICompanyService companyService;
 
    @Autowired
    private IIncomeService incomeService;
 
    @Autowired
    private IOrderCancelService orderCancelService;
 
    @Autowired
    private IOrderLogisticsSpreadService orderLogisticsSpreadService;
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Resource
    private RegionMapper regionMapper;
 
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
    @Autowired
    private PayMoneyUtil payMoneyUtil;
 
    @Value("${callbackPath}")
    private String callbackPath;
 
    private static List<Integer> orderIds = new ArrayList<>();
 
 
 
    /**
     * 根据起点和终点坐标判断是不是同一个市内
     * @param startLonLat
     * @param endAddress
     * @return
     */
    @Override
    public ResultUtil judgingTheCity(String startLonLat, String endAddress) throws Exception {
        Map<String, String> sgeocode = gdMapGeocodingUtil.geocode(startLonLat.split(",")[0], startLonLat.split(",")[1]);
        String scityCode = sgeocode.get("cityCode");
        Map<String, Object> geocoding = gdMapGeocodingUtil.geocoding(endAddress);
        if(Integer.valueOf(geocoding.get("status").toString()) != 0){
            return ResultUtil.error("收货地址有误,无法查询具体地址信息");
        }
        List<String> list = (List<String>)geocoding.get("data");
        Map<String, String> egeocode = gdMapGeocodingUtil.geocode(list.get(0).split(",")[0], list.get(0).split(",")[1]);
        String ecityCode = egeocode.get("cityCode");
        if(!scityCode.equals(ecityCode)){
            return ResultUtil.error("已超出服务范围,请重新选择跨城小件物流");
        }
        return ResultUtil.success();
    }
 
 
    /**
     * 获取小件物流的单价
     * @param type
     * @param startLonLat
     * @param endAddress
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil queryLogisticsUnitPrice(Integer type, String startLonLat, String endAddress, Integer uid) throws Exception {
        Company query = companyCityService.query(startLonLat.split(",")[0], startLonLat.split(",")[1]);
        if(null == query){
            return ResultUtil.error("预约取货点暂无企业服务");
        }
        Double price1 = 0D;
        Double price2 = 0D;
        if(type == 4){//同城
            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
            if(null == query1){
                return ResultUtil.error("请先完善价格设定");
            }
            String content = String.valueOf(query1.get("content"));
            JSONObject jsonObject = JSON.parseObject(content);
            price1 = jsonObject.getDouble("num2");
            price2 = jsonObject.getDouble("num13");
        }else{
            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
            if(null == query1){
                return ResultUtil.error("请先完善价格设定");
            }
            String content = String.valueOf(query1.get("content"));
            JSONObject jsonObject = JSON.parseObject(content);
            price1 = jsonObject.getDouble("num1");
            price2 = jsonObject.getDouble("num2");
        }
        int i = this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId", uid).eq("isDelete", 1));
        Map<String, Object> map = new HashMap<>();
        map.put("ordinary", price1);
        map.put("precious", price2);
        map.put("first", i);
        return ResultUtil.success(map);
    }
 
 
    /**
     * 获取支付金额
     * @param type
     * @param startLonLat
     * @param endAddress
     * @return
     * @throws Exception
     */
    public ResultUtil queryPayMoney(Integer number, Integer type, String startLonLat, String endAddress) throws Exception{
        Map<String, Object> geocoding = gdMapGeocodingUtil.geocoding(endAddress);
        if(Integer.valueOf(geocoding.get("status").toString()) != 0){
            return ResultUtil.error("收货地址有误,无法查询具体地址信息");
        }
        String location = ((List<String>)geocoding.get("data")).get(0);
        ResultUtil<Map<String, Double>> price = this.getPrice(type, startLonLat.split(",")[0], startLonLat.split(",")[1], location.split(",")[0], location.split(",")[1]);
        if(price.getCode() == 200 && type == 5){
            Map<String, Double> data = price.getData();
            data.put("ordinary", data.get("ordinary") * number);
            data.put("precious", data.get("precious") * number);
        }
        return price;
    }
 
 
 
 
    /**
     * 小件物流下单操作
     * @param type
     * @param cargoType
     * @param cargoNumber
     * @param remark
     * @param placementLon
     * @param placementLat
     * @param startLon
     * @param startLat
     * @param startAddress
     * @param recipient
     * @param recipientPhone
     * @param endAddress
     * @param travelTime
     * @param orderSource
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil smallLogistics(Integer type, Integer cargoType, Integer cargoNumber, String remark, String placementLon, String placementLat, String startLon, String startLat, String startAddress, String recipient,
                                     String recipientPhone, String endAddress, Integer urgent, Double tipMoney, Date travelTime, Integer orderSource, Integer uid) throws Exception {
        startAddress = startAddress.replaceAll("& #40;", "(");
        startAddress = startAddress.replaceAll("& #41;", ")");
        endAddress = endAddress.replaceAll("& #40;", "(");
        endAddress = endAddress.replaceAll("& #41;", ")");
        OrderLogistics orderLogistics = new OrderLogistics();
        Company query = companyCityService.query(placementLon, placementLat);
        if(null == query){
            return ResultUtil.error("该地点暂无企业服务");
        }
        orderLogistics.setCompanyId(query.getId());
        orderLogistics.setType(type);
        orderLogistics.setUserId(uid);
        orderLogistics.setOrderNum(this.getOrderNum());
        orderLogistics.setCargoType(cargoType);
        orderLogistics.setCargoNumber(cargoNumber);
        orderLogistics.setRemark(remark);
        orderLogistics.setPlacementLon(Double.valueOf(placementLon));
        orderLogistics.setPlacementLat(Double.valueOf(placementLat));
        Map<String, String> geocode = gdMapGeocodingUtil.geocode(placementLon, placementLat);
        orderLogistics.setPlacementAddress(geocode.get("address"));
        orderLogistics.setStartLon(Double.valueOf(startLon));
        orderLogistics.setStartLat(Double.valueOf(startLat));
        orderLogistics.setStartAddress(startAddress);
        Map<String, Object> geocoding = gdMapGeocodingUtil.geocoding(endAddress);
        if(Integer.valueOf(geocoding.get("status").toString()) != 0){
            return ResultUtil.error("收货地址有误,无法查询具体地址信息");
        }
        if(((List<String>)geocoding.get("data")).size() == 0){
            return ResultUtil.error("无法查询具体地址信息");
        }
        String location = ((List<String>)geocoding.get("data")).get(0);
        orderLogistics.setEndLon(Double.valueOf(location.split(",")[0]));
        orderLogistics.setEndLat(Double.valueOf(location.split(",")[1]));
        orderLogistics.setEndAddress(endAddress);
        orderLogistics.setUrgent(urgent);
        orderLogistics.setRecipient(recipient);
        orderLogistics.setRecipientPhone(recipientPhone);
        orderLogistics.setMileage(0D);
        orderLogistics.setIsReassign(1);
        orderLogistics.setReassignNotice(0);
        ResultUtil<Map<String, Double>> price = this.getPrice(type, String.valueOf(startLon), String.valueOf(startLat), location.split(",")[0], location.split(",")[1]);
        if(price.getCode() != 200){
            return price;
        }
        Map<String, Double> data = price.getData();
        orderLogistics.setOrderMoney((cargoType == 1 ? data.get("ordinary") : data.get("precious")) + tipMoney);
        orderLogistics.setTravelMoney(cargoType == 1 ? data.get("ordinary") : data.get("precious"));
        if(type == 5){
            orderLogistics.setOrderMoney(((cargoType == 1 ? data.get("ordinary") : data.get("precious")) * cargoNumber) + tipMoney);
            orderLogistics.setTravelMoney((cargoType == 1 ? data.get("ordinary") : data.get("precious")) * cargoNumber);
        }
        orderLogistics.setTipMoney(tipMoney);
        orderLogistics.setState(7);//待支付
        orderLogistics.setInsertTime(new Date());
        orderLogistics.setTravelTime(travelTime);
        orderLogistics.setOrderSource(orderSource);
        orderLogistics.setIsDelete(1);
        this.insert(orderLogistics);
 
        //添加消息
        systemNoticeService.addSystemNotice(1, "您的"+ (type == 4 ? "同城" : "跨城") + "小件物流订单已下单成功,我们正在为您指派司机,请稍后!", orderLogistics.getUserId(), 1);
 
        BaseWarpper baseWarpper = new BaseWarpper();
        baseWarpper.setId(orderLogistics.getId());
        return ResultUtil.success(baseWarpper);
    }
 
 
    /**
     * 获取价格
     * @param type
     * @return
     * @throws Exception
     */
    public ResultUtil<Map<String, Double>> getPrice(Integer type, String startLon, String startLat, String endLon, String endLat) throws Exception{
        Company query = companyCityService.query(startLon, startLat);
        if(null == query){
            return ResultUtil.error("预约取货点暂无企业服务");
        }
        Double price1 = 0D;
        Double price2 = 0D;
        if(type == 4){//同城
            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
            Map<String, String> distance = gdMapElectricFenceUtil.getDistance(startLon + "," + startLat, endLon + "," + endLat, 1);
            String content = String.valueOf(query1.get("content"));
            JSONObject jsonObject = JSON.parseObject(content);
            String distance1 = distance.get("distance");
            Double dist = Double.valueOf(distance1) / 1000;
            if(dist.compareTo(0D) >= 0 && dist.compareTo(jsonObject.getDouble("num1")) < 0){
                price1 = jsonObject.getDouble("num2");
            }
            if(dist.compareTo(0D) >= 0 && dist.compareTo(jsonObject.getDouble("num12")) < 0){
                price2 = jsonObject.getDouble("num13");
            }
 
            if(dist.compareTo(jsonObject.getDouble("num3")) >= 0 && dist.compareTo(jsonObject.getDouble("num4")) < 0){
                price1 = jsonObject.getDouble("num5");
            }
            if(dist.compareTo(jsonObject.getDouble("num14")) >= 0 && dist.compareTo(jsonObject.getDouble("num15")) < 0){
                price2 = jsonObject.getDouble("num16");
            }
 
            if(dist.compareTo(jsonObject.getDouble("num6")) >= 0 && dist.compareTo(jsonObject.getDouble("num7")) < 0){
                price1 = jsonObject.getDouble("num8");
            }
            if(dist.compareTo(jsonObject.getDouble("num17")) >= 0 && dist.compareTo(jsonObject.getDouble("num18")) < 0){
                price2 = jsonObject.getDouble("num19");
            }
 
            if(dist.compareTo(jsonObject.getDouble("num9")) >= 0 && dist.compareTo(jsonObject.getDouble("num10")) < 0){
                price1 = jsonObject.getDouble("num11");
            }
            if(dist.compareTo(jsonObject.getDouble("num20")) >= 0 && dist.compareTo(jsonObject.getDouble("num21")) < 0){
                price2 = jsonObject.getDouble("num22");
            }
        }else{
            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
            String content = String.valueOf(query1.get("content"));
            JSONObject jsonObject = JSON.parseObject(content);
            price1 = jsonObject.getDouble("num1");
            price2 = jsonObject.getDouble("num2");
        }
        Map<String, Double> map = new HashMap<>();
        map.put("ordinary", price1);//普通
        map.put("precious", price2);//贵重
        return ResultUtil.success(map);
    }
 
 
 
    /**
     * 推送抢单数据
     * @param orderLogistics
     * @throws Exception
     */
    public void pushOrder(OrderLogistics orderLogistics) throws Exception{
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    orderIds.add(orderLogistics.getId());//添加记录,防止调用接口重复提醒无人接单
                    String vehicle = redisUtil.getValue("VEHICLE");
                    List<Integer> integers = new ArrayList<>();
                    if(ToolUtil.isNotEmpty(vehicle)){
                        integers = JSON.parseArray(vehicle).toJavaList(Integer.class);
                    }
                    Company query = companyCityService.query(String.valueOf(orderLogistics.getStartLon()), String.valueOf(orderLogistics.getStartLat()));//获取起点所属分公司
                    List<PushOrder> querys = pushOrderService.querys(null, 1, query.getId());//用专车的推单配置
                    for(int i = 1; i <= querys.size(); i++){
                        PushOrder pushOrder = pushOrderService.querys(i, 1, query.getId()).get(0);
                        //获取空闲司机
                        List<Driver> list = driverService.queryIdleDriver(orderLogistics.getType(), null, orderLogistics.getStartLon(), orderLogistics.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
                        if(list.size() > 0){
                            double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数
                            int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取)
                            list = list.subList(0, lastIndex);//获取空闲司机中占比数据
                            for(Driver driver : list){//开始进行推送
                                boolean bo = false;
                                for(Integer integer : integers){
                                    if(integer.compareTo(driver.getId()) == 0){
                                        bo = true;
                                        break;
                                    }
                                }
                                if(bo){
                                    continue;
                                }
                                pushUtil.pushOrderState(2, driver.getId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), pushOrder.getPushTime());
                            }
                        }
                        Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间
                        Integer state = orderLogisticsMapper.selectById(orderLogistics.getId()).getState();
                        if(state > 1){
                            break;
                        }
                        if(i == querys.size() && state == 1){
//                            pushUtil.pushEndPush(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType());
                            orderIds.remove(orderLogistics.getId());
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
 
 
 
 
    /**
     * 订单支付
     * @param payType
     * @param orderId
     * @param type
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil payLogisticsOrder(Integer payType, Integer orderId, Integer type) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(orderLogistics.getState() != 7){
            return ResultUtil.error("订单已完成支付,不允许重复支付");
        }
        Integer uid = orderLogistics.getUserId();
        Double orderMoney = orderLogistics.getOrderMoney();
        UserInfo userInfo = userInfoService.selectById(uid);
        ResultUtil resultUtil = ResultUtil.success();
 
        if(payType == 1){//微信支付
            String app = type == 1 ? "APP" : "JSAPI";
            resultUtil = payMoneyUtil.weixinpay("小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(),  "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 1);//添加预支付数据
        }
        if(payType == 2){//支付宝支付
            resultUtil = payMoneyUtil.alipay("小件物流下单支付", "小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi");
            paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 2, orderMoney, "", 1);//添加预支付数据
        }
 
 
//        if(payType == 1){//微信支付
//            String value = redisUtil.getValue("appletOpenId");
//            String appletsOpenId = null;
//            if(ToolUtil.isNotEmpty(value)){
//                JSONObject jsonObject = JSON.parseObject(value);
//                appletsOpenId = jsonObject.getString(uid.toString());
//            }else{
//                appletsOpenId = userInfo.getAppletsOpenId();
//            }
//            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 9, 5, uid.toString(), "小件物流下单支付", orderMoney, callbackPath + "/base/wxPayOrderTaxi", "", type, appletsOpenId);
//            if(map.get("code").equals("200")){
//                paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, map.get("order_id"), 1);//添加预支付数据
//                resultUtil = ResultUtil.success(map.get("data"));
//            }else{
//                resultUtil = ResultUtil.error(map.get("msg"), "");
//            }
//        }
//        if(payType == 2){//支付宝支付
//            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 10, 5, uid.toString(), "小件物流下单支付", orderMoney, callbackPath + "/base/aliPayOrderTaxi", "", type, null);
//            if(map.get("code").equals("200")){
//                paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 2, orderMoney, map.get("order_id"), 1);//添加预支付数据
//                resultUtil = ResultUtil.success(map.get("data"));
//            }else{
//                resultUtil = ResultUtil.error(map.get("msg"), "");
//            }
//        }
        if(payType == 3){//余额支付
            if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){
                return ResultUtil.error("余额不足,无法完成支付");
            }
 
            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
 
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
 
            //添加交易明细
            transactionDetailsService.saveData(uid, "小件物流下单支付", orderMoney, 2, 1, 1, 4, orderId);
            userInfoService.updateById(userInfo);
 
            orderLogistics.setState(1);//小件物流先支付后司机抢单
            orderLogistics.setPayType(3);
            orderLogistics.setPayMoney(orderMoney);
 
            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
                }
            }).start();
 
            systemNoticeService.addSystemNotice(1, "您已使用余额成功完成小件物流订单支付,谢谢使用!", uid, 1);
 
            this.pushOrder(orderLogistics);//推单
        }
 
        this.updateById(orderLogistics);
        return resultUtil;
    }
 
 
 
 
    /**
     * 补差价支付
     * @param payType
     * @param orderId
     * @param type
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil payLogisticsOrder_(Integer payType, Integer orderId, Integer type) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        Integer uid = orderLogistics.getUserId();
        OrderLogisticsSpread orderLogisticsSpread = orderLogisticsSpreadService.selectOne(new EntityWrapper<OrderLogisticsSpread>().eq("orderLogisticsId", orderId));
        Double orderMoney = orderLogisticsSpread.getPrice();
        UserInfo userInfo = userInfoService.selectById(uid);
        ResultUtil resultUtil = ResultUtil.success();
 
        if(payType == 1){//微信支付
            String app = type == 1 ? "APP" : "JSAPI";
            resultUtil = payMoneyUtil.weixinpay("小件物流补差价", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderLogisticsSpread", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 1);//添加预支付数据
        }
        if(payType == 2){//支付宝支付
            resultUtil = payMoneyUtil.alipay("小件物流补差价", "小件物流补差价", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderLogisticsSpread");
            paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 2, orderMoney, "", 1);//添加预支付数据
        }
 
//        if(payType == 1){//微信支付
//            String value = redisUtil.getValue("appletOpenId");
//            String appletsOpenId = null;
//            if(ToolUtil.isNotEmpty(value)){
//                JSONObject jsonObject = JSON.parseObject(value);
//                appletsOpenId = jsonObject.getString(uid.toString());
//            }else{
//                appletsOpenId = userInfo.getAppletsOpenId();
//            }
//            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 9, 5, uid.toString(), "小件物流补差价", orderMoney, callbackPath + "/base/wxPayOrderLogisticsSpread", "", type, appletsOpenId);
//            if(map.get("code").equals("200")){
//                paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, map.get("order_id"), 1);//添加预支付数据
//                resultUtil = ResultUtil.success(map.get("data"));
//            }else{
//                resultUtil = ResultUtil.error(map.get("msg"), "");
//            }
//        }
//        if(payType == 2){//支付宝支付
//            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 10, 5, uid.toString(), "小件物流补差价", orderMoney, callbackPath + "/base/aliPayOrderLogisticsSpread", "", type, null);
//            if(map.get("code").equals("200")){
//                paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 2, orderMoney, map.get("order_id"), 1);//添加预支付数据
//                resultUtil = ResultUtil.success(map.get("data"));
//            }else{
//                resultUtil = ResultUtil.error(map.get("msg"), "");
//            }
//        }
        if(payType == 3){//余额支付
            if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){
                return ResultUtil.error("余额不足,无法完成支付");
            }
 
            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
 
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
 
            //添加交易明细
            transactionDetailsService.saveData(uid, "小件物流补差价", orderMoney, 2, 1, 1, 4, orderId);
            userInfoService.updateById(userInfo);
 
            orderLogistics.setState(12);//已支付差价
            this.updateById(orderLogistics);
 
            orderLogistics.setOrderMoney(orderLogistics.getOrderMoney() + orderMoney);
            orderLogistics.setTravelMoney(orderLogistics.getTravelMoney() + orderMoney);
            orderLogistics.setPayMoney(orderLogistics.getPayMoney() + orderMoney);
 
            orderLogisticsSpread.setPayMoney(orderMoney);
            orderLogisticsSpread.setPayTime(new Date());
            orderLogisticsSpread.setPayType(3);
            orderLogisticsSpreadService.updateById(orderLogisticsSpread);
 
            //添加已收入明细
            Company company = companyService.selectById(orderLogistics.getCompanyId());
            Double speMoney =  orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney();
            BigDecimal d = null;
            BigDecimal c = null;
            if(company.getIsSpeFixedOrProportional() == 2){//固定
                d = new BigDecimal(speMoney);
                c = new BigDecimal(orderMoney).subtract(d);
            }
            if(company.getIsSpeFixedOrProportional() == 1){//比例
                d = new BigDecimal(orderMoney).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                c = new BigDecimal(orderMoney).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
 
            Income income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 1).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
            income.setMoney(income.getMoney() + d.doubleValue());
            incomeService.updateById(income);
            income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", orderLogistics.getDriverId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
            income.setMoney(income.getMoney() + c.doubleValue());
            incomeService.updateById(income);
            Driver driver = driverService.selectById(orderLogistics.getDriverId());
            driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            driverService.updateById(driver);
 
            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
                }
            }).start();
 
            systemNoticeService.addSystemNotice(1, "您已使用余额成功完成小件物流订单差价支付,谢谢使用!", uid, 1);
        }
 
        this.updateById(orderLogistics);
        return resultUtil;
    }
 
 
 
    @Override
    public void payOrderLogisticsCallback(Integer id, String order_id, Integer type) throws Exception {
        OrderLogistics orderLogistics = this.selectById(id);
        PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, Integer.valueOf(id), orderLogistics.getType(), type, 1);
        if(null != query){
            //添加交易明细
            transactionDetailsService.saveData(orderLogistics.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, orderLogistics.getType(), query.getOrderId());
            orderLogistics.setState(1);//先支付后抢单
            orderLogistics.setPayType(type);
            orderLogistics.setPayMoney(query.getAmount());
            this.updateById(orderLogistics);
 
            UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId());
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
            userInfoService.updateById(userInfo);
 
            query.setState(2);
            query.setCode(order_id);
            paymentRecordService.updateById(query);
 
            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
                }
            }).start();
 
 
            systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功完成小件物流订单支付,谢谢使用!", orderLogistics.getUserId(), 1);
 
            this.pushOrder(orderLogistics);//推单
        }else{
            System.err.println("预支付数据异常(orderId = "  + id + ")");
        }
    }
 
 
 
    @Override
    public void payOrderLogisticsSpreadCallback(Integer id, String order_id, Integer type) throws Exception {
        OrderLogistics orderLogistics = this.selectById(id);
        OrderLogisticsSpread orderLogisticsSpread = orderLogisticsSpreadService.selectOne(new EntityWrapper<OrderLogisticsSpread>().eq("orderLogisticsId", id));
        PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, Integer.valueOf(id), orderLogistics.getType(), type, 1);
        if(null != query){
            //添加交易明细
            transactionDetailsService.saveData(orderLogistics.getUserId(), "小件物流补差价", query.getAmount(), 2, 1, 1, 4, query.getOrderId());
            orderLogistics.setState(4);//待取货
 
            orderLogistics.setOrderMoney(orderLogistics.getOrderMoney() + query.getAmount());
            orderLogistics.setTravelMoney(orderLogistics.getTravelMoney() + query.getAmount());
            orderLogistics.setPayMoney(orderLogistics.getPayMoney() + query.getAmount());
 
            orderLogisticsSpread.setPayMoney(query.getAmount());
            orderLogisticsSpread.setPayTime(new Date());
            orderLogisticsSpread.setPayType(3);
            orderLogisticsSpreadService.updateById(orderLogisticsSpread);
 
            UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId());
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
            userInfoService.updateById(userInfo);
 
            query.setState(2);
            query.setCode(order_id);
            paymentRecordService.updateById(query);
 
            //添加已收入明细
            Company company = companyService.selectById(orderLogistics.getCompanyId());
            Double speMoney =  orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney();
            BigDecimal d = null;
            BigDecimal c = null;
            if(company.getIsSpeFixedOrProportional() == 2){//固定
                d = new BigDecimal(speMoney);
                c = new BigDecimal(query.getAmount()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
            if(company.getIsSpeFixedOrProportional() == 1){//比例
                d = new BigDecimal(query.getAmount()).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                c = new BigDecimal(query.getAmount()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
            Income income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 1).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
            income.setMoney(income.getMoney() + d.doubleValue());
            incomeService.updateById(income);
            income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", orderLogistics.getDriverId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
            income.setMoney(income.getMoney() + c.doubleValue());
            incomeService.updateById(income);
            Driver driver = driverService.selectById(orderLogistics.getDriverId());
            driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            driverService.updateById(driver);
 
            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
                }
            }).start();
 
 
            systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功完成小件物流订单差价支付,谢谢使用!", orderLogistics.getUserId(), 1);
            this.updateById(orderLogistics);
        }else{
            System.err.println("预支付数据异常(orderId = "  + id + ")");
        }
    }
 
 
 
 
 
    /**
     * 获取首页订单数量
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public int queryLogisticsNumber(Integer uid) throws Exception {
        return orderLogisticsMapper.queryLogisticsNumber(uid);
    }
 
 
    /**
     * 获取个人中心订单列表
     * @param uid
     * @param pageNum
     * @param size
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryMyOrderList(Integer uid, Integer pageNum, Integer size) throws Exception {
        pageNum = (pageNum - 1) * size;
        List<Map<String, Object>> maps = orderLogisticsMapper.queryMyOrderList(uid, pageNum, size);
        return maps;
    }
 
 
    /**
     * 获取历史消费记录
     * @param uid
     * @return
     */
    @Override
    public List<Map<String, Object>> queryMyTravelRecord(Integer uid) {
        return orderLogisticsMapper.queryMyTravelRecord(uid);
    }
 
 
    @Override
    public List<Map<String, Object>> queryInvoiceOrder(Integer type, Date startTime, Date endTime, Double startMoney, Double endMoney, Integer uid, Integer orderType) throws Exception {
        startTime = dateUtil.getStartOrEndDate(startTime, "start");
        endTime = dateUtil.getStartOrEndDate(endTime, "end");
        return orderLogisticsMapper.queryInvoiceOrder(type, startTime, endTime, startMoney, endMoney, uid, orderType);
    }
 
 
 
    @Override
    public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid) throws Exception {
        if(ToolUtil.isNotEmpty(remark)){
            if(ToolUtil.isNotEmpty(remark)){
                List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
                for(SensitiveWords s : sensitiveWords){
                    remark = remark.replaceAll(s.getContent(), "***");
                }
            }
        }
 
        OrderLogistics orderLogistics = this.selectById(id);
        Integer integer = null;
        if(null == orderLogistics){
            return ResultUtil.error("取消订单失败,订单信息有误");
        }
        if(orderLogistics.getState() > 5 && orderLogistics.getState() != 7 && orderLogistics.getState() != 8  && orderLogistics.getState() != 11){
            return ResultUtil.error("取消订单失败,不合法的操作");
        }
 
        if(orderLogistics.getState() == 7){
            integer = orderCancelService.saveData(orderLogistics.getId(), orderLogistics.getType(), reason, remark, null, null, 2, 1, orderLogistics.getUserId());
            orderLogistics.setState(10);
            this.updateById(orderLogistics);
            //添加消息
            systemNoticeService.addSystemNotice(1, "您已成功取消小件物流订单,谢谢使用!", orderLogistics.getUserId(), 1);
            Map<String, Object> map = new HashMap<>();
            map.put("id", integer);
            return ResultUtil.success(map);
        }
 
 
        //回退支付金额
        if(null != orderLogistics.getPayType() && null != orderLogistics.getPayMoney()) {//已支付
            if(orderLogistics.getPayType() == 3){//余额支付
                UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId());
                userInfo.setBalance(userInfo.getBalance() + orderLogistics.getPayMoney());
                userInfoService.updateById(userInfo);
            }else{
                //调用回退接口
                PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getPayType(), 2);
                boolean b = false;
 
                if(query.getPayType() == 1){//微信
                    Map<String, String> map = payMoneyUtil.wxRefund(query.getCode(), orderLogistics.getId() + "_" + orderLogistics.getType(), query.getAmount().toString(), query.getAmount().toString(), "/base/cancleOrderWXPay");
                    if(!"SUCCESS".equals(map.get("return_code"))){
                        return ResultUtil.error(map.get("return_msg"));
                    }
                }else{//支付宝
                    Map<String, String> map = payMoneyUtil.aliRefund(query.getCode(), query.getAmount().toString());
                    if(!"10000".equals(map.get("code"))){
                        return ResultUtil.error(map.get("msg"));
                    }
                }
 
 
//                //调用回退接口
//                PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getPayType(), 2);
//                boolean b = false;
//                Map<String, Object> merrefund = icbcPayUtil.merrefund(query.getCode(), "", query.getAmount(), orderLogistics.getId() + "_" + orderLogistics.getType(), orderLogistics.getOrderNum());
//                if (Integer.valueOf(merrefund.get("code").toString()) == 0) {
//                    Map<String, Object> refundqry = icbcPayUtil.refundqry("", query.getCode(), orderLogistics.getOrderNum());
//                    if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 0) {//成功
//                        b = true;
//                    }
//                    if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 1) {//失败
//                        return ResultUtil.error("订单取消失败(退款不成功)");
//                    }
//                    if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 2) {//未知
//                        return ResultUtil.error("退款返回未知异常");
//
//                    }
//                }
                if(b){
 
                }
            }
            //添加交易明细
            transactionDetailsService.saveData(orderLogistics.getUserId(), "小件物流取消退款", orderLogistics.getPayMoney(), 1, 1, 1, 4, orderLogistics.getId());
 
            integer = orderCancelService.saveData(orderLogistics.getId(), orderLogistics.getType(), reason, remark, null, null, 2, 1, orderLogistics.getUserId());
            orderLogistics.setState(10);
            this.updateById(orderLogistics);
 
            //添加负的收入明细
            List<Income> incomes = incomeService.selectList(new EntityWrapper<Income>().eq("type", 2).eq("incomeId", id).eq("orderType", orderLogistics.getType()));
            for(Income income : incomes){
                if(income.getUserType() == 2){//处理司机的收入
                    Driver driver = driverService.selectById(income.getObjectId());
                    driver.setBalance(driver.getBalance() - income.getMoney());
                    driver.setBusinessMoney(driver.getBusinessMoney() - income.getMoney());
                    driver.setLaveBusinessMoney(driver.getLaveBusinessMoney() - income.getMoney());
                    driverService.updateById(driver);
                }
                Income income1 = new Income();
                BeanUtils.copyProperties(income, income1);
                income1.setMoney(income.getMoney() * -1);
                income1.setId(null);
                income1.setInsertTime(new Date());
                incomeService.insert(income1);
            }
 
        }
 
        if(null != orderLogistics.getDriverId()){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
                }
            }).start();
        }
 
        //添加消息
        systemNoticeService.addSystemNotice(1, "您已成功取消小件物流订单,谢谢使用!", orderLogistics.getUserId(), 1);
        Map<String, Object> map = new HashMap<>();
        map.put("id", integer);
        return ResultUtil.success(map);
    }
 
 
    /**
     * 获取行政区域数据
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryRegion() throws Exception {
        Map<String, Object> map = new HashMap<>();
        List<Region> querys = regionMapper.querys(0);
        Map<Integer, String> map1 = new HashMap<>();
        Map<Integer, String> map2 = new HashMap<>();
        Map<Integer, String> map3 = new HashMap<>();
        for(Region region : querys){
            map1.put(Integer.valueOf(region.getCode()), region.getName());
 
            List<Region> querys1 = regionMapper.querys(region.getId());
            for(Region region1 : querys1){
                map2.put(Integer.valueOf(region1.getCode()), region1.getName());
 
                List<Region> querys2 = regionMapper.querys(region1.getId());
                for(Region region2 : querys2) {
                    map3.put(Integer.valueOf(region2.getCode()), region2.getName());
                }
            }
        }
        map.put("province_list", map1);
        map.put("city_list", map2);
        map.put("county_list", map3);
        return map;
    }
 
 
    /**
     * 获取行政区域
     * @param parentId
     * @return
     * @throws Exception
     */
    @Override
    public List<Region> queryRegions(Integer parentId) throws Exception {
        return regionMapper.querys(parentId);
    }
 
    @Override
    public Map<String, Object> queryBalance(Integer orderId, Integer uid) throws Exception {
        Map<String, Object> map = new HashMap<>();
        UserInfo userInfo = userInfoService.selectById(uid);
        map.put("balance", userInfo.getBalance());
        map.put("coupon", 0);
        return map;
    }
 
 
 
    public synchronized String getOrderNum() throws Exception{
        int size = this.selectCount(null);
        return "LOGISTICS" + String.valueOf(1000000 + size + 1).substring(1);
    }
}