xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
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.DateUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.account.model.TEnterpriseWithdrawal;
import com.stylefeng.guns.modular.account.service.ITEnterpriseWithdrawalService;
import com.stylefeng.guns.modular.account.service.UserWithdrawalService;
import com.stylefeng.guns.modular.account.util.Base64Util;
import com.stylefeng.guns.modular.cloudPayment.example.AllocationExample;
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
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.UserInfoMapper;
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.MerchantCouponListWarpper;
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.resp.AllocationResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
 
 
@Service
public class OrderLogisticsServiceImpl extends ServiceImpl<OrderLogisticsMapper, OrderLogistics> implements IOrderLogisticsService {
 
    @Resource
    private OrderLogisticsMapper orderLogisticsMapper;
 
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private GDFalconUtil gdFalconUtil;
 
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
 
    @Resource
    private RegionMapper regionMapper;
 
    @Autowired
    private ChinaMobileUtil chinaMobileUtil;
 
    @Autowired
    private PushUtil pushUtil;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
    @Autowired
    private IOrderLogisticsSpreadService orderLogisticsSpreadService;
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Autowired
    private ICompanyService companyService;
 
    @Autowired
    private IIncomeService incomeService;
 
    @Autowired
    private ALiSendSms aLiSendSms;
 
    @Resource
    private UserInfoMapper userInfoMapper;
 
    @Autowired
    private IMerchantActivityService merchantActivityService;
 
    @Autowired
    private IMerchantActivitySlaveService merchantActivitySlaveService;
 
    @Autowired
    private IUserMerchantCouponService userMerchantCouponService;
 
    @Autowired
    private IMerchantCouponService merchantCouponService;
 
    @Autowired
    private IAgreementService agreementService;
    @Autowired
    private ITEnterpriseWithdrawalService enterpriseWithdrawalService;
    @Autowired
    private UserWithdrawalService userWithdrawalService;
 
 
 
 
 
 
    /**
     * 获取司机抢单界面详情
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryPushOrder(Integer orderId) throws Exception {
        return orderLogisticsMapper.queryPushOrder(orderId);
    }
 
 
    /**
     * 司机抢单操作
     * @param orderId
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public synchronized ResultUtil grabOrder(Integer orderId, Integer uid) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(orderLogistics.getState() == 10){
            return ResultUtil.error("订单已取消");
        }
        if(orderLogistics.getState() != 1){
            return ResultUtil.error("手速有点慢哦,订单已被抢啦!");
        }
        Driver driver = driverService.selectById(uid);
        orderLogistics.setDriverId(uid);
        orderLogistics.setCarId(driver.getCarId());
        orderLogistics.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
                driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
        orderLogistics.setState(2);
        orderLogistics.setSnatchOrderTime(new Date());
 
        //调用高德创建轨迹
        String s = gdFalconUtil.selectTerminal(driver.getPhone());
        String track = gdFalconUtil.createTrack(s);
        orderLogistics.setTrackId(track);
 
        //调用移动的小号接口
        Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderLogistics.getRecipientPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000));
        if(String.valueOf(map.get("code")).equals("200")){
            orderLogistics.setTelX(map.get("telX"));
            orderLogistics.setBindId(map.get("bindId"));
        }
        UserInfo userInfo = userInfoMapper.selectById(orderLogistics.getUserId());
 
        Map<String, String> map1 = chinaMobileUtil.midAxbBindSend(userInfo.getPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000));
        System.out.println("二次绑定信息:"+map1);
        if(String.valueOf(map1.get("code")).equals("200")){
            orderLogistics.setTelXOne(map1.get("telX"));
            orderLogistics.setBindIdOne(map1.get("bindId"));
        }
 
        this.updateById(orderLogistics);
 
        //添加已收入明细
//        Company company = companyService.selectById(driver.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(orderLogistics.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机
//        }
//        if(company.getIsSpeFixedOrProportional() == 1){//比例
//            Double price = orderLogistics.getTravelMoney();
//            d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100)), new MathContext(2, RoundingMode.HALF_EVEN));
//            c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
//        }
//        incomeService.saveData(1, orderLogistics.getCompanyId(), 2, orderLogistics.getId(), orderLogistics.getType(), d.doubleValue());
//        incomeService.saveData(2, orderLogistics.getDriverId(), 2, orderLogistics.getId(), orderLogistics.getType(), c.doubleValue());
//        /*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);*/
 
 
 
 
        //推送相关代码------------------start----------------
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
            }
        }).start();
 
        // TODO: 2023/11/4 小件物流无服务中页面
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                pushUtil.pushDriverPosition(orderId, orderLogistics.getType());
//            }
//        }).start();
 
 
        systemNoticeService.addSystemNotice(2, "您已成功抢得小件物流订单,请及时联系客户!", orderLogistics.getDriverId(), 1);
        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderLogistics.getUserId(), 1);
 
 
        if (this.selectList(new EntityWrapper<OrderLogistics>().eq("driverId",uid)).size() == 1){
            return ResultUtil.success(agreementService.selectOne(new EntityWrapper<Agreement>().eq("type",17)));
        }
        return ResultUtil.success(String.valueOf(orderLogistics.getId()));
    }
 
 
    /**
     * 获取订单详情页(服务中的页面)
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryOrderInfo(Integer orderId) throws Exception {
        return orderLogisticsMapper.queryOrderInfo(orderId);
    }
 
 
    /**
     * 走订单流程
     * @param orderId
     * @param state
     * @param lon
     * @param lat
     * @param address
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address, String driverImg) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        UserInfo userInfo = userInfoMapper.selectById(orderLogistics.getUserId());
        switch (state){
            case 3://出发前往预约点
                orderLogistics.setState(3);
                orderLogistics.setSetOutTime(new Date());
                systemNoticeService.addSystemNotice(1, "司机已出发,请耐心等待", orderLogistics.getUserId(), 1);
                break;
            case 4://到达预约点,等待客户上车
                orderLogistics.setState(4);
                orderLogistics.setArriveTime(new Date());
                systemNoticeService.addSystemNotice(1, "司机已到达您设置的预约地点。", orderLogistics.getUserId(), 1);
                break;
            case 5://开始服务
                orderLogistics.setBoardingLon(lon);
                orderLogistics.setBoardingLat(lat);
                orderLogistics.setBoardingAddress(address);
                orderLogistics.setBoardingTime(new Date());
                orderLogistics.setState(5);
                orderLogistics.setStartServiceTime(new Date());
 
//                pushUtil.pushDriverPosition(orderLogistics.getId(), orderLogistics.getType());//主动推送司机定位
                break;
            case 6://结束服务(专车可以返回继续服务)不修改状态
                if(orderLogistics.getState()!=6){
                    orderLogistics.setGetoffLon(lon);
                    orderLogistics.setGetoffLat(lat);
                    orderLogistics.setGetoffAddress(address);
                    orderLogistics.setGetoffTime(new Date());
                    orderLogistics.setEndServiceTime(new Date());
                    orderLogistics.setState(6);
                    orderLogistics.setDriverImg(driverImg);
 
                    //添加抽成及收入记录
                    Map<String, Object> map = incomeService.saveIncome(orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getOrderMoney());
                    orderLogistics.setSplitAllocation(JSON.toJSONString(map));
 
                    //记录添加用户商家优惠券
                    //订单数要加1,因为这里是后修改订单状态
                    List<OrderLogistics> list = this.selectList(new EntityWrapper<OrderLogistics>().eq("userId", userInfo.getId()).eq("type", orderLogistics.getType()).eq("state", 9).eq("isDelete", 1));
                    List<MerchantActivity> merchantActivities = merchantActivityService.selectList(new EntityWrapper<MerchantActivity>().eq("companyId", orderLogistics.getCompanyId()).eq("activityType", 1).eq("auditStatus", 2).eq("status", 1)
                            .eq("state", 1).like("orderType", "%" + orderLogistics.getType() + "%").where("((orderAmountFull is not null and orderAmountFull <= " + orderLogistics.getOrderMoney() + ") or (orderNumber is not null and orderNumber <= " + (list.size() + 1) + "))")
                            .in("id", merchantActivitySlaveService.selectList(new EntityWrapper<MerchantActivitySlave>().gt("laveNumber", 0)).stream().map(MerchantActivitySlave::getMerchantActivityId).collect(Collectors.toList()))
                            .notIn("id", userMerchantCouponService.selectList(new EntityWrapper<UserMerchantCoupon>().eq("userType", 1).eq("userId", userInfo.getId()).eq("state", 1)).stream().map(UserMerchantCoupon::getMerchantActivityId).collect(Collectors.toList()))
                    );
                    List<MerchantCouponListWarpper> listWarppers = new ArrayList<>();
                    if(merchantActivities.size() > 0){
                        for(MerchantActivity merchantActivity :merchantActivities){
                            List<MerchantActivitySlave> merchantActivitySlaves = merchantActivitySlaveService.selectList(new EntityWrapper<MerchantActivitySlave>().eq("merchantActivityId", merchantActivity.getId()).gt("laveNumber", 0));
 
                            for(MerchantActivitySlave merchantActivitySlave : merchantActivitySlaves){
                                UserMerchantCoupon userMerchantCoupon = new  UserMerchantCoupon();
                                try {
                                    userMerchantCoupon.setCode(UUIDUtil.getRandomCode(16));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                userMerchantCoupon.setUserType(1);
                                userMerchantCoupon.setUserId(userInfo.getId());
                                userMerchantCoupon.setMerchantActivityId(merchantActivity.getId());
                                userMerchantCoupon.setMerchantCouponId(merchantActivitySlave.getMerchantCouponId());
                                Calendar calendar = Calendar.getInstance();
                                calendar.setTime(new Date());
                                calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + merchantActivity.getEffectiveDays());
                                userMerchantCoupon.setEndTime(calendar.getTime());
                                userMerchantCoupon.setStatus(1);
                                userMerchantCoupon.setState(1);
                                userMerchantCoupon.setCreateTime(new Date());
                                userMerchantCouponService.insert(userMerchantCoupon);
 
                                MerchantCoupon merchantCoupon = merchantCouponService.selectById(merchantActivitySlave.getMerchantCouponId());
                                MerchantCouponListWarpper merchantCouponListWarpper = new MerchantCouponListWarpper();
                                merchantCouponListWarpper.setId(merchantActivitySlave.getMerchantCouponId());
                                merchantCouponListWarpper.setName(merchantCoupon.getName());
                                merchantCouponListWarpper.setType(merchantCoupon.getType());
                                merchantCouponListWarpper.setFullAmount(merchantCoupon.getFullAmount());
                                merchantCouponListWarpper.setDiscount(merchantCoupon.getDiscount());
                                listWarppers.add(merchantCouponListWarpper);
 
                                merchantActivitySlave.setLaveNumber(merchantActivitySlave.getLaveNumber() - 1);
                                if(merchantActivitySlave.getLaveNumber() == 0){
                                    merchantActivity.setStatus(2);
                                }
                            }
                            if(merchantActivitySlaves.size() > 0){
                                merchantActivitySlaveService.updateBatchById(merchantActivitySlaves);
                            }
                        }
                        merchantActivityService.updateBatchById(merchantActivities);
                    }
                    String value = redisUtil.getValue("merchantVoucher");
                    JSONObject jsonObject = JSON.parseObject(value);
                    if(null == jsonObject){
                        jsonObject = new JSONObject();
                    }
                    jsonObject.put(userInfo.getPhone(), listWarppers);
                    redisUtil.setStrValue("merchantVoucher", jsonObject.toJSONString());
                }
 
                break;
        }
        this.updateById(orderLogistics);
 
        // TODO: 2020/6/5 推送状态
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
            }
        }).start();
        return ResultUtil.success();
    }
 
 
    @Autowired
    private ISysWithdrawalPoundageService sysWithdrawalPoundageService;
 
    @Autowired
    private ISysTimeoutMoneyService sysTimeoutMoneyService;
 
    /**
     * 验证取件码(小件物流)
     * @param orderId
     * @param pickUpCode
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil fillInPickUpCode(Integer orderId, String pickUpCode) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(!orderLogistics.getPickUpCode().equals(pickUpCode)){
            return ResultUtil.error("验证失败");
        }
        orderLogistics.setState(9);
        orderLogistics.setEndServiceTime(DateUtil.parseTime(DateUtil.getTime()));
 
        ///   超时,扣款订单的%费用
        SysTimeoutMoney sysTimeoutMoney = sysTimeoutMoneyService.selectOne(null);
        if(orderLogistics.getArriveTimeExpect()!=null){
            if (new Date().getTime() > (orderLogistics.getArriveTimeExpect().getTime() + sysTimeoutMoney.getTimeOut())){
                double timeOutMoney = sysTimeoutMoney.getDeductMoney()*orderLogistics.getOrderMoney()/100;
                orderLogistics.setTimeOutMoney(timeOutMoney);
 
                ///   超时扣款扣除司机余额和剩余业务金额
                Driver driver = driverService.selectById(orderLogistics.getDriverId());
                driver.setLaveBusinessMoney(driver.getLaveBusinessMoney() - timeOutMoney);
                driver.setBalance(driver.getBalance() - timeOutMoney);
                driverService.updateById(driver);
 
 
                ///  存入平台收入
                Income income = new Income();
                income.setIncomeId(orderId);
                income.setOrderType(orderLogistics.getType());
                income.setInsertTime(new Date());
                income.setMoney(timeOutMoney);
                income.setUserType(1);
                income.setType(7);
                income.setObjectId(orderLogistics.getCompanyId());
                incomeService.insert(income);
 
                // TODO 司机云闪付 超时扣款 司机电子余额转账到平台
                // 超时扣款 司机电子余额转账到平台
                divideAccounts(orderLogistics.getDriverId(),timeOutMoney,orderLogistics.getOrderNum());
            }
        }
 
        this.updateById(orderLogistics);
 
        return ResultUtil.success();
    }
 
    /**
     * 分账
     */
    private void divideAccounts(Integer driverId,double amount,String orderNum){
        try{
 
            // 查询平台开户信息
            TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
                    .eq("companyId", 1)
                    .last("LIMIT 1"));
            if(Objects.isNull(enterpriseWithdrawal)){
                throw new RuntimeException("平台开户信息为空");
            }
            // 司机开户信息
            Driver driver = driverService.selectById(driverId);
            if(Objects.isNull(driver)){
                throw new RuntimeException("司机信息不存在");
            }
            // TODO 司机进件信息
            UserWithdrawal driverWith = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
                    .eq("phone", driver.getPhone())
                    .last("LIMIT 1"));
            if(Objects.isNull(driverWith)){
                throw new RuntimeException("司机开户信息为空");
            }
 
            AllocationReq allocationReq = new AllocationReq();
            allocationReq.setOutOrderNo(orderNum);
            allocationReq.setPayBalanceAcctId(driverWith.getBalanceAcctId()); // 发送方
            allocationReq.setRecvBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId()); // 接收方
            BigDecimal multiply = new BigDecimal(100).multiply(BigDecimal.valueOf(amount));
            allocationReq.setAmount(multiply.intValue()); // 金额
            allocationReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode())); // 密码
            allocationReq.setOrderNo(orderNum);
            allocationReq.setOrderAmount((long) multiply.intValue());
            allocationReq.setProductName("小件物流超时扣款");
            allocationReq.setProductCount(1);
            AllocationResp allocationResp = AllocationExample.create(allocationReq);
            System.err.println("小件物流超时扣款:"+allocationResp);
        }catch (UpyztException e){
            e.printStackTrace();
        }
    }
 
 
    /**
     * 司机设置补差价金额
     * @param orderId
     * @param difference
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil makeUpTheDifference(Integer orderId, Double difference) throws Exception {
        OrderLogisticsSpread query = orderLogisticsSpreadService.query(orderId);
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(orderLogistics.getState() != 4 && orderLogistics.getState() != 8){
            return ResultUtil.error("不允许设置差价");
        }
        if(query != null){
            query.setPrice(difference);
            orderLogisticsSpreadService.updateById(query);
            return ResultUtil.success();
        }
        OrderLogisticsSpread orderLogisticsSpread = new OrderLogisticsSpread();
        orderLogisticsSpread.setOrderLogisticsId(orderId);
        orderLogisticsSpread.setPrice(difference);
        orderLogisticsSpreadService.insert(orderLogisticsSpread);
        orderLogistics.setState(8);
        this.updateById(orderLogistics);
 
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushPayDifference(1, orderLogistics.getUserId(), orderId, orderLogistics.getType(), difference);
            }
        }).start();
        return ResultUtil.success();
    }
 
    @Override
    public List<Map<String, Object>> queryOrderList(Integer driverId) throws Exception {
        return orderLogisticsMapper.queryOrderList(driverId);
    }
 
    /**
     * 获取我的订单列表
     * @param state     1=全部,2=待支付,3=已取消
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryMyAllOrder(Integer state, Integer uid) throws Exception {
        return orderLogisticsMapper.queryMyAllOrder(state, uid);
    }
 
 
    /**
     * 抢单操作(车载端)
     * @param orderId
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public synchronized ResultUtil grabOrder_(Integer orderId, Integer uid) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(orderLogistics.getState() == 10){
            return ResultUtil.error("订单已取消");
        }
        if(orderLogistics.getState() != 1){
            return ResultUtil.error("手速有点慢哦,订单已被抢啦!");
        }
        Driver driver = driverService.selectById(uid);
        orderLogistics.setDriverId(uid);
        orderLogistics.setCarId(driver.getCarId());
        orderLogistics.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
                driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
        orderLogistics.setState(2);
        Date date = new Date();
        orderLogistics.setSnatchOrderTime(date);
        orderLogistics.setSetOutTime(date);
        orderLogistics.setArriveTime(date);
        orderLogistics.setStartServiceTime(date);
        orderLogistics.setBoardingTime(date);
 
        String value = redisUtil.getValue("DRIVER" + uid);
        if(ToolUtil.isNotEmpty(value)){
            String[] split = value.split(",");
            Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(split[0], split[1]);
            orderLogistics.setBoardingAddress(geocode1.get("address"));
            orderLogistics.setBoardingLon(Double.valueOf(split[0]));
            orderLogistics.setBoardingLat(Double.valueOf(split[1]));
        }
 
        //调用高德创建轨迹
        String s = gdFalconUtil.selectTerminal(driver.getPhone());
        String track = gdFalconUtil.createTrack(s);
        orderLogistics.setTrackId(track);
 
        //调用移动的小号接口 TODO 车载端使用真实号码
//        Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
//        Region region = regionMapper.query(geocode.get("districtCode"));
//        Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1)));
////        if(String.valueOf(map.get("code")).equals("200")){
////            orderTaxi.setTelX(map.get("telX"));
////            orderTaxi.setBindId(map.get("bindId"));
////        }
 
        this.updateById(orderLogistics);
 
        //推送相关代码------------------start----------------
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
            }
        }).start();
 
        // TODO: 2023/11/4 小件物流无服务中页面
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                pushUtil.pushDriverPosition(orderId, orderLogistics.getType());
//            }
//        }).start();
 
        systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderLogistics.getDriverId(), 1);
        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderLogistics.getUserId(), 1);
 
        return ResultUtil.success();
    }
 
    @Override
    public List<OrderLogistics> query(Integer driverId, Integer... state) throws Exception {
        return orderLogisticsMapper.query(Arrays.asList(state), driverId);
    }
 
    @Override
    public void sendVerificationCode(Integer orderId) throws Exception {
//        OrderLogistics orderLogistics = this.selectById(orderId);
//        String random = "";
//        for(int i = 0; i < 6; i++){
//            random += Double.valueOf(Math.random() * 10).intValue();
//        }
//        orderLogistics.setPickUpCode(random);
//        this.updateById(orderLogistics);
        //发送短信
//        aLiSendSms.sendSms(orderLogistics.getRecipientPhone(), "SMS_229715276", "{\"code\":\"" + random + "\"}");
    }
 
    @Override
    public List<OrderLogistics> queryMaturity() throws Exception {
        return orderLogisticsMapper.queryMaturity();
    }
 
    @Override
    public List<OrderLogistics> taskMidAxbUnBindSend() throws Exception {
        return this.baseMapper.taskMidAxbUnBindSend();
    }
}