From 79e8abf8fb0e451fe151af6350d655f9c92727fd Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 09 六月 2023 21:04:21 +0800
Subject: [PATCH] 更新最终版本

---
 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java |  192 +++++++++++++++++++++++++++--------------------
 1 files changed, 110 insertions(+), 82 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 11518dc..030c3e6 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
@@ -277,8 +277,8 @@
                     order.setStartDistance(distance);//起步里程
                     order.setStartPrice(num4);//起步价
                 }else{
-                    BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num3));//超出起步里程
-                    BigDecimal divide = subtract.divide(new BigDecimal(num5), new MathContext(2, RoundingMode.HALF_EVEN));
+                    BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num3)).setScale(2, BigDecimal.ROUND_HALF_EVEN);//超出起步里程
+                    BigDecimal divide = subtract.divide(new BigDecimal(num5), 2, BigDecimal.ROUND_HALF_EVEN);
                     BigDecimal multiply = divide.multiply(new BigDecimal(num6));
                     order.setStartDistance(num3);//起步里程
                     order.setStartPrice(num4);//起步价
@@ -292,8 +292,8 @@
                     }
                     //计算长途里程超出的部分
                     if(distance.compareTo(num8) > 0){
-                        BigDecimal subtract1 = new BigDecimal(distance).subtract(new BigDecimal(num8));
-                        BigDecimal divide1 = subtract1.divide(new BigDecimal(num10), new MathContext(2, RoundingMode.HALF_EVEN));
+                        BigDecimal subtract1 = new BigDecimal(distance).subtract(new BigDecimal(num8)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                        BigDecimal divide1 = subtract1.divide(new BigDecimal(num10), 2, BigDecimal.ROUND_HALF_EVEN);
                         BigDecimal multiply1 = divide1.multiply(new BigDecimal(num11));
                         order.setOverLongDistance(subtract1.doubleValue());//超出长途里程
                         order.setOverLongDistancePrice(multiply1.doubleValue());//超出长途里程费
@@ -451,6 +451,10 @@
                 if(ToolUtil.isEmpty(value)){
                     continue;
                 }
+                DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", youTuiDriver.getDriverId()).eq("status", 1));
+                if(null == driverWork){
+                    continue;
+                }
                 Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
                 Double wgs84 = distance.get("WGS84");
                 if(d == null || d.compareTo(wgs84) > 0){
@@ -492,6 +496,10 @@
                     Double score = null;
                     Double d = null;
                     for (Driver driver1 : drivers) {
+                        DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver1.getId()).eq("status", 1));
+                        if(null == driverWork){
+                            continue;
+                        }
                         if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大
                             integral = driver1.getIntegral();
                             score = driver1.getScore();
@@ -859,6 +867,8 @@
                 accountChangeDetail.setUserType(2);
                 accountChangeDetail.setUserId(order.getDriverId());
                 accountChangeDetail.setType(2);
+                accountChangeDetail.setChangeType(5);
+                accountChangeDetail.setOrderId(order.getId());
                 accountChangeDetail.setOldData(driver.getIntegral().doubleValue());
                 driver.setIntegral(driver.getIntegral() + num5);
                 accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
@@ -866,52 +876,30 @@
                 accountChangeDetailService.saveData(accountChangeDetail);
             }
             //恶劣天气完成订单奖励
-            Integer num8 = JSON.parseObject(systemConfig.getContent()).getInteger("num8");
-            if(num8 > 0){
-                AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
-                accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
-                accountChangeDetail.setUserType(2);
-                accountChangeDetail.setUserId(order.getDriverId());
-                accountChangeDetail.setType(2);
-                accountChangeDetail.setOldData(driver.getIntegral().doubleValue());
-                driver.setIntegral(driver.getIntegral() + num8);
-                accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
-                accountChangeDetail.setExplain("恶劣天气完成订单奖励");
-                accountChangeDetailService.saveData(accountChangeDetail);
+            String city = "";
+            District geocode = MapUtil.geocode(order.getEndLng(), order.getEndLat());
+            if(null != geocode){
+                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() : "";
             }
-            driverService.updateById(driver);
-
-            if(null == order.getUserId()){
-                return;
-            }
-            //推荐用户首单完成奖励
-            Integer num4 = JSON.parseObject(systemConfig.getContent()).getInteger("num4");
-            if(num4 > 0){
-                List<Integer> state = Arrays.asList(105);
-                int count = this.selectCount(new EntityWrapper<Order>().eq("userId", order.getUserId()).eq("status", 1).in("state", state));
-                if(count > 1){
-                    return;
-                }
-                AppUser appUser = appUserService.selectById(order.getUserId());
-                if(null != appUser && null != appUser.getInviterType()){
-                    if(appUser.getInviterType() == 1){
-                        return;
-                    }
-                    Driver driver1 = driverService.selectById(appUser.getInviterId());
+            boolean badWeather = WeatherUtil.isBadWeather(city);
+            if(badWeather){
+                Integer num8 = JSON.parseObject(systemConfig.getContent()).getInteger("num8");
+                if(num8 > 0){
                     AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
                     accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
                     accountChangeDetail.setUserType(2);
-                    accountChangeDetail.setUserId(driver1.getId());
+                    accountChangeDetail.setUserId(order.getDriverId());
                     accountChangeDetail.setType(2);
-                    accountChangeDetail.setOldData(driver1.getIntegral().doubleValue());
-                    driver1.setIntegral(driver1.getIntegral() + num4);
-                    accountChangeDetail.setNewData(driver1.getIntegral().doubleValue());
-                    accountChangeDetail.setExplain("推荐用户完成首单奖励");
+                    accountChangeDetail.setOldData(driver.getIntegral().doubleValue());
+                    driver.setIntegral(driver.getIntegral() + num8);
+                    accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
+                    accountChangeDetail.setExplain("恶劣天气完成订单奖励");
                     accountChangeDetailService.saveData(accountChangeDetail);
-                    driverService.updateById(driver1);
                 }
             }
-
+            driverService.updateById(driver);
         }
     }
 
@@ -1193,13 +1181,13 @@
                     accountChangeDetail.setUserType(2);
                     accountChangeDetail.setUserId(order.getDriverId());
                     accountChangeDetail.setCreateTime(new Date());
-                    accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+                    accountChangeDetail.setOldData(driver.getCouponBalance() + driver.getCommission());
                     accountChangeDetail.setType(1);
                     accountChangeDetail.setChangeType(7);
                     accountChangeDetail.setOrderId(order.getId());
                     accountChangeDetail.setExplain("优惠券收入");
                     driver.setCommission(driver.getCommission() + coupon.getCouponPreferentialAmount());
-                    accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+                    accountChangeDetail.setNewData(driver.getCouponBalance() + driver.getCommission());
                     driverService.updateById(driver);
                     accountChangeDetailService.insert(accountChangeDetail);
 
@@ -1238,13 +1226,13 @@
                 accountChangeDetail.setUserType(2);
                 accountChangeDetail.setUserId(order.getDriverId());
                 accountChangeDetail.setCreateTime(new Date());
-                accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+                accountChangeDetail.setOldData(driver.getCouponBalance() + driver.getCommission());
                 accountChangeDetail.setType(1);
                 accountChangeDetail.setChangeType(7);
                 accountChangeDetail.setOrderId(order.getId());
                 accountChangeDetail.setExplain("折扣优惠收入");
                 driver.setCommission(driver.getCommission() + order.getDiscountAmount());
-                accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+                accountChangeDetail.setNewData(driver.getCouponBalance() + driver.getCommission());
                 driverService.updateById(driver);
                 accountChangeDetailService.insert(accountChangeDetail);
 
@@ -1304,7 +1292,7 @@
         Transfer transfer = new Transfer();
         transfer.setDepositMerOrderId(merOrderId);
         transfer.setToUserId(toUserId);
-        transfer.setAmount(String.valueOf(Double.valueOf(amount * 100)));
+        transfer.setAmount(String.valueOf(Double.valueOf(amount * 100).intValue()));
         transfer.setOrderName("补贴");
         transfer.setNotifyUrl(notifyUrl);
         transfer.setParameter1(id.toString());
@@ -1326,7 +1314,7 @@
 
 
     /**
-     * 计算抽成和分佣
+     * 计算线下收款的抽成和分佣
      * @param order
      */
     public void saveRevenue(Order order) throws Exception{
@@ -1334,41 +1322,67 @@
         //司机分佣和司机推荐用户首单奖励都在平台的抽佣中扣除,剩余的为平台抽佣。
         Driver driver = driverService.selectById(order.getDriverId());
         AppUser appUser = appUserService.selectById(order.getUserId());
+
+        //司机推荐首单收入
+        List<Integer> state = Arrays.asList(107, 108, 109);
+        int count = this.selectCount(new EntityWrapper<Order>().eq("userId", order.getUserId()).eq("status", 1).in("state", state));
+        if(null != appUser.getInviterType() && appUser.getInviterType() == 2 && count == 1){
+            Driver driver1 = driverService.selectById(appUser.getInviterId());
+            //首单积分奖励
+            SystemConfig systemConfig1 = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4));
+            JSONObject jsonObject2 = JSON.parseObject(systemConfig1.getContent());
+            Integer num4 = jsonObject2.getInteger("num4");
+            AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+            accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
+            accountChangeDetail.setUserType(2);
+            accountChangeDetail.setUserId(driver1.getId());
+            accountChangeDetail.setType(2);
+            accountChangeDetail.setChangeType(5);
+            accountChangeDetail.setOrderId(order.getId());
+            accountChangeDetail.setOldData(driver1.getIntegral().doubleValue());
+            accountChangeDetail.setExplain("邀请用户首单积分奖励");
+            accountChangeDetail.setCreateTime(new Date());
+            driver1.setIntegral(driver1.getIntegral() + num4);
+            accountChangeDetail.setNewData(driver1.getIntegral().doubleValue());
+            accountChangeDetailService.insert(accountChangeDetail);
+            driverService.updateById(driver1);
+        }
+
+
         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;//司机收入
+            if(order.getOrderMoney() >= num2){//订单金额大于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.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
                             accountChangeDetail.setUserType(2);
                             accountChangeDetail.setUserId(driver1.getId());
                             accountChangeDetail.setType(1);
                             accountChangeDetail.setChangeType(5);
-                            accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
-                            accountChangeDetail.setExplain("订单分佣收入");
+                            accountChangeDetail.setOldData(driver1.getCouponBalance() + driver1.getCommission());
+                            accountChangeDetail.setExplain("邀请用户首单奖励");
                             accountChangeDetail.setCreateTime(new Date());
                             driver1.setCommission(driver1.getCommission() + num1);
-                            accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
-                            driverService.updateById(driver1);
+                            accountChangeDetail.setNewData(driver1.getCouponBalance() + driver1.getCommission());
                             accountChangeDetailService.saveData(accountChangeDetail);
+                            driverService.updateById(driver1);
 
                             Revenue revenue = new Revenue();
                             revenue.setType(2);
@@ -1407,7 +1421,7 @@
                     }
 
                     //开始处理层级抽佣
-                    if(null != driver.getInviterType() && driver.getInviterType() == 2){
+                    if(num3 > 0 && null != driver.getInviterType() && driver.getInviterType() == 2){
                         Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机
                         if(null != driver1 && null != driver1.getInviterType() && driver1.getInviterType() == 2){
                             Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机
@@ -1433,11 +1447,11 @@
                                     accountChangeDetail.setUserId(driver1.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
+                                    accountChangeDetail.setOldData(driver1.getCouponBalance() + driver1.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver1.setCommission(driver1.getCommission() + num5);
-                                    accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
+                                    accountChangeDetail.setNewData(driver1.getCouponBalance() + driver1.getCommission());
                                     driverService.updateById(driver1);
                                     accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -1483,11 +1497,11 @@
                                     accountChangeDetail.setUserId(driver2.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
+                                    accountChangeDetail.setOldData(driver2.getCouponBalance() + driver2.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver2.setCommission(driver2.getCommission() + num6);
-                                    accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
+                                    accountChangeDetail.setNewData(driver2.getCouponBalance() + driver2.getCommission());
                                     driverService.updateById(driver2);
                                     accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -1533,11 +1547,11 @@
                                     accountChangeDetail.setUserId(driver3.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver3.getBalance() + driver3.getBackgroundBalance() + driver3.getCouponBalance() + driver3.getCommission());
+                                    accountChangeDetail.setOldData(driver3.getCouponBalance() + driver3.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver3.setCommission(driver3.getCommission() + num7);
-                                    accountChangeDetail.setNewData(driver3.getBalance() + driver3.getBackgroundBalance() + driver3.getCouponBalance() + driver3.getCommission());
+                                    accountChangeDetail.setNewData(driver3.getCouponBalance() + driver3.getCommission());
                                     driverService.updateById(driver3);
                                     accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -1586,11 +1600,11 @@
                                     accountChangeDetail.setUserId(driver1.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
+                                    accountChangeDetail.setOldData(driver1.getCouponBalance() + driver1.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver1.setCommission(driver1.getCommission() + num3_);
-                                    accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
+                                    accountChangeDetail.setNewData(driver1.getCouponBalance() + driver1.getCommission());
                                     driverService.updateById(driver1);
                                     accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -1636,11 +1650,11 @@
                                     accountChangeDetail.setUserId(driver2.getId());
                                     accountChangeDetail.setType(1);
                                     accountChangeDetail.setChangeType(5);
-                                    accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
+                                    accountChangeDetail.setOldData(driver2.getCouponBalance() + driver2.getCommission());
                                     accountChangeDetail.setExplain("订单分佣收入");
                                     accountChangeDetail.setCreateTime(new Date());
                                     driver2.setCommission(driver2.getCommission() + num4);
-                                    accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
+                                    accountChangeDetail.setNewData(driver2.getCouponBalance() + driver2.getCommission());
                                     driverService.updateById(driver2);
                                     accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -1689,11 +1703,11 @@
                                 accountChangeDetail.setUserId(driver1.getId());
                                 accountChangeDetail.setType(1);
                                 accountChangeDetail.setChangeType(5);
-                                accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
+                                accountChangeDetail.setOldData(driver1.getCouponBalance() + driver1.getCommission());
                                 accountChangeDetail.setExplain("订单分佣收入");
                                 accountChangeDetail.setCreateTime(new Date());
                                 driver1.setCommission(driver1.getCommission() + num2_);
-                                accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
+                                accountChangeDetail.setNewData(driver1.getCouponBalance() + driver1.getCommission());
                                 driverService.updateById(driver1);
                                 accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -1760,8 +1774,9 @@
                 }
             }
         }
-        //司机余额扣减抽佣金额
+        //司机余额扣减抽佣金额,将金额先分账给平台
         if(order.getPayMoney() > payMoney){
+            driver = driverService.selectById(order.getDriverId());
             Double m = order.getPayMoney() - payMoney;
             AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
             accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
@@ -1770,11 +1785,11 @@
             accountChangeDetail.setType(1);
             accountChangeDetail.setChangeType(9);
             accountChangeDetail.setOrderId(order.getId());
-            accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+            accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance());
             accountChangeDetail.setExplain("线下收款服务费支出");
             accountChangeDetail.setCreateTime(new Date());
             driver.setBalance(driver.getBalance() - m);
-            accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+            accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance());
             driverService.updateById(driver);
             accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -1829,7 +1844,7 @@
         List<PamentOrderUser> splitList = new ArrayList<>();
         PamentOrderUser pamentOrderUser = new PamentOrderUser();
         pamentOrderUser.setSplitUserId(merchantNumber);
-        pamentOrderUser.setSplitAmount(amount.toString());
+        pamentOrderUser.setSplitAmount(String.valueOf(Double.valueOf(amount * 100).intValue()));
         pamentOrderUser.setSplitType("1");
         splitList.add(pamentOrderUser);
         complete.setSplitList(splitList);
@@ -1876,11 +1891,11 @@
         Receive receive = new Receive();
         receive.setOriginalMerOrderId(orderNumber);
         receive.setAsynMerOrderId(divisionRecord.getMerOrderId());
-        receive.setRcvAmount(divisionRecord.getAmount().toString());
+        receive.setRcvAmount(String.valueOf(Double.valueOf(divisionRecord.getAmount() * 100).intValue()));
         List<ReceiveUser> splitList = new ArrayList<>();
         ReceiveUser receiveUser = new ReceiveUser();
         receiveUser.setSplitUserId(merchantNumber);
-        receiveUser.setRcvSplitAmount(divisionRecord.getAmount().toString());
+        receiveUser.setRcvSplitAmount(String.valueOf(Double.valueOf(divisionRecord.getAmount() * 100).intValue()));
         splitList.add(receiveUser);
         receive.setSplitList(splitList);
         TrhRequest<Receive> request = new TrhRequest();
@@ -1991,6 +2006,10 @@
             if(performanceRankingWarpper.getDriverId().compareTo(driverId) == 0){
                 break;
             }
+            if(i == performanceRankingWarppers.size() - 1){
+                position = 0;
+                d = 0D;
+            }
         }
         MyAchievementWarpper myAchievementWarpper = new MyAchievementWarpper();
         myAchievementWarpper.setType("订单");
@@ -2012,6 +2031,10 @@
             }
             if(performanceRankingWarpper.getDriverId().compareTo(driverId) == 0){
                 break;
+            }
+            if(i == performanceRankingWarppers.size() - 1){
+                position = 0;
+                d = 0D;
             }
         }
         myAchievementWarpper = new MyAchievementWarpper();
@@ -2035,6 +2058,10 @@
             if(performanceRankingWarpper.getDriverId().compareTo(driverId) == 0){
                 break;
             }
+            if(i == performanceRankingWarppers.size() - 1){
+                position = 0;
+                d = 0D;
+            }
         }
         myAchievementWarpper = new MyAchievementWarpper();
         myAchievementWarpper.setType("佣金");
@@ -2051,7 +2078,8 @@
      */
     @Override
     public void completeCollection() {
-        List<Order> orders = this.selectList(new EntityWrapper<Order>().eq("state", 107).eq("status", 1).eq("payType", 3));
+        List<Order> orders = this.selectList(new EntityWrapper<Order>().eq("state", 107).eq("status", 1)
+                .eq("payType", 3).last(" and UNIX_TIMESTAMP(getoffTime) + 120 <= UNIX_TIMESTAMP(now())"));
         for (Order order : orders) {
             order.setPayTime(new Date());
             if(null != order.getCouponId()){
@@ -2067,13 +2095,13 @@
                     accountChangeDetail.setUserType(2);
                     accountChangeDetail.setUserId(order.getDriverId());
                     accountChangeDetail.setCreateTime(new Date());
-                    accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+                    accountChangeDetail.setOldData(driver.getCouponBalance() + driver.getCommission());
                     accountChangeDetail.setType(1);
                     accountChangeDetail.setChangeType(7);
                     accountChangeDetail.setOrderId(order.getId());
                     accountChangeDetail.setExplain("优惠券收入");
                     driver.setCommission(driver.getCommission() + coupon.getCouponPreferentialAmount());
-                    accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+                    accountChangeDetail.setNewData(driver.getCouponBalance() + driver.getCommission());
                     driverService.updateById(driver);
                     accountChangeDetailService.insert(accountChangeDetail);
 
@@ -2110,13 +2138,13 @@
                 accountChangeDetail.setUserType(2);
                 accountChangeDetail.setUserId(order.getDriverId());
                 accountChangeDetail.setCreateTime(new Date());
-                accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+                accountChangeDetail.setOldData(driver.getCouponBalance() + driver.getCommission());
                 accountChangeDetail.setType(1);
                 accountChangeDetail.setChangeType(7);
                 accountChangeDetail.setOrderId(order.getId());
                 accountChangeDetail.setExplain("折扣优惠收入");
                 driver.setCommission(driver.getCommission() + order.getDiscountAmount());
-                accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+                accountChangeDetail.setNewData(driver.getCouponBalance() + driver.getCommission());
                 driverService.updateById(driver);
                 accountChangeDetailService.insert(accountChangeDetail);
 

--
Gitblit v1.7.1