From e52227b01983146f2e3c81dc575141d8b9889497 Mon Sep 17 00:00:00 2001
From: yanghb <yanghb>
Date: 星期五, 21 四月 2023 10:16:30 +0800
Subject: [PATCH] 代码调整

---
 DriverTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java |  250 ++++++++++++--------------------------------------
 1 files changed, 60 insertions(+), 190 deletions(-)

diff --git a/DriverTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java b/DriverTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
index e9b0ae7..e268828 100644
--- a/DriverTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
+++ b/DriverTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -1,10 +1,7 @@
 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.smallLogistics.dao.OrderLogisticsMapper;
 import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
@@ -12,18 +9,22 @@
 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.model.Company;
+import com.stylefeng.guns.modular.system.model.Driver;
+import com.stylefeng.guns.modular.system.model.Income;
+import com.stylefeng.guns.modular.system.model.Region;
+import com.stylefeng.guns.modular.system.service.ICompanyService;
+import com.stylefeng.guns.modular.system.service.IDriverService;
+import com.stylefeng.guns.modular.system.service.IIncomeService;
+import com.stylefeng.guns.modular.system.service.ISystemNoticeService;
 import com.stylefeng.guns.modular.system.util.*;
-import com.stylefeng.guns.modular.system.warpper.MerchantCouponListWarpper;
+import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.*;
-import java.util.stream.Collectors;
 
 
 @Service
@@ -67,24 +68,6 @@
 
     @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;
 
 
 
@@ -133,7 +116,9 @@
         orderLogistics.setTrackId(track);
 
         //调用移动的小号接口
-        Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderLogistics.getRecipientPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000));
+        Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString());
+        Region region = regionMapper.query(geocode.get("districtCode"));
+        Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderLogistics.getRecipientPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1)));
         if(String.valueOf(map.get("code")).equals("200")){
             orderLogistics.setTelX(map.get("telX"));
             orderLogistics.setBindId(map.get("bindId"));
@@ -157,10 +142,10 @@
         }
         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.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);*/
+        driverService.updateById(driver);
 
 
 
@@ -180,13 +165,9 @@
             }
         }).start();
 
-        systemNoticeService.addSystemNotice(2, "您已成功抢得小件物流订单,请及时联系客户!", orderLogistics.getDriverId(), 1);
-        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderLogistics.getUserId(), 1);
+        systemNoticeService.addSystemNotice(2, "您已成功抢得小件物流订单,请及时联系客户!", orderLogistics.getDriverId());
+        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderLogistics.getUserId());
 
-
-        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();
     }
 
@@ -214,19 +195,18 @@
      * @throws Exception
      */
     @Override
-    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address, String driverImg) throws Exception {
+    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address) 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);
+                systemNoticeService.addSystemNotice(1, "司机已出发,请耐心等待", orderLogistics.getUserId());
                 break;
             case 4://到达预约点,等待客户上车
                 orderLogistics.setState(4);
                 orderLogistics.setArriveTime(new Date());
-                systemNoticeService.addSystemNotice(1, "司机已到达您设置的预约地点。", orderLogistics.getUserId(), 1);
+                systemNoticeService.addSystemNotice(1, "司机已到达您设置的预约地点。", orderLogistics.getUserId());
                 break;
             case 5://开始服务
                 orderLogistics.setBoardingLon(lon);
@@ -239,108 +219,39 @@
                 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);
+                orderLogistics.setGetoffLon(lon);
+                orderLogistics.setGetoffLat(lat);
+                orderLogistics.setGetoffAddress(address);
+                orderLogistics.setGetoffTime(new Date());
+                orderLogistics.setEndServiceTime(new Date());
+                orderLogistics.setState(6);
 
-                    //添加已收入明细
-                    // TODO: 2022/3/19  抽成按照订单金额计算,优先保证司机的收入,用户支付金额不够,则在平台收入中补贴司机收入
-                    //例如:订单金额10元,优惠3元,司机收入比例80%,平台收入比例20%。
-                    //司机收入:10 * 0.8 = 8
-                    //平台收入:7 - 8 = -1
-                    Company company = companyService.selectById(orderLogistics.getCompanyId());
-                    Double speMoney =  orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney();
-                    Double orderMoney = orderLogistics.getOrderMoney();
-                    BigDecimal d = null;
-                    BigDecimal c = null;
-                    if(company.getIsSpeFixedOrProportional() == 2){//固定
-                        d = new BigDecimal(speMoney.compareTo(orderMoney) > 0 ? orderMoney : speMoney);
-                        c = new BigDecimal(orderMoney).subtract(d);
-                    }
-                    if(company.getIsSpeFixedOrProportional() == 1){//比例
-                        c = new BigDecimal(orderMoney).multiply(new BigDecimal(1 - (speMoney / 100))).setScale(2, BigDecimal.ROUND_HALF_EVEN);
-                        d = new BigDecimal(orderLogistics.getPayMoney()).subtract(c).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(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(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);
-
-
-                    //记录添加用户商家优惠券
-                    //订单数要加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());
+                Double orderMoney = orderLogistics.getOrderMoney();
+                //添加已收入明细
+                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))).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);
 
                 break;
         }
@@ -358,12 +269,6 @@
     }
 
 
-    @Autowired
-    private ISysWithdrawalPoundageService sysWithdrawalPoundageService;
-
-    @Autowired
-    private ISysTimeoutMoneyService sysTimeoutMoneyService;
-
     /**
      * 验证取件码(小件物流)
      * @param orderId
@@ -378,37 +283,7 @@
             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);
-            }
-        }
-
         this.updateById(orderLogistics);
-
         return ResultUtil.success();
     }
 
@@ -536,8 +411,8 @@
             }
         }).start();
 
-        systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderLogistics.getDriverId(), 1);
-        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderLogistics.getUserId(), 1);
+        systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderLogistics.getDriverId());
+        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderLogistics.getUserId());
 
         return ResultUtil.success();
     }
@@ -549,24 +424,19 @@
 
     @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);
+        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 + "\"}");
+        aLiSendSms.sendSms(orderLogistics.getRecipientPhone(), "SMS_206737941", "{\"code\":\"" + random + "\"}");
     }
 
     @Override
     public List<OrderLogistics> queryMaturity() throws Exception {
         return orderLogisticsMapper.queryMaturity();
-    }
-
-    @Override
-    public List<OrderLogistics> taskMidAxbUnBindSend() throws Exception {
-        return this.baseMapper.taskMidAxbUnBindSend();
     }
 }

--
Gitblit v1.7.1