From 04ae1bf1c6b3f0498dfd180275a6d4255a8dce5e Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 26 五月 2023 15:14:24 +0800
Subject: [PATCH] 修改bug

---
 user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java |  149 ++++++++++++++++++++++++-------------------------
 1 files changed, 72 insertions(+), 77 deletions(-)

diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
index af5bc2e..a351a6f 100644
--- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
+++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -166,7 +166,7 @@
             }
             if(nearbyDriverWarppers.size() > 0){
                 NearbyDriverWarpper nearbyDriverWarpper = nearbyDriverWarppers.get(0);
-                Map<String, String> distance = MapUtil.getDistance(nearbyDriverWarpper.getLonLat(), estimatedCosts.getLng() + "," + estimatedCosts.getLat(), 1);
+                Map<String, String> distance = MapUtil.getDistance(nearbyDriverWarpper.getLonLat(), estimatedCosts.getStartLng() + "," + estimatedCosts.getStartLat(), 1);
                 if(null != distance){
                     distance.get("distance");//距离(M)
                     String duration = distance.get("duration");//时间(S)
@@ -449,18 +449,19 @@
         for (Integer i = 0; i < travelOrder.getDriverNum(); i++) {
             order.setId(null);
             order.setCode(UUIDUtil.getTimeStr() + UUIDUtil.getNumberRandom(3));
-            this.insert(order);
-
-            //推送状态
-            pushUtil.pushOrderStatus(uid, 1, order.getId(), order.getState());
-            if(null != order.getDriverId()){
-                PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
-                pushOrderInfoWarpper.setId(order.getId());
-                pushOrderInfoWarpper.setState(order.getState());
-                pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
-            }else{
-                //推单
-                pushOrder(order);
+            boolean insert = this.insert(order);
+            if(insert){
+                //推送状态
+                pushUtil.pushOrderStatus(uid, 1, order.getId(), order.getState());
+                if(null != order.getDriverId()){
+                    PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
+                    pushOrderInfoWarpper.setId(order.getId());
+                    pushOrderInfoWarpper.setState(order.getState());
+                    pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
+                }else{
+                    //推单
+                    pushOrder(order.getId());
+                }
             }
         }
         return ResultUtil.success(order.getId());
@@ -471,9 +472,9 @@
 
     /**
      * 订单推送逻辑
-     * @param order
      */
-    public void pushOrder(Order order){
+    public void pushOrder(Long orderId){
+        Order order = this.selectById(orderId);
         /**
          * 1.先找最大推单范围内的优推司机 -》 距离最近
          * 没有1 - 》
@@ -515,7 +516,7 @@
                     continue;
                 }
                 Driver driver1 = driverService.selectById(youTuiDriver.getDriverId());
-                if(driver1.getServerStatus() == 2){
+                if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){
                     continue;
                 }
                 Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
@@ -549,13 +550,14 @@
 
                 driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList());
                 if(driverIds.size() > 0){
-                    List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2).eq("serverStatus", 1).eq("status", 1).in("id", driverIds));
+                    List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2)
+                            .eq("serverStatus", 1).eq("openOrderQRCode", 0).eq("status", 1).in("id", driverIds));
                     if(drivers.size() == 0){
                         continue;
                     }
 
-                    Integer integral = null;
-                    Double score = null;
+                    Integer integral = null;//积分
+                    Double score = null;//评分
                     Double d = null;
                     for (Driver driver1 : drivers) {
                         String value = redisUtil.getValue("DRIVER" + driver1.getId());
@@ -566,19 +568,27 @@
                             integral = driver1.getIntegral();
                             score = driver1.getScore();
                             driver = driver1.getId();
+                            Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
+                            Double wgs84 = distance.get("WGS84");
+                            d = wgs84;
                             continue;
                         }
                         if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分
                             integral = driver1.getIntegral();
                             score = driver1.getScore();
                             driver = driver1.getId();
+                            Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
+                            Double wgs84 = distance.get("WGS84");
+                            d = wgs84;
                             continue;
                         }
                         if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离
                             Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
                             Double wgs84 = distance.get("WGS84");
-                            if(d == null || d.compareTo(wgs84) > 0){
+                            if(d.compareTo(wgs84) > 0){
                                 d = wgs84;
+                                integral = driver1.getIntegral();
+                                score = driver1.getScore();
                                 driver = driver1.getId();
                                 continue;
                             }
@@ -742,22 +752,6 @@
         BeanUtils.copyProperties(order, orderPriceWarpper);
         orderPriceWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
         orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue());
-        if(null == order.getPayTime()){
-            AppUser appUser = appUserService.selectById(uid);
-            orderPriceWarpper.setBalance(appUser.getAccountBalance());
-            Double orderMoney = order.getOrderMoney();
-            //先算优惠券
-            Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney);
-            if(null != coupon){
-                orderMoney = orderMoney - coupon.getCouponPreferentialAmount();
-                orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount());
-                orderPriceWarpper.setCouponId(coupon.getId());
-            }
-            orderPriceWarpper.setDiscount(0D);
-            orderPriceWarpper.setDiscountAmount(0D);
-            orderPriceWarpper.setPayType(1);//微信支付
-            orderPriceWarpper.setPayMoney(orderMoney);
-        }
         return orderPriceWarpper;
     }
 
@@ -785,10 +779,15 @@
         orderPriceWarpper.setPayType(1);//微信支付
         Double orderMoney = order.getOrderMoney();
         //先算优惠券
-        Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney);
-        if(null != coupon && null == couponId){
-            orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount());
-            orderPriceWarpper.setCouponId(coupon.getId());
+//        Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney);
+//        if(null != coupon && null == couponId){
+//            orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount());
+//            orderPriceWarpper.setCouponId(coupon.getId());
+//        }
+        if(payType == 1 && null == couponId && appUser.getHavDiscount() == 1 && balance.compareTo(orderMoney) >= 0){//使用余额抵扣
+            orderPriceWarpper.setDiscount(9D);
+            orderPriceWarpper.setDiscountAmount(new BigDecimal(orderMoney * 0.1).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
+            orderMoney = new BigDecimal(orderMoney * 0.9).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
         }
         if(null != couponId){
             UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
@@ -797,20 +796,16 @@
             orderPriceWarpper.setDiscountedPrice(coupon1.getCouponPreferentialAmount());
             orderPriceWarpper.setCouponId(couponId);
         }
-        if(payType == 1 && appUser.getHavDiscount() == 1 && balance >= orderMoney){//使用余额抵扣
-            orderPriceWarpper.setDiscount(9D);
-            orderPriceWarpper.setDiscountAmount(new BigDecimal(orderMoney * 0.1).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
-            orderMoney = new BigDecimal(orderMoney * 0.9).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
-        }
         if(payType == 0){//不使用余额抵扣
             orderPriceWarpper.setPayType(1);
         }
-        if(payType == 1 && balance >= orderMoney){//使用余额抵扣
+        if(payType == 1 && balance.compareTo(orderMoney) >= 0){//使用余额抵扣
             orderPriceWarpper.setPayType(2);
         }
-        if(payType == 1 && balance < orderMoney){//使用余额抵扣部分
+        if(payType == 1 && balance.compareTo(orderMoney) < 0){//使用余额抵扣部分
             orderPriceWarpper.setPayType(4);
         }
+
         orderPriceWarpper.setPayMoney(orderMoney);
         return orderPriceWarpper;
     }
@@ -958,13 +953,13 @@
                 accountChangeDetail.setUserType(2);
                 accountChangeDetail.setUserId(order.getDriverId());
                 accountChangeDetail.setCreateTime(new Date());
-                accountChangeDetail.setOldData(driver.getCouponBalance());
+                accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
                 accountChangeDetail.setType(1);
                 accountChangeDetail.setChangeType(7);
                 accountChangeDetail.setOrderId(order.getId());
                 accountChangeDetail.setExplain("优惠券收入");
                 driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount());
-                accountChangeDetail.setNewData(driver.getCouponBalance());
+                accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
                 driverService.updateById(driver);
                 accountChangeDetailService.insert(accountChangeDetail);
             }
@@ -1286,13 +1281,13 @@
             accountChangeDetail.setUserType(2);
             accountChangeDetail.setUserId(order.getDriverId());
             accountChangeDetail.setCreateTime(new Date());
-            accountChangeDetail.setOldData(driver.getCouponBalance());
+            accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
             accountChangeDetail.setType(1);
             accountChangeDetail.setChangeType(7);
             accountChangeDetail.setOrderId(order.getId());
             accountChangeDetail.setExplain("优惠券收入");
             driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount());
-            accountChangeDetail.setNewData(driver.getCouponBalance());
+            accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
             driverService.updateById(driver);
             accountChangeDetailService.insert(accountChangeDetail);
 
@@ -1457,11 +1452,11 @@
                             accountChangeDetail.setUserId(driver1.getId());
                             accountChangeDetail.setType(1);
                             accountChangeDetail.setChangeType(5);
-                            accountChangeDetail.setOldData(driver1.getCommission());
+                            accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                             accountChangeDetail.setExplain("订单分佣收入");
                             accountChangeDetail.setCreateTime(new Date());
                             driver1.setCommission(driver1.getCommission() + num1);
-                            accountChangeDetail.setNewData(driver1.getCommission());
+                            accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                             driverService.updateById(driver1);
                             accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -1478,17 +1473,17 @@
                     }
 
                     //开始处理层级抽佣
-                    if(null != driver.getInviterType() && driver.getInviterType() == 2){
+                    if(null != driver & null != driver.getInviterType() && driver.getInviterType() == 2){
                         Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机
-                        if(null != driver1.getInviterType() && driver1.getInviterType() == 2){
+                        if(null != driver1 && null != driver1.getInviterType() && driver1.getInviterType() == 2){
                             Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机
-                            if(null != driver2.getInviterType() && driver2.getInviterType() == 2){
+                            if(null != driver2 && null != driver2.getInviterType() && driver2.getInviterType() == 2){
                                 Driver driver3 = driverService.selectById(driver2.getInviterId());//三级级司机
                                 Double num5 = jsonObject1.getDouble("num5");
                                 Double num6 = jsonObject1.getDouble("num6");
                                 Double num7 = jsonObject1.getDouble("num7");
                                 num5 = (num3 >= num5 ? num5 : num3);
-                                if(num5 > 0){
+                                if(num5 > 0 && null != driver1){
                                     Revenue revenue = new Revenue();
                                     revenue.setType(2);
                                     revenue.setUserType(2);
@@ -1504,17 +1499,17 @@
                                     accountChangeDetail.setUserId(driver1.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver1.getCommission());
+                                    accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver1.setCommission(driver1.getCommission() + num5);
-                                    accountChangeDetail.setNewData(driver1.getCommission());
+                                    accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                     driverService.updateById(driver1);
                                     accountChangeDetailService.saveData(accountChangeDetail);
                                     num3 = (num3 >= num5 ? num3 - num5 : 0);
                                 }
                                 num6 = (num3 >= num6 ? num6 : num3);
-                                if(num6 > 0){
+                                if(num6 > 0 && null != driver2){
                                     Revenue revenue = new Revenue();
                                     revenue.setType(2);
                                     revenue.setUserType(2);
@@ -1530,17 +1525,17 @@
                                     accountChangeDetail.setUserId(driver2.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver2.getCommission());
+                                    accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver2.setCommission(driver2.getCommission() + num6);
-                                    accountChangeDetail.setNewData(driver2.getCommission());
+                                    accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
                                     driverService.updateById(driver2);
                                     accountChangeDetailService.saveData(accountChangeDetail);
                                     num3 = (num3 >= num6 ? num3 - num6 : 0);
                                 }
                                 num7 = (num3 >= num7 ? num7 : num3);
-                                if(num7 > 0){
+                                if(num7 > 0 && null != driver3){
                                     Revenue revenue = new Revenue();
                                     revenue.setType(2);
                                     revenue.setUserType(2);
@@ -1556,11 +1551,11 @@
                                     accountChangeDetail.setUserId(driver3.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver3.getCommission());
+                                    accountChangeDetail.setOldData(driver3.getBalance() + driver3.getBackgroundBalance() + driver3.getCouponBalance() + driver3.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver3.setCommission(driver3.getCommission() + num7);
-                                    accountChangeDetail.setNewData(driver3.getCommission());
+                                    accountChangeDetail.setNewData(driver3.getBalance() + driver3.getBackgroundBalance() + driver3.getCouponBalance() + driver3.getCommission());
                                     driverService.updateById(driver3);
                                     accountChangeDetailService.saveData(accountChangeDetail);
                                     num3 = (num3 >= num7 ? num3 - num7 : 0);
@@ -1569,7 +1564,7 @@
                                 Double num3_ = jsonObject1.getDouble("num3");
                                 Double num4 = jsonObject1.getDouble("num4");
                                 num3_ = (num3 >= num3_ ? num3_ : num3);
-                                if(num3_ > 0){
+                                if(num3_ > 0 && null != driver1){
                                     Revenue revenue = new Revenue();
                                     revenue.setType(2);
                                     revenue.setUserType(2);
@@ -1585,17 +1580,17 @@
                                     accountChangeDetail.setUserId(driver1.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver1.getCommission());
+                                    accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver1.setCommission(driver1.getCommission() + num3_);
-                                    accountChangeDetail.setNewData(driver1.getCommission());
+                                    accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                     driverService.updateById(driver1);
                                     accountChangeDetailService.saveData(accountChangeDetail);
                                     num3 = (num3 >= num3_ ? num3 - num3_ : 0);
                                 }
                                 num4 = (num3 >= num4 ? num4 : num3);
-                                if(num4 > 0){
+                                if(num4 > 0 && null != driver2){
                                     Revenue revenue = new Revenue();
                                     revenue.setType(2);
                                     revenue.setUserType(2);
@@ -1611,11 +1606,11 @@
                                     accountChangeDetail.setUserId(driver2.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver2.getCommission());
+                                    accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver2.setCommission(driver2.getCommission() + num4);
-                                    accountChangeDetail.setNewData(driver2.getCommission());
+                                    accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
                                     driverService.updateById(driver2);
                                     accountChangeDetailService.saveData(accountChangeDetail);
                                     num3 = (num3 >= num4 ? num3 - num4 : 0);
@@ -1624,7 +1619,7 @@
                         }else{
                             Double num2_ = jsonObject1.getDouble("num2");
                             num2_ = (num3 >= num2_ ? num2_ : num3);
-                            if(num2_ > 0){
+                            if(num2_ > 0 && null != driver1){
                                 Revenue revenue = new Revenue();
                                 revenue.setType(2);
                                 revenue.setUserType(2);
@@ -1640,11 +1635,11 @@
                                 accountChangeDetail.setUserId(driver1.getId());
                                 accountChangeDetail.setType(1);
                                 accountChangeDetail.setChangeType(5);
-                                accountChangeDetail.setOldData(driver1.getCommission());
+                                accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                 accountChangeDetail.setExplain("订单分佣收入");
                                 accountChangeDetail.setCreateTime(new Date());
                                 driver1.setCommission(driver1.getCommission() + num2_);
-                                accountChangeDetail.setNewData(driver1.getCommission());
+                                accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                 driverService.updateById(driver1);
                                 accountChangeDetailService.saveData(accountChangeDetail);
                                 num3 = (num3 >= num2_ ? num3 - num2_ : 0);
@@ -1652,7 +1647,7 @@
                         }
                     }
                     //处理代理商抽佣
-                    if(num3 > 0){
+                    if(num3 > 0 && null != driver){
                         Revenue revenue = new Revenue();
                         revenue.setType(1);
                         revenue.setUserType(3);
@@ -1682,14 +1677,14 @@
         accountChangeDetail.setType(1);
         accountChangeDetail.setChangeType(1);
         accountChangeDetail.setOrderId(order.getId());
-        accountChangeDetail.setOldData(driver.getBalance() + driver.getCouponBalance());
+        accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
         accountChangeDetail.setExplain("订单收入");
         accountChangeDetail.setCreateTime(new Date());
         driver.setBalance(driver.getBalance() + payMoney);
         if(null != order.getCouponId()){
             driver.setCouponBalance(driver.getCouponBalance() + order.getDiscountedPrice());
         }
-        accountChangeDetail.setNewData(driver.getBalance() + driver.getCouponBalance());
+        accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
         driverService.updateById(driver);
         accountChangeDetailService.saveData(accountChangeDetail);
     }

--
Gitblit v1.7.1