From 7a9e05846c5e37f7278f242857056d0623532379 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 16 六月 2023 20:17:32 +0800
Subject: [PATCH] 修改bug和功能优化

---
 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java |  413 ++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 267 insertions(+), 146 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 030c3e6..b6fa8fc 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
@@ -196,10 +196,10 @@
                     .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);
+        order.setCreateTime(new Date());
+        order = getOrderPrice(1, d, 0D, order, city);
         order.setState(null == order.getDriverId() ? 101 : 102);
         order.setStatus(1);
-        order.setCreateTime(new Date());
         this.insert(order);
         driverService.updateById(driver);
         //推送状态
@@ -228,7 +228,9 @@
      * @param city          查询天气的城市
      * @return
      */
-    public Order getOrderPrice(Integer type, Double distance, Integer waitTime, Order order, String city){
+    public Order getOrderPrice(Integer type, Double distance, Double waitTime, Order order, String city){
+        distance = new BigDecimal(distance).setScale(0, BigDecimal.ROUND_UP).doubleValue();
+        waitTime = new BigDecimal(waitTime).setScale(0, BigDecimal.ROUND_UP).doubleValue();
         order = getOrderInitialPrice(order);
         SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5));
         if(null == systemConfig){
@@ -243,7 +245,7 @@
         JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
         JSONArray chargeStandard = jsonObject.getJSONArray("ChargeStandard");
         JSONObject extraCost = jsonObject.getJSONObject("ExtraCost");
-        Date date = new Date();
+        Date date = order.getCreateTime();
         for (int i = 0; i < chargeStandard.size(); i++) {
             JSONObject jsonObject1 = chargeStandard.getJSONObject(i);
             String num1 = jsonObject1.getString("num1");
@@ -259,18 +261,29 @@
             Double num11 = jsonObject1.getDouble("num11");//超过num8每num10公里收取num11
 
             String[] split = num1.split(":");
+            Integer hour1 = Integer.valueOf(split[0]);
+            String[] split1 = num2.split(":");
+            Integer hour2 = Integer.valueOf(split1[0]);
+
             Calendar s = Calendar.getInstance();
             s.setTime(date);
-            s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0]));
+            s.set(Calendar.HOUR_OF_DAY, hour1);
             s.set(Calendar.MINUTE, Integer.valueOf(split[1]));
             s.set(Calendar.SECOND, 0);
 
-            split = num2.split(":");
             Calendar e = Calendar.getInstance();
             e.setTime(date);
-            e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0]));
-            e.set(Calendar.MINUTE, Integer.valueOf(split[1]));
+            e.set(Calendar.HOUR_OF_DAY, hour2);
+            e.set(Calendar.MINUTE, Integer.valueOf(split1[1]));
             e.set(Calendar.SECOND, 0);
+
+            if(hour1 > hour2){
+                if(s.getTimeInMillis() > date.getTime()){
+                    s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) - 1);
+                }else{
+                    e.set(Calendar.DAY_OF_YEAR, e.get(Calendar.DAY_OF_YEAR) + 1);
+                }
+            }
 
             if(date.getTime() >= s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){
                 if(num3.compareTo(distance) >= 0){//起步里程内
@@ -285,8 +298,13 @@
                     order.setOverDriveDistance(subtract.doubleValue());//超出起步里程
                     order.setOverDrivePrice(multiply.doubleValue());//超出起步里程费
 
-                    //计算长途费
+                    //计算长途费(超出长途起始公里,费用开始按照长途规则计算。)
                     if(distance.compareTo(num7) > 0){
+                        order.setStartDistance(0D);//起步里程
+                        order.setStartPrice(0D);//起步价
+                        order.setOverDriveDistance(0D);//超出起步里程
+                        order.setOverDrivePrice(0D);//超出起步里程费
+
                         order.setLongDistance(num7 + "-" + num8);//长途里程
                         order.setLongDistancePrice(num9);//长途费
                     }
@@ -304,9 +322,9 @@
         }
 
         //计算额外费用
-        Integer num1 = extraCost.getInteger("num1");//等待时长
+        Double num1 = extraCost.getDouble("num1");//等待时长
         Double num2 = extraCost.getDouble("num2");//等待费
-        Integer num3 = extraCost.getInteger("num3");//等待超出时长
+        Double num3 = extraCost.getDouble("num3");//等待超出时长
         Double num4 = extraCost.getDouble("num4");//等到超出时长费用单价 X/分钟
         Double num5 = extraCost.getDouble("num5");//恶劣天气公里
         Double num6 = extraCost.getDouble("num6");//恶劣天气费
@@ -319,7 +337,7 @@
             order.setWaitTime(num1);//等待时长
             order.setWaitTimePrice(num2);//等待费用
 
-            Integer w = waitTime - num3;
+            Double w = waitTime - num1 - num3;
             BigDecimal multiply = new BigDecimal(w).multiply(new BigDecimal(num4));
             order.setOutWaitTime(w);//等待时长超出分钟
             order.setOutWaitTimePrice(multiply.doubleValue());//等待时长超出费用
@@ -390,9 +408,9 @@
         order.setLongDistancePrice(0D);//长途里程费
         order.setOverLongDistance(0D);//超出长途里程
         order.setOverLongDistancePrice(0d);//超出长途里程费
-        order.setWaitTime(0);//等待时长
+//        order.setWaitTime(0);//等待时长
         order.setWaitTimePrice(0D);//等待费
-        order.setOutWaitTime(0);//超出等待时长
+        order.setOutWaitTime(0D);//超出等待时长
         order.setOutWaitTimePrice(0D);//超出等待时长费
         order.setBadWeatherDistance(0D);//恶劣天气里程
         order.setBadWeatherPrice(0D);//恶劣天气里程费
@@ -411,27 +429,194 @@
      * @param order
      */
     public void pushOrder(Order order){
-        /**
-         * 1.先找最大推单范围内的优推司机 -》 距离最近
-         * 没有1 - 》
-         *      2.按照后台推送配置在范围内查找合适司机
-         *        合适司:积分 > 评分 > 距离
-         *      3.司机没有接单直接将订单置入大厅
-         */
-        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1));
-        if(null == systemConfig){
-            return;
+        try {
+            /**
+             * 1.先找最大推单范围内的优推司机 -》 距离最近
+             * 没有1 - 》
+             *      2.按照后台推送配置在范围内查找合适司机
+             *        合适司:积分 > 评分 > 距离
+             *      3.司机没有接单直接将订单置入大厅
+             */
+            boolean lock = redisUtil.lock(5);
+            if(!lock){
+                int num1 = 1;
+                while (num1 <= 10){
+                    Thread.sleep(3000);//等待3秒
+                    lock = redisUtil.lock(5);
+                    if(lock){
+                        break;
+                    }else{
+                        num1++;
+                    }
+                }
+            }
+            if(!lock){
+                redisUtil.unlock();
+                order.setHallOrder(1);
+                this.updateById(order);
+                ExtraPushOrder(order);
+                return;
+            }
+            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1));
+            if(null == systemConfig){
+                redisUtil.unlock();
+                return;
+            }
+            JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
+            Double num3 = jsonObject.getDouble("num3");//推单最大范围
+            Integer num4 = jsonObject.getInteger("num4");//接单时间
+            String startLat = order.getStartLat();
+            String startLng = order.getStartLng();
+
+            //1
+            //找到中心点
+            GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat));
+            Double num = num3 / 1000;//范围公里
+            //构造半径
+            Distance distanceR = new Distance(num, Metrics.KILOMETERS);
+            //画圆
+            Circle circle = new Circle(geoJsonPoint, distanceR);
+            // 构造query对象
+            Query query = Query.query(Criteria.where("location").withinSphere(circle));
+            List<Location> locations = mongoTemplate.find(query, Location.class);
+            List<Integer> driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList());
+            Integer driver = null;
+            YouTuiDriver youTuiDriver1 = null;
+            if(driverIds.size() > 0){
+                List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds)
+                        .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime"));
+                Double d = null;
+                for (YouTuiDriver youTuiDriver : youTuiDrivers) {
+                    String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId());
+                    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){
+                        d = wgs84;
+                        driver = youTuiDriver.getDriverId();
+                        youTuiDriver1 = youTuiDriver;
+                    }
+                }
+            }
+
+            if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){
+                youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1);
+                youTuiDriverService.updateById(youTuiDriver1);
+            }
+
+            //开始范围查找
+            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);
+                    //画圆
+                    circle = new Circle(geoJsonPoint, distanceR);
+                    // 构造query对象
+                    query = Query.query(Criteria.where("location").withinSphere(circle));
+                    locations = mongoTemplate.find(query, Location.class);
+
+                    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));
+                        if(drivers.size() == 0){
+                            continue;
+                        }
+
+                        Integer integral = null;
+                        Double score = null;
+                        Double d = null;
+                        for (Driver driver1 : drivers) {
+                            String value = redisUtil.getValue("DRIVER" + driver1.getId());
+                            if(ToolUtil.isEmpty(value)){
+                                continue;
+                            }
+                            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();
+                                driver = driver1.getId();
+                                continue;
+                            }
+                            if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分
+                                integral = driver1.getIntegral();
+                                score = driver1.getScore();
+                                driver = driver1.getId();
+                                continue;
+                            }
+                            if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离
+                                String value1 = redisUtil.getValue("DRIVER" + driver1.getId());
+                                if(ToolUtil.isEmpty(value1)){
+                                    continue;
+                                }
+                                Map<String, Double> distance = GeodesyUtil.getDistance(value1, order.getStartLng() + "," + order.getStartLat());
+                                Double wgs84 = distance.get("WGS84");
+                                if(d == null || d.compareTo(wgs84) > 0){
+                                    d = wgs84;
+                                    driver = driver1.getId();
+                                    continue;
+                                }
+                            }
+                        }
+
+                    }
+                }
+            }
+
+            if(null != driver){
+                //防止多笔订单推给一个司机
+                Driver driver1 = driverService.selectById(driver);
+                driver1.setServerStatus(2);
+                driverService.updateById(driver1);
+                pushUtil.pushGrabOrder(driver, 2, order.getId(), num4);
+                //创建定时任务处理订单到大厅
+                new Timer().schedule(new TimerTask() {
+                    @Override
+                    public void run() {
+                        driver1.setServerStatus(1);
+                        driverService.updateById(driver1);
+
+                        Order order1 = OrderServiceImpl.this.selectById(order.getId());
+                        if(order1.getState() == 101 || order1.getState() == 201){
+                            order1.setHallOrder(1);
+                            OrderServiceImpl.this.updateById(order1);
+                            ExtraPushOrder(order);
+                        }
+                    }
+                }, num4 * 1000);
+            }else{
+                order.setHallOrder(1);
+                this.updateById(order);
+                ExtraPushOrder(order);
+            }
+            redisUtil.unlock();
+        }catch (Exception e){
+            redisUtil.unlock();
+            e.printStackTrace();
         }
-        JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
-        Double num3 = jsonObject.getDouble("num3");//推单最大范围
-        Integer num4 = jsonObject.getInteger("num4");//接单时间
+    }
+
+
+
+    public void ExtraPushOrder(Order order){
         String startLat = order.getStartLat();
         String startLng = order.getStartLng();
 
-        //1
         //找到中心点
         GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat));
-        Double num = num3 / 1000;//范围公里
+        Double num = 5D;//范围公里
         //构造半径
         Distance distanceR = new Distance(num, Metrics.KILOMETERS);
         //画圆
@@ -440,115 +625,26 @@
         Query query = Query.query(Criteria.where("location").withinSphere(circle));
         List<Location> locations = mongoTemplate.find(query, Location.class);
         List<Integer> driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList());
-        Integer driver = null;
-        YouTuiDriver youTuiDriver1 = null;
-        if(driverIds.size() > 0){
-            List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds)
-                    .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime"));
-            Double d = null;
-            for (YouTuiDriver youTuiDriver : youTuiDrivers) {
-                String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId());
-                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){
-                    d = wgs84;
-                    driver = youTuiDriver.getDriverId();
-                    youTuiDriver1 = youTuiDriver;
-                }
+        if(driverIds.size() == 0){
+            return;
+        }
+        List<DriverWork> tDriverWorks = driverWorkService.selectList(new EntityWrapper<DriverWork>().in("driverId", driverIds).eq("status", 1));
+        driverIds = tDriverWorks.stream().map(DriverWork::getDriverId).collect(Collectors.toList());
+        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){
+            return;
+        }
+        for (Driver driver1 : drivers) {
+            String value = redisUtil.getValue("DRIVER" + driver1.getId());
+            if (ToolUtil.isEmpty(value)) {
+                return;
             }
-        }
-
-        if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){
-            youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1);
-            youTuiDriverService.updateById(youTuiDriver1);
-        }
-
-        //开始范围查找
-        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);
-                //画圆
-                circle = new Circle(geoJsonPoint, distanceR);
-                // 构造query对象
-                query = Query.query(Criteria.where("location").withinSphere(circle));
-                locations = mongoTemplate.find(query, Location.class);
-
-                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));
-                    if(drivers.size() == 0){
-                        continue;
-                    }
-
-                    Integer integral = null;
-                    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();
-                            driver = driver1.getId();
-                            continue;
-                        }
-                        if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分
-                            integral = driver1.getIntegral();
-                            score = driver1.getScore();
-                            driver = driver1.getId();
-                            continue;
-                        }
-                        if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离
-                            String value = redisUtil.getValue("DRIVER" + driver1.getId());
-                            if(ToolUtil.isEmpty(value)){
-                                continue;
-                            }
-                            Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
-                            Double wgs84 = distance.get("WGS84");
-                            if(d == null || d.compareTo(wgs84) > 0){
-                                d = wgs84;
-                                driver = driver1.getId();
-                                continue;
-                            }
-                        }
-                    }
-
-                }
-            }
-        }
-
-        if(null != driver){
-            pushUtil.pushGrabOrder(driver, 2, order.getId(), num4);
-            //创建定时任务处理订单到大厅
-            new Timer().schedule(new TimerTask() {
-                @Override
-                public void run() {
-                    Order order1 = OrderServiceImpl.this.selectById(order.getId());
-                    if(order1.getState() == 101 || order1.getState() == 201){
-                        order1.setHallOrder(1);
-                        OrderServiceImpl.this.updateById(order1);
-                    }
-                }
-            }, num4 * 1000);
-        }else{
-            order.setHallOrder(1);
-            this.updateById(order);
+            pushUtil.pushGrabOrderExtras(driver1.getId(), 2);
         }
     }
+
+
 
 
 
@@ -606,6 +702,9 @@
         orderRefusalService.insert(orderRefusal);
 
         Driver driver = driverService.selectById(uid);
+        driver.setServerStatus(1);
+        driverService.updateById(driver);
+
         //扣除积分
         SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4));
         if(null != systemConfig) {
@@ -651,7 +750,19 @@
             if(count > 0){
                 return ResultUtil.error("还有未完成的订单");
             }
-            boolean lock = redisUtil.lock();
+            boolean lock = redisUtil.lock(5);
+            if(!lock){
+                int num1 = 1;
+                while (num1 <= 10){
+                    Thread.sleep(3000);//等待3秒
+                    lock = redisUtil.lock(5);
+                    if(lock){
+                        break;
+                    }else{
+                        num1++;
+                    }
+                }
+            }
             if(!lock){
                 return ResultUtil.error("请重试");
             }
@@ -807,7 +918,7 @@
                     order.setStartTime(new Date());
                 }
                 //计算等待用户时长
-                Integer w = Double.valueOf((System.currentTimeMillis() - order.getStartWaitTime().getTime()) / 60000).intValue();
+                Double w = new BigDecimal(Double.valueOf(System.currentTimeMillis() - order.getStartWaitTime().getTime()) / 60000).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                 order.setWaitTime(order.getWaitTime() + w);
                 order.setStartWaitTime(null);
                 break;
@@ -847,6 +958,9 @@
         }
         return ResultUtil.success();
     }
+
+
+
 
 
     /**
@@ -932,9 +1046,9 @@
                     pushOrderInfoWarpper.setDriverLat(split[1]);
                     pushOrderInfoWarpper.setDriverLng(split[0]);
                 }
-                int w = 0;
+                Double w = 0D;
                 if(null != order.getStartWaitTime()){
-                    w = Double.valueOf((System.currentTimeMillis() - order.getStartWaitTime().getTime()) / 60000).intValue();
+                    w = Double.valueOf((System.currentTimeMillis() - order.getStartWaitTime().getTime()) / 60000);
                 }
                 pushOrderInfoWarpper.setWaitTime(order.getWaitTime() + w);
                 pushOrderInfoWarpper.setState(order.getState());
@@ -1028,7 +1142,7 @@
                     .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);
+        order = getOrderPrice(1, d, 0D, order, city);
         this.updateById(order);
         return ResultUtil.success();
     }
@@ -1152,6 +1266,12 @@
             return ResultUtil.error("操作失败");
         }
         Order order = this.selectById(orderId);
+        if(state == 107 && order.getState() != 106){
+            return ResultUtil.error("操作失败");
+        }
+        if(state == 108 && order.getState() != 107){
+            return ResultUtil.error("操作失败");
+        }
         order.setState(state);
 
         if(payType == 2 && state == 107){
@@ -1159,7 +1279,7 @@
             Coupon coupon = userToCouponService.queryCoupon(order.getUserId(), order.getOrderMoney());
             if(null != coupon){
                 order.setCouponId(coupon.getId());
-                order.setDiscountAmount(coupon.getCouponPreferentialAmount());
+                order.setDiscountedPrice(coupon.getCouponPreferentialAmount());
                 order.setPayMoney(order.getOrderMoney() - coupon.getCouponPreferentialAmount());
             }else{
                 order.setPayMoney(order.getOrderMoney());
@@ -1362,8 +1482,8 @@
                 SystemConfig systemConfig1 = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 2));
                 if(null != systemConfig1){
                     JSONObject jsonObject1 = JSON.parseObject(systemConfig1.getContent());
-                    //司机推荐首单收入
-                    if(null != appUser.getInviterType() && appUser.getInviterType() == 2 && count == 1){
+                    //司机推荐用户收入
+                    if(null != appUser.getInviterType() && appUser.getInviterType() == 2){
                         Double num1 = jsonObject1.getDouble("num1");
                         num1 = (num3 >= num1 ? num1 : num3);
 
@@ -1377,7 +1497,7 @@
                             accountChangeDetail.setType(1);
                             accountChangeDetail.setChangeType(5);
                             accountChangeDetail.setOldData(driver1.getCouponBalance() + driver1.getCommission());
-                            accountChangeDetail.setExplain("邀请用户首单奖励");
+                            accountChangeDetail.setExplain("邀请用户奖励");
                             accountChangeDetail.setCreateTime(new Date());
                             driver1.setCommission(driver1.getCommission() + num1);
                             accountChangeDetail.setNewData(driver1.getCouponBalance() + driver1.getCommission());
@@ -1775,7 +1895,7 @@
             }
         }
         //司机余额扣减抽佣金额,将金额先分账给平台
-        if(order.getPayMoney() > payMoney){
+        if(order.getPayMoney().compareTo(payMoney) > 0){
             driver = driverService.selectById(order.getDriverId());
             Double m = order.getPayMoney() - payMoney;
             AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
@@ -2079,8 +2199,9 @@
     @Override
     public void completeCollection() {
         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())"));
+                .eq("payType", 3).last(" and UNIX_TIMESTAMP(getoffTime) + 600 <= UNIX_TIMESTAMP(now())"));
         for (Order order : orders) {
+            order.setState(108);
             order.setPayTime(new Date());
             if(null != order.getCouponId()){
                 UserToCoupon userToCoupon = userToCouponService.selectById(order.getCouponId());

--
Gitblit v1.7.1