From 7454b6532cd2a5c68235a45f1cc540e25f1ffaf4 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 07 四月 2023 18:40:45 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java |  421 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 360 insertions(+), 61 deletions(-)

diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java
index 646f3a3..4416d6b 100644
--- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java
+++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java
@@ -107,12 +107,15 @@
      * @throws Exception
      */
     @Override
-    public Long queryDriverServerOrder(Integer uid) throws Exception {
-        Order order = this.selectOne(new EntityWrapper<Order>().eq("driverId", uid).eq("status", 1).in("state", Arrays.asList(102, 103, 104, 105, 201)));
+    public Map<String, Object> queryDriverServerOrder(Integer uid) throws Exception {
+        Order order = this.selectOne(new EntityWrapper<Order>().eq("driverId", uid).eq("status", 1)
+                .in("state", Arrays.asList(102, 103, 104, 105, 106, 401)));
+        Map<String, Object> map = new HashMap<>();
         if(null != order){
-            return order.getId();
+            map.put("id", order.getId());
+            map.put("state", order.getState());
         }
-        return 0L;
+        return map;
     }
 
 
@@ -129,14 +132,13 @@
          * 司机上线且空闲,下单直接给当前司机,其余进大厅
          * 司机下的订单不需要创建新用户,且只能走线下支付
          */
-
         int count = this.selectCount(new EntityWrapper<Order>().eq("userPhone", addOrderWarpper.getPhone()).eq("status", 1).in("state", Arrays.asList(101, 102, 103, 104, 105, 106, 201)));
         if(count > 0){
             return ResultUtil.error("该用户还有未完成的订单");
         }
         Driver driver = driverService.selectById(uid);
         DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", uid).eq("status", 1));
-        Order order1 = this.selectOne(new EntityWrapper<Order>().eq("driverId", uid).eq("status", 1).in("state", Arrays.asList(102, 103, 104, 105, 201)));
+        Order order1 = this.selectOne(new EntityWrapper<Order>().eq("driverId", uid).eq("status", 1).in("state", Arrays.asList(102, 103, 104, 105, 201, 401)));
         Order order = new Order();
         if(driverWork != null && null == order1){
             order.setDriverId(uid);
@@ -168,11 +170,13 @@
             }
             d = Double.valueOf(distance.get("distance")) / 1000;
             order.setEstimatedMileage(d);
+            order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60);
         }
         String city = "";
         District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat());
         if(null != geocode){
-            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district"));
+            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
+                    .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
             city = null != weatherCity ? weatherCity.getId().toString() : "";
         }
         order = getOrderPrice(1, d, 0, order, city);
@@ -188,7 +192,7 @@
             //开始推单
             pushOrder(order);
         }
-        return ResultUtil.success();
+        return ResultUtil.success(order.getState() == 102 ? order.getId() : null);
     }
 
 
@@ -299,28 +303,36 @@
         }
 
         //恶劣天气
-        boolean badWeather = WeatherUtil.isBadWeather(city);
-        if(badWeather){
-            order.setBadWeatherDistance(num5);//恶劣天气公里
-            order.setBadWeatherPrice(num6);//恶劣天气费
-            if(distance.compareTo(num7) > 0){
-                BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7));
-                BigDecimal multiply = subtract.multiply(new BigDecimal(num8));
-                order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里
-                order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费
-            }
+        systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8));
+        if(null != systemConfig) {
+            JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent());
+            Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价
+            if(1 == num11){
+                boolean badWeather = WeatherUtil.isBadWeather(city);
+                if(badWeather){
+                    order.setBadWeatherDistance(num5);//恶劣天气公里
+                    order.setBadWeatherPrice(num6);//恶劣天气费
+                    if(distance.compareTo(num7) > 0){
+                        BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7));
+                        BigDecimal multiply = subtract.multiply(new BigDecimal(num8));
+                        order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里
+                        order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费
+                    }
 
-            double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
-            if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额)
-                if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额
-                    order.setBadWeatherPrice(num9);//恶劣天气费
-                    order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费
-                }else{
-                    BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add));
-                    order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费
+                    double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+                    if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额)
+                        if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额
+                            order.setBadWeatherPrice(num9);//恶劣天气费
+                            order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费
+                        }else{
+                            BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add));
+                            order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费
+                        }
+                    }
                 }
             }
         }
+
 
         //计算折扣
         if(null != order.getUserId()){
@@ -434,6 +446,9 @@
         //开始范围查找
         if(null == driver){
             for (int i = 1; i < 4; i++) {
+                if(null != driver){
+                    break;
+                }
                 num = jsonObject.getDouble("num" + i) / 1000;//范围公里
                 //构造半径
                 distanceR = new Distance(num, Metrics.KILOMETERS);
@@ -517,13 +532,16 @@
     @Override
     public List<HallOrderList> queryOrderHall(Integer uid, Integer pageNum, Integer pageSize) throws Exception {
         pageNum = (pageNum - 1) * pageSize;
+        String value = redisUtil.getValue("DRIVER" + uid);
         List<HallOrderList> hallOrderLists = this.baseMapper.queryOrderHall(pageNum, pageSize);
         hallOrderLists.forEach(hallOrderList -> {
             hallOrderList.setCurrentDistance(0D);
-            if(ToolUtil.isNotEmpty(hallOrderList.getEndLng())){
-                Map<String, Double> distance = GeodesyUtil.getDistance(hallOrderList.getStartLng() + "," + hallOrderList.getStartLat(), hallOrderList.getEndLng() + "," + hallOrderList.getEndLat());
+            if(ToolUtil.isNotEmpty(value)){
+                Map<String, Double> distance = GeodesyUtil.getDistance(hallOrderList.getStartLng() + "," + hallOrderList.getStartLat(), value);
                 Double wgs84 = distance.get("WGS84");
                 hallOrderList.setCurrentDistance(wgs84);
+            }else{
+                hallOrderList.setCurrentDistance(0D);
             }
         });
         return hallOrderLists;
@@ -566,8 +584,8 @@
                 accountChangeDetail.setUserType(2);
                 accountChangeDetail.setUserId(order.getDriverId());
                 accountChangeDetail.setType(2);
-                accountChangeDetail.setOldData(driver.getIntegral().doubleValue());
-                driver.setIntegral(driver.getIntegral() - num10);
+                accountChangeDetail.setOldData(null == driver.getIntegral() ? 0 : driver.getIntegral().doubleValue());
+                driver.setIntegral((null == driver.getIntegral() ? 0 : driver.getIntegral()) - num10);
                 accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
                 accountChangeDetail.setExplain("拒绝订单扣除积分");
                 accountChangeDetailService.saveData(accountChangeDetail);
@@ -591,6 +609,11 @@
             DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", uid).eq("status", 1));
             if(null == driverWork){
                 return ResultUtil.error("请先上班");
+            }
+            List<Integer> state1 = Arrays.asList(102, 103, 104, 105, 106, 201, 401);
+            int count = this.selectCount(new EntityWrapper<Order>().eq("driverId", uid).eq("status", 1).in("state", state1));
+            if(count > 0){
+                return ResultUtil.error("还有未完成的订单");
             }
             boolean lock = redisUtil.lock();
             if(!lock){
@@ -662,6 +685,7 @@
             }
 
             //推动订单数据
+            pushOrderInfo(order.getId(), uid);//开始推送订单数据
             //发送系统消息
             systemMessageService.addSystemMessage(uid, 2, "接单成功", "您已成功接到用户订单,请尽快联系客户!");
             pushUtil.pushOrderStatus(order.getDriverId(), 2, order.getId(), order.getState());
@@ -687,6 +711,9 @@
     @Override
     public OrderInfoWarpper queryOrderInfo(Integer uid, Long orderId) throws Exception {
         OrderInfoWarpper orderInfoWarpper = this.baseMapper.queryOrderInfo(orderId);
+        if(orderInfoWarpper.getTravelTime() == null){
+            orderInfoWarpper.setTravelTime(0);
+        }
         AppUser appUser = appUserService.selectById(uid);
         orderInfoWarpper.setBalance(appUser.getAccountBalance());
         orderInfoWarpper.setCurrentDistance(0D);
@@ -724,7 +751,6 @@
         switch (processOperationsWarpper.getState()){
             case 103:
                 order.setGoToAppointmentPointTime(new Date());
-                pushOrderInfo(order.getId(), uid);//开始推送订单数据
                 break;
             case 104:
                 order.setStartWaitTime(new Date());
@@ -736,10 +762,10 @@
                     order.setBoardingTime(new Date());
                     order.setStartTime(new Date());
                 }
-                order.setStartWaitTime(null);
                 //计算等待用户时长
                 Integer w = Double.valueOf((System.currentTimeMillis() - order.getStartWaitTime().getTime()) / 60000).intValue();
                 order.setWaitTime(order.getWaitTime() + w);
+                order.setStartWaitTime(null);
                 break;
             case 106:
                 order.setGetoffTime(new Date());
@@ -748,17 +774,12 @@
                     order.setEndLng(processOperationsWarpper.getEndLng());
                     order.setEndLat(processOperationsWarpper.getEndLat());
                 }
-                //停止定时任务
-                Timer timer = timerMap.get(order.getId().toString());
-                if(null != timer){
-                    timer.cancel();
-                    timerMap.remove(order.getId().toString());
-                }
                 //开始计算费用
                 String city = "";
                 District geocode = MapUtil.geocode(order.getEndLng(), order.getEndLat());
                 if(null != geocode){
-                    WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district"));
+                    WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
+                            .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
                     city = null != weatherCity ? weatherCity.getId().toString() : "";
                 }
                 order = getOrderPrice(2, Double.valueOf(order.getActualMileage() / 1000), order.getWaitTime(), order, city);
@@ -836,21 +857,23 @@
                     return;
                 }
                 AppUser appUser = appUserService.selectById(order.getUserId());
-                if(appUser.getInviterType() == 1){
-                    return;
+                if(null != appUser && null != appUser.getInviterType()){
+                    if(appUser.getInviterType() == 1){
+                        return;
+                    }
+                    Driver driver1 = driverService.selectById(appUser.getInviterId());
+                    AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                    accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
+                    accountChangeDetail.setUserType(2);
+                    accountChangeDetail.setUserId(driver1.getId());
+                    accountChangeDetail.setType(2);
+                    accountChangeDetail.setOldData(driver1.getIntegral().doubleValue());
+                    driver1.setIntegral(driver1.getIntegral() + num4);
+                    accountChangeDetail.setNewData(driver1.getIntegral().doubleValue());
+                    accountChangeDetail.setExplain("推荐用户完成首单奖励");
+                    accountChangeDetailService.saveData(accountChangeDetail);
+                    driverService.updateById(driver1);
                 }
-                Driver driver1 = driverService.selectById(appUser.getInviterId());
-                AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
-                accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
-                accountChangeDetail.setUserType(2);
-                accountChangeDetail.setUserId(driver1.getId());
-                accountChangeDetail.setType(2);
-                accountChangeDetail.setOldData(driver1.getIntegral().doubleValue());
-                driver1.setIntegral(driver1.getIntegral() + num4);
-                accountChangeDetail.setNewData(driver1.getIntegral().doubleValue());
-                accountChangeDetail.setExplain("推荐用户完成首单奖励");
-                accountChangeDetailService.saveData(accountChangeDetail);
-                driverService.updateById(driver1);
             }
 
         }
@@ -870,7 +893,7 @@
             public void run() {
                 String value = redisUtil.getValue("DRIVER" + uid);
                 Order order = OrderServiceImpl.this.selectById(orderId);
-                if(order.getState() == 106){
+                if(order.getState() == 106 || order.getState() == 301){
                     Timer timer = timerMap.get(order.getId().toString());
                     if(null != timer){
                         timer.cancel();
@@ -894,8 +917,11 @@
                     pushOrderInfoWarpper.setTravelTime(travelTime);
                 }
                 pushUtil.pushOrderInfo(uid, 2, pushOrderInfoWarpper);
+                if(null != order.getUserId()){
+                    pushUtil.pushOrderInfo(order.getUserId(), 1, pushOrderInfoWarpper);
+                }
             }
-        },0, 5000);
+        },0, 10000);
         timerMap.put(orderId.toString(), timer);
     }
 
@@ -954,10 +980,12 @@
         }
         Double d = Double.valueOf(distance.get("distance")) / 1000;
         order.setEstimatedMileage(d);
+        order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60);
         String city = "";
         District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat());
         if(null != geocode){
-            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district"));
+            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
+                    .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
             city = null != weatherCity ? weatherCity.getId().toString() : "";
         }
         order = getOrderPrice(1, d, 0, order, city);
@@ -1022,6 +1050,11 @@
         cancelOrder.setStatus(1);
         cancelOrder.setCreateTime(new Date());
         cancelOrderService.insert(cancelOrder);
+        Driver driver = driverService.selectById(order.getDriverId());
+        if(null != driver){
+            driver.setServerStatus(1);
+            driverService.updateById(driver);
+        }
         return ResultUtil.success();
     }
 
@@ -1039,8 +1072,23 @@
         Order order = this.selectById(orderId);
         OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper();
         BeanUtils.copyProperties(order, orderPriceWarpper);
+        orderPriceWarpper.setWaitTime(orderPriceWarpper.getWaitTime() + orderPriceWarpper.getOutWaitTime());
+        orderPriceWarpper.setWaitTimePrice(orderPriceWarpper.getWaitTimePrice() + orderPriceWarpper.getOutWaitTimePrice());
+        orderPriceWarpper.setLongDistance(0D);
+        if(ToolUtil.isNotEmpty(order.getLongDistance())){
+            String[] split = order.getLongDistance().split("-");
+            Double longDistanc = Double.valueOf(split[1]) - Double.valueOf(split[0]) + orderPriceWarpper.getOverLongDistance();
+            orderPriceWarpper.setLongDistance(longDistanc);
+        }
+        orderPriceWarpper.setLongDistancePrice(orderPriceWarpper.getLongDistancePrice() + orderPriceWarpper.getOverLongDistancePrice());
+        orderPriceWarpper.setBadWeatherDistance(orderPriceWarpper.getBadWeatherDistance() + orderPriceWarpper.getOverBadWeatherDistance());
+        orderPriceWarpper.setBadWeatherPrice(orderPriceWarpper.getBadWeatherPrice() + orderPriceWarpper.getOverBadWeatherPrice());
+
         orderPriceWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-        orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue());
+        orderPriceWarpper.setTravelTime(0);
+        if(null != order.getGetoffTime()){
+            orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue());
+        }
         orderPriceWarpper.setWxCollectionCode(driver.getWxCollectionCode());
         orderPriceWarpper.setZfbCollectionCode(driver.getZfbCollectionCode());
         return orderPriceWarpper;
@@ -1058,7 +1106,7 @@
     @Override
     public ResultUtil setOrderStatus(Integer uid, Long orderId, Integer state) throws Exception {
         List<Integer> s = Arrays.asList(107, 108);
-        if(s.contains(state)){
+        if(!s.contains(state)){
             return ResultUtil.error("操作失败");
         }
         Order order = this.selectById(orderId);
@@ -1074,9 +1122,12 @@
             saveRevenue(order);
         }
 
-        pushUtil.pushOrderStatus(order.getDriverId(), 2, orderId, order.getState());
+        PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
+        pushOrderInfoWarpper.setId(order.getId());
+        pushOrderInfoWarpper.setState(order.getState());
+        pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
         if(null != order.getUserId()){
-            pushUtil.pushOrderStatus(order.getUserId(), 1, orderId, order.getState());
+            pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState());
         }
         return ResultUtil.success();
     }
@@ -1086,8 +1137,256 @@
      * 计算抽成和分佣
      * @param order
      */
-    public void saveRevenue(Order order){
+    public void saveRevenue(Order order) throws Exception{
+        //司机收入和代理商抽成(先分佣,后抽成)
+        //司机分佣和司机推荐用户首单奖励都在平台的抽佣中扣除,剩余的为平台抽佣。
+        Driver driver = driverService.selectById(order.getDriverId());
+        AppUser appUser = appUserService.selectById(order.getUserId());
+        Double payMoney = order.getPayMoney();
+        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 3));
+        Double n = 0D;
+        if(null != systemConfig){
+            JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
+            Double num2 = jsonObject.getDouble("num2");
+            Double num3 = jsonObject.getDouble("num3");
+            n = num3;
+            if(order.getPayMoney() >= num2){
+                payMoney = payMoney - num3;//司机收入
+                SystemConfig systemConfig1 = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 2));
+                if(null != systemConfig1){
+                    JSONObject jsonObject1 = JSON.parseObject(systemConfig1.getContent());
+                    //司机推荐首单收入
+                    List<Integer> state = Arrays.asList(108, 109);
+                    int count = this.selectCount(new EntityWrapper<Order>().eq("userId", appUser.getId()).eq("status", 1).in("state", state));
+                    if(null != appUser.getInviterType() && appUser.getInviterType() == 2 && count == 1){
+                        Double num1 = jsonObject1.getDouble("num1");
+                        num1 = (num3 >= num1 ? num1 : num3);
 
+                        if(num1 > 0){
+                            Driver driver1 = driverService.selectById(appUser.getInviterId());
+                            AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                            accountChangeDetail.setUserType(2);
+                            accountChangeDetail.setUserId(driver1.getId());
+                            accountChangeDetail.setType(1);
+                            accountChangeDetail.setChangeType(5);
+                            accountChangeDetail.setOldData(driver1.getCommission());
+                            accountChangeDetail.setExplain("订单分佣收入");
+                            accountChangeDetail.setCreateTime(new Date());
+                            driver1.setCommission(driver1.getCommission() + num1);
+                            accountChangeDetail.setNewData(driver1.getCommission());
+                            driverService.updateById(driver1);
+                            accountChangeDetailService.saveData(accountChangeDetail);
+
+                            Revenue revenue = new Revenue();
+                            revenue.setType(2);
+                            revenue.setUserType(2);
+                            revenue.setUserId(driver1.getId());
+                            revenue.setOrderId(order.getId());
+                            revenue.setAmount(num1);
+                            revenue.setCreateTime(new Date());
+                            revenueService.insert(revenue);
+                        }
+                        num3 = (num3 >= num1 ? num3 - num1 : 0);
+                    }
+
+                    //开始处理层级抽佣
+                    if(null != driver.getInviterType() && driver.getInviterType() == 2){
+                        Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机
+                        if(null != driver1.getInviterType() && driver1.getInviterType() == 2){
+                            Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机
+                            if(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){
+                                    Revenue revenue = new Revenue();
+                                    revenue.setType(2);
+                                    revenue.setUserType(2);
+                                    revenue.setUserId(driver1.getId());
+                                    revenue.setOrderId(order.getId());
+                                    revenue.setAmount(num5);
+                                    revenue.setCreateTime(new Date());
+                                    revenueService.insert(revenue);
+
+                                    AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                                    accountChangeDetail.setUserType(2);
+                                    accountChangeDetail.setUserId(driver1.getId());
+                                    accountChangeDetail.setType(1);
+                                    accountChangeDetail.setChangeType(5);
+                                    accountChangeDetail.setOldData(driver1.getCommission());
+                                    accountChangeDetail.setExplain("订单分佣收入");
+                                    accountChangeDetail.setCreateTime(new Date());
+                                    driver1.setCommission(driver1.getCommission() + num5);
+                                    accountChangeDetail.setNewData(driver1.getCommission());
+                                    driverService.updateById(driver1);
+                                    accountChangeDetailService.saveData(accountChangeDetail);
+                                    num3 = (num3 >= num5 ? num3 - num5 : 0);
+                                }
+                                num6 = (num3 >= num6 ? num6 : num3);
+                                if(num6 > 0){
+                                    Revenue revenue = new Revenue();
+                                    revenue.setType(2);
+                                    revenue.setUserType(2);
+                                    revenue.setUserId(driver2.getId());
+                                    revenue.setOrderId(order.getId());
+                                    revenue.setAmount(num6);
+                                    revenue.setCreateTime(new Date());
+                                    revenueService.insert(revenue);
+
+                                    AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                                    accountChangeDetail.setUserType(2);
+                                    accountChangeDetail.setUserId(driver2.getId());
+                                    accountChangeDetail.setType(1);
+                                    accountChangeDetail.setChangeType(5);
+                                    accountChangeDetail.setOldData(driver2.getCommission());
+                                    accountChangeDetail.setExplain("订单分佣收入");
+                                    accountChangeDetail.setCreateTime(new Date());
+                                    driver2.setCommission(driver2.getCommission() + num6);
+                                    accountChangeDetail.setNewData(driver2.getCommission());
+                                    driverService.updateById(driver2);
+                                    accountChangeDetailService.saveData(accountChangeDetail);
+                                    num3 = (num3 >= num6 ? num3 - num6 : 0);
+                                }
+                                num7 = (num3 >= num7 ? num7 : num3);
+                                if(num7 > 0){
+                                    Revenue revenue = new Revenue();
+                                    revenue.setType(2);
+                                    revenue.setUserType(2);
+                                    revenue.setUserId(driver3.getId());
+                                    revenue.setOrderId(order.getId());
+                                    revenue.setAmount(num7);
+                                    revenue.setCreateTime(new Date());
+                                    revenueService.insert(revenue);
+
+                                    AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                                    accountChangeDetail.setUserType(2);
+                                    accountChangeDetail.setUserId(driver3.getId());
+                                    accountChangeDetail.setType(1);
+                                    accountChangeDetail.setChangeType(5);
+                                    accountChangeDetail.setOldData(driver3.getCommission());
+                                    accountChangeDetail.setExplain("订单分佣收入");
+                                    accountChangeDetail.setCreateTime(new Date());
+                                    driver3.setCommission(driver3.getCommission() + num7);
+                                    accountChangeDetail.setNewData(driver3.getCommission());
+                                    driverService.updateById(driver3);
+                                    accountChangeDetailService.saveData(accountChangeDetail);
+                                    num3 = (num3 >= num7 ? num3 - num7 : 0);
+                                }
+                            }else{
+                                Double num3_ = jsonObject1.getDouble("num3");
+                                Double num4 = jsonObject1.getDouble("num4");
+                                num3_ = (num3 >= num3_ ? num3_ : num3);
+                                if(num3_ > 0){
+                                    Revenue revenue = new Revenue();
+                                    revenue.setType(2);
+                                    revenue.setUserType(2);
+                                    revenue.setUserId(driver1.getId());
+                                    revenue.setOrderId(order.getId());
+                                    revenue.setAmount(num3_);
+                                    revenue.setCreateTime(new Date());
+                                    revenueService.insert(revenue);
+
+                                    AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                                    accountChangeDetail.setUserType(2);
+                                    accountChangeDetail.setUserId(driver1.getId());
+                                    accountChangeDetail.setType(1);
+                                    accountChangeDetail.setChangeType(5);
+                                    accountChangeDetail.setOldData(driver1.getCommission());
+                                    accountChangeDetail.setExplain("订单分佣收入");
+                                    accountChangeDetail.setCreateTime(new Date());
+                                    driver1.setCommission(driver1.getCommission() + num3_);
+                                    accountChangeDetail.setNewData(driver1.getCommission());
+                                    driverService.updateById(driver1);
+                                    accountChangeDetailService.saveData(accountChangeDetail);
+                                    num3 = (num3 >= num3_ ? num3 - num3_ : 0);
+                                }
+                                num4 = (num3 >= num4 ? num4 : num3);
+                                if(num4 > 0){
+                                    Revenue revenue = new Revenue();
+                                    revenue.setType(2);
+                                    revenue.setUserType(2);
+                                    revenue.setUserId(driver2.getId());
+                                    revenue.setOrderId(order.getId());
+                                    revenue.setAmount(num4);
+                                    revenue.setCreateTime(new Date());
+                                    revenueService.insert(revenue);
+
+                                    AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                                    accountChangeDetail.setUserType(2);
+                                    accountChangeDetail.setUserId(driver2.getId());
+                                    accountChangeDetail.setType(1);
+                                    accountChangeDetail.setChangeType(5);
+                                    accountChangeDetail.setOldData(driver2.getCommission());
+                                    accountChangeDetail.setExplain("订单分佣收入");
+                                    accountChangeDetail.setCreateTime(new Date());
+                                    driver2.setCommission(driver2.getCommission() + num4);
+                                    accountChangeDetail.setNewData(driver2.getCommission());
+                                    driverService.updateById(driver2);
+                                    accountChangeDetailService.saveData(accountChangeDetail);
+                                    num3 = (num3 >= num4 ? num3 - num4 : 0);
+                                }
+                            }
+                        }else{
+                            Double num2_ = jsonObject1.getDouble("num2");
+                            num2_ = (num3 >= num2_ ? num2_ : num3);
+                            if(num2_ > 0){
+                                Revenue revenue = new Revenue();
+                                revenue.setType(2);
+                                revenue.setUserType(2);
+                                revenue.setUserId(driver1.getId());
+                                revenue.setOrderId(order.getId());
+                                revenue.setAmount(num2_);
+                                revenue.setCreateTime(new Date());
+                                revenueService.insert(revenue);
+
+                                AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                                accountChangeDetail.setUserType(2);
+                                accountChangeDetail.setUserId(driver1.getId());
+                                accountChangeDetail.setType(1);
+                                accountChangeDetail.setChangeType(5);
+                                accountChangeDetail.setOldData(driver1.getCommission());
+                                accountChangeDetail.setExplain("订单分佣收入");
+                                accountChangeDetail.setCreateTime(new Date());
+                                driver1.setCommission(driver1.getCommission() + num2_);
+                                accountChangeDetail.setNewData(driver1.getCommission());
+                                driverService.updateById(driver1);
+                                accountChangeDetailService.saveData(accountChangeDetail);
+                                num3 = (num3 >= num2_ ? num3 - num2_ : 0);
+                            }
+                        }
+                    }
+                    //处理代理商抽佣
+                    if(num3 > 0){
+                        Revenue revenue = new Revenue();
+                        revenue.setType(1);
+                        revenue.setUserType(3);
+                        revenue.setUserId(driver.getAgentId());
+                        revenue.setOrderId(order.getId());
+                        revenue.setAmount(num3);
+                        revenue.setCreateTime(new Date());
+                        revenueService.insert(revenue);
+                    }
+                }
+            }
+        }
+        //司机余额扣减抽佣金额
+        if(n > 0){
+            AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+            accountChangeDetail.setUserType(2);
+            accountChangeDetail.setUserId(driver.getId());
+            accountChangeDetail.setType(1);
+            accountChangeDetail.setChangeType(9);
+            accountChangeDetail.setOrderId(order.getId());
+            accountChangeDetail.setOldData(driver.getBalance());
+            accountChangeDetail.setExplain("线下收款服务费支出");
+            accountChangeDetail.setCreateTime(new Date());
+            driver.setBalance(driver.getBalance() - n);
+            accountChangeDetail.setNewData(driver.getBalance());
+            driverService.updateById(driver);
+            accountChangeDetailService.saveData(accountChangeDetail);
+        }
     }
 
     /**

--
Gitblit v1.7.1