From 79d97c39f1d118824f91467feb9f4a55717fd0c0 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 26 七月 2024 14:03:41 +0800
Subject: [PATCH] Merge branch '2.0' of http://120.76.84.145:10101/gitblit/r/java/IgoTravel into 2.0

---
 UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java |  656 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 503 insertions(+), 153 deletions(-)

diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
index 5ade0de..cc9ef4f 100644
--- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
+++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -30,6 +30,8 @@
 import com.stylefeng.guns.modular.system.util.Tingg.model.Results;
 import com.stylefeng.guns.modular.system.util.itextpdf.HtmlToPdfUtils;
 import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
+import com.stylefeng.guns.modular.system.warpper.EndPushWarpper;
+import com.stylefeng.guns.modular.system.warpper.OrderServerWarpper;
 import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
 import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
 import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
@@ -51,10 +53,7 @@
 import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
+import java.io.*;
 import java.math.BigDecimal;
 import java.math.MathContext;
 import java.math.RoundingMode;
@@ -208,6 +207,10 @@
     
     @Autowired
     private ICarService carService;
+    
+    
+    @Value("${filePath}")
+    private String filePath;
 
 
 
@@ -556,7 +559,42 @@
                                 if(bo){
                                     continue;
                                 }
-                                pushUtil.pushOrderState(2, driver.getId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), pushOrder.getPushTime());
+                                String text = "";
+                                Integer language1 = driver.getLanguage();
+                                switch (language1){
+                                    case 1:
+                                        text = "收到新的包裹订单,从" + orderLogistics.getStartAddress() + "出发,全程约" + orderLogistics.getEstimatedMileage() + "公里";
+                                        break;
+                                    case 2:
+                                        text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre";
+                                        break;
+                                    case 3:
+                                        text = "J'ai reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage() + "kilométrage";
+                                        break;
+        
+                                }
+                                String audioUrl = "";
+                                try {
+                                    audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, "pushOrder" + orderLogistics.getDriverId() + ".mp3");
+                                } catch (Exception e) {
+                                    throw new RuntimeException(e);
+                                }
+                                //定时任务删除语音文件
+                                new Timer().schedule(new TimerTask() {
+                                    @Override
+                                    public void run() {
+                                        Process process = null;
+                                        try {
+                                            process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/pushOrder" + orderLogistics.getDriverId() + ".mp3");
+                                        } catch (IOException e) {
+                                            throw new RuntimeException(e);
+                                        }
+                                        if (process != null) {
+                                            process.destroy();
+                                        }
+                                    }
+                                }, 30000);
+                                pushUtil.pushOrderState(2, driver.getId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), pushOrder.getPushTime(), audioUrl);
                             }
                         }
                         Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间
@@ -647,6 +685,7 @@
         orderLogistics.setInsertTime(new Date());
         orderLogistics.setTravelTime(new Date());
         orderLogistics.setOrderSource(orderSource);
+        orderLogistics.setRemark(remark);
         if(orderSource == 2){//扫码下单
             Driver driver = driverService.selectById(driverId);
             if(null == driver){
@@ -684,7 +723,15 @@
             CarService query1 = carServiceMapper.query(1, driver.getCarId());
             orderLogistics.setServerCarModelId(query1.getServerCarModelId());
             orderLogistics.setSnatchOrderTime(new Date());
-        
+            String value = redisUtil.getValue("DRIVER" + driver.getId());
+            if(ToolUtil.isNotEmpty(value)) {
+                String[] split = value.split(",");
+                DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]));
+                //超时时间
+                long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000);
+                orderLogistics.setEstimateArriveTime(new Date(timeOut));
+                orderLogistics.setEstimateArriveMileage(distancematrix.getDistance());
+            }
             driver.setState(3);
             driverService.updateById(driver);
         }
@@ -692,37 +739,82 @@
         orderLogistics.setIsReassign(1);
         orderLogistics.setIsDelete(1);
         orderLogistics.setTripId(UUIDUtil.getRandomCode());
+        DistancematrixVo distancematrix1 = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), orderLogistics.getEndLat(), orderLogistics.getEndLon());
+        Long distance1 = distancematrix1.getDistance();
+        orderLogistics.setEstimatedMileage(new BigDecimal(distance1).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
         this.insert(orderLogistics);
     
-    
-        String vehicleId = null;
-        if(null != orderLogistics.getDriverId()){
-            Driver driver = driverService.selectById(orderLogistics.getDriverId());
-            Car car = carMapper.selectById(driver.getCarId());
-            if(!StringUtils.hasLength(car.getVehicleId())){
-                car.setVehicleId(UUIDUtil.getRandomCode());
-                carMapper.updateById(car);
-            }
-            //查询车辆信息,没有则创建信息
-            String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
-            if(ToolUtil.isEmpty(vehicles)){
-                CarModel carModel = carModelMapper.selectById(car.getCarModelId());
-                fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
-                fleetEngineUtil.updateVehicles("ONLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
-            }
+        new Thread(() -> {
+            try {
+                String vehicleId = null;
+                if(null != orderLogistics.getDriverId()){
+                    Driver driver = driverService.selectById(orderLogistics.getDriverId());
+                    Car car = carMapper.selectById(driver.getCarId());
+                    if(!StringUtils.hasLength(car.getVehicleId())){
+                        car.setVehicleId(UUIDUtil.getRandomCode());
+                        carMapper.updateById(car);
+                    }
+                    //查询车辆信息,没有则创建信息
+                    String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
+                    if(ToolUtil.isEmpty(vehicles)){
+                        CarModel carModel = carModelMapper.selectById(car.getCarModelId());
+                        fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
+                        fleetEngineUtil.updateVehicles("ONLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
+                    }
         
-        }
-        //创建行程数据
-        fleetEngineUtil.createTrip(vehicleId, 1, orderLogistics.getTripId(),
-                orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
+                }
+                //创建行程数据
+                fleetEngineUtil.createTrip(vehicleId, 1, orderLogistics.getTripId(),
+                        orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
     
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+        }).start();
     
         if(orderSource == 2){//扫码下单
+            Driver driver = driverService.selectById(orderLogistics.getDriverId());
+            String text = "";
+            Integer language1 = driver.getLanguage();
+            switch (language1){
+                case 1:
+                    text = "收到新的包裹订单,从" + orderLogistics.getStartAddress() + "出发,全程约" + orderLogistics.getEstimatedMileage() + "公里";
+                    break;
+                case 2:
+                    text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre";
+                    break;
+                case 3:
+                    text = "J'ai reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage() + "kilométrage";
+                    break;
+        
+            }
+            String audioUrl = "";
+            try {
+                audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, "pushOrder" + orderLogistics.getDriverId() + ".mp3");
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            //定时任务删除语音文件
+            new Timer().schedule(new TimerTask() {
+                @Override
+                public void run() {
+                    Process process = null;
+                    try {
+                        process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/pushOrder" + orderLogistics.getDriverId() + ".mp3");
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                    if (process != null) {
+                        process.destroy();
+                    }
+                }
+            }, 30000);
+            String finalAudioUrl = audioUrl;
             new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    pushUtil.pushOrderState(1, uid, orderLogistics.getId(), 4, 2, 0);
-                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, 2, 0);
+                    pushUtil.pushOrderState(1, uid, orderLogistics.getId(), 4, 2, 0, "");
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, 2, 0, finalAudioUrl);
                 }
             }).start();
         }
@@ -793,12 +885,48 @@
                     dr.setState(3);
                     driverService.updateById(dr);
                     this.updateById(orderLogistics);
-                
+    
+                    String text = "";
+                    Integer language1 = dr.getLanguage();
+                    switch (language1){
+                        case 1:
+                            text = "收到新的包裹订单,从" + orderLogistics.getStartAddress() + "出发,全程约" + orderLogistics.getEstimatedMileage() + "公里";
+                            break;
+                        case 2:
+                            text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre";
+                            break;
+                        case 3:
+                            text = "J'ai reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage() + "kilométrage";
+                            break;
+        
+                    }
+                    String audioUrl = "";
+                    try {
+                        audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, "pushOrder" + orderLogistics.getDriverId() + ".mp3");
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                    //定时任务删除语音文件
+                    new Timer().schedule(new TimerTask() {
+                        @Override
+                        public void run() {
+                            Process process = null;
+                            try {
+                                process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/pushOrder" + orderLogistics.getDriverId() + ".mp3");
+                            } catch (IOException e) {
+                                throw new RuntimeException(e);
+                            }
+                            if (process != null) {
+                                process.destroy();
+                            }
+                        }
+                    }, 30000);
+                    String finalAudioUrl = audioUrl;
                     new Thread(new Runnable() {
                         @Override
                         public void run() {
-                            pushUtil.pushOrderState(1, uid, orderLogistics.getId(), 4, 2, 0);
-                            pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, 2, 0);
+                            pushUtil.pushOrderState(1, uid, orderLogistics.getId(), 4, 2, 0, "");
+                            pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, 2, 0, finalAudioUrl);
                         }
                     }).start();
                 }
@@ -861,9 +989,22 @@
         }
         UserInfo userInfo = userInfoService.selectById(uid);
         ResultUtil resultUtil = ResultUtil.success("");
-        //折扣
-        if(null != orderLogistics.getActivityId()){
-            orderMoney = orderMoney - orderLogistics.getDiscountMoney();
+        //计算折扣
+        UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderLogistics.getCompanyId());
+        if(null != query2){
+            Integer orderNum=this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId",orderLogistics.getUserId()).eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())"));
+            if(query2.getDistance()*1000>orderLogistics.getMileage() && query2.getOrderNum()>orderNum){
+                Double special = query2.getLogistics();
+                if(null != special){
+                    orderLogistics.setDiscount(special);
+                    double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+                    if(orderMoney.compareTo(v) > 0){
+                        orderLogistics.setDiscountMoney(orderMoney - v);
+                        orderLogistics.setActivityId(query2.getId());
+                        orderMoney = v;
+                    }
+                }
+            }
         }
         
         //计算优惠券
@@ -901,11 +1042,12 @@
                 Double total = userRedPacketRecordService.queryRemainingAmount(uid);
                 List<UserRedPacketRecord> userRedPacketRecords = userRedPacketRecordService.selectList(new EntityWrapper<UserRedPacketRecord>().eq("userId", uid)
                         .eq("state", 1).eq("companyId", orderLogistics.getCompanyId()).gt("remainingAmount", 0).orderBy("insertTime", false));
-                if(total.compareTo(orderMoney) >= 0){
-                    BigDecimal deductionRatio = redEnvelopePaymentSettings.getDeductionRatio();
-                    BigDecimal multiply = new BigDecimal(orderMoney).multiply(deductionRatio.divide(new BigDecimal(100)));
-                    orderLogistics.setRedPacketMoney(multiply.doubleValue());
-                    orderMoney = orderMoney - multiply.doubleValue();
+    
+                BigDecimal deductionRatio = redEnvelopePaymentSettings.getDeductionRatio();
+                BigDecimal multiply1 = new BigDecimal(orderMoney).multiply(deductionRatio.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_EVEN);
+                if(total.compareTo(multiply1.doubleValue()) >= 0){
+                    orderLogistics.setRedPacketMoney(multiply1.doubleValue());
+                    orderMoney = orderMoney - multiply1.doubleValue();
                 
                     //获取红包id
                     JSONArray jsonArray = new JSONArray();
@@ -913,14 +1055,19 @@
                         JSONObject jsonObject = new JSONObject();
                         jsonObject.put("id", userRedPacketRecord.getId());
                         BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount());
-                        if(multiply.compareTo(remainingAmount) >= 0){
-                            multiply = multiply.subtract(remainingAmount);
+                        if(multiply1.compareTo(remainingAmount) >= 0){
+                            userRedPacketRecord.setRemainingAmount(0D);
+                            userRedPacketRecord.setEndTime(new Date());
+                            userRedPacketRecord.setState(2);
+                            multiply1 = multiply1.subtract(remainingAmount).setScale(2, RoundingMode.HALF_EVEN);
                             jsonObject.put("money", remainingAmount);
                             jsonArray.add(jsonObject);
+                            userRedPacketRecordService.updateById(userRedPacketRecord);
                         }else{
-                            userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).doubleValue());
-                            jsonObject.put("money", multiply);
+                            userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply1).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
+                            jsonObject.put("money", multiply1);
                             jsonArray.add(jsonObject);
+                            userRedPacketRecordService.updateById(userRedPacketRecord);
                             break;
                         }
                     }
@@ -936,13 +1083,18 @@
                         jsonObject.put("id", userRedPacketRecord.getId());
                         BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount());
                         if(multiply.compareTo(remainingAmount) >= 0){
-                            multiply = multiply.subtract(remainingAmount);
+                            userRedPacketRecord.setRemainingAmount(0D);
+                            userRedPacketRecord.setEndTime(new Date());
+                            userRedPacketRecord.setState(2);
+                            multiply = multiply.subtract(remainingAmount).setScale(2, RoundingMode.HALF_EVEN);
                             jsonObject.put("money", remainingAmount);
                             jsonArray.add(jsonObject);
+                            userRedPacketRecordService.updateById(userRedPacketRecord);
                         }else{
-                            userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).doubleValue());
+                            userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
                             jsonObject.put("money", multiply);
                             jsonArray.add(jsonObject);
+                            userRedPacketRecordService.updateById(userRedPacketRecord);
                             break;
                         }
                     }
@@ -1021,21 +1173,6 @@
                 userCouponRecord.setEndTime(new Date());
                 userCouponRecordService.updateById(userCouponRecord);
             }
-            if(null != orderLogistics.getRedPacketId()){
-                JSONArray jsonArray = JSON.parseArray(orderLogistics.getRedPacketId());
-                for (int i = 0; i < jsonArray.size(); i++) {
-                    JSONObject jsonObject = jsonArray.getJSONObject(i);
-                    Integer id1 = jsonObject.getInteger("id");
-                    Double money = jsonObject.getDouble("money");
-                    UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1);
-                    userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money);
-                    if(0 == userRedPacketRecord.getRemainingAmount()){
-                        userRedPacketRecord.setState(2);
-                        userRedPacketRecord.setEndTime(new Date());
-                    }
-                    userRedPacketRecordService.updateById(userRedPacketRecord);
-                }
-            }
 
             //添加交易明细
             transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId);
@@ -1044,7 +1181,6 @@
             orderLogistics.setState(8);
             orderLogistics.setPayType(3);
             orderLogistics.setPayMoney(orderMoney);
-            orderLogistics.setOrderMoney(orderLogistics.getOrderMoney()+orderLogistics.getFreeMoney().doubleValue());
     
             //处理优惠券和红包
             if(null != userCouponRecord){
@@ -1096,7 +1232,8 @@
             new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                 }
             }).start();
 
@@ -1392,11 +1529,10 @@
             transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId);
             userInfoService.updateById(userInfo);
 
-            orderLogistics.setState(1);//小件物流先支付后司机抢单
+            orderLogistics.setState(8);//小件物流先支付后司机抢单
             orderLogistics.setDriverPay(1);
             orderLogistics.setPayType(4);
             orderLogistics.setPayMoney(orderMoney);
-            orderLogistics.setOrderMoney(orderLogistics.getOrderMoney()+orderLogistics.getFreeMoney().doubleValue());
     
             //处理优惠券和红包
             if(null != userCouponRecord){
@@ -1412,19 +1548,6 @@
                 driverService.updateById(driver);
             }
             if(null != orderLogistics.getRedPacketId()){
-                JSONArray jsonArray = JSON.parseArray(orderLogistics.getRedPacketId());
-                for (int i = 0; i < jsonArray.size(); i++) {
-                    JSONObject jsonObject = jsonArray.getJSONObject(i);
-                    Integer id1 = jsonObject.getInteger("id");
-                    Double money = jsonObject.getDouble("money");
-                    UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1);
-                    userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money);
-                    if(0 == userRedPacketRecord.getRemainingAmount()){
-                        userRedPacketRecord.setState(2);
-                        userRedPacketRecord.setEndTime(new Date());
-                    }
-                    userRedPacketRecordService.updateById(userRedPacketRecord);
-                }
                 Double money = orderLogistics.getRedPacketMoney();
                 incomeService.saveData(2, orderLogistics.getDriverId(), 7, orderLogistics.getId(), 4, money);
                 driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
@@ -1522,7 +1645,8 @@
             new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                     pushUtil.pushOfflinePayment(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4);
                 }
             }).start();
@@ -1919,8 +2043,8 @@
             new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
-                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                 }
             }).start();
 
@@ -1977,8 +2101,8 @@
             new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
-                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                 }
             }).start();
 
@@ -2018,21 +2142,6 @@
                 userCouponRecord.setEndTime(new Date());
                 userCouponRecordService.updateById(userCouponRecord);
             }
-            if(null != orderLogistics.getRedPacketId()){
-                JSONArray jsonArray = JSON.parseArray(orderLogistics.getRedPacketId());
-                for (int i = 0; i < jsonArray.size(); i++) {
-                    JSONObject jsonObject = jsonArray.getJSONObject(i);
-                    Integer id1 = jsonObject.getInteger("id");
-                    Double money = jsonObject.getDouble("money");
-                    UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1);
-                    userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money);
-                    if(0 == userRedPacketRecord.getRemainingAmount()){
-                        userRedPacketRecord.setState(2);
-                        userRedPacketRecord.setEndTime(new Date());
-                    }
-                    userRedPacketRecordService.updateById(userRedPacketRecord);
-                }
-            }
 
             query.setState(2);
             query.setCode(order_id);
@@ -2042,7 +2151,8 @@
             new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                 }
             }).start();
 
@@ -2395,8 +2505,8 @@
             new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
-                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                 }
             }).start();
 
@@ -2453,10 +2563,34 @@
                 map.put("receipt", "");
             }
             if(state == 7){
-                Double discountMoney = Double.valueOf(map.get("discountMoney").toString());
+                Double discountMoney = 0D;
+                OrderLogistics orderLogistics = this.selectById(orderId);
+                UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(Integer.valueOf(String.valueOf(map.get("companyId"))));
+                if(null != query2){
+                    Integer orderNum=this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId",orderLogistics.getUserId()).eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())"));
+                    if(query2.getDistance()*1000>orderLogistics.getMileage() && query2.getOrderNum()>orderNum){
+                        Double special = query2.getLogistics();
+                        Double orderMoney = orderLogistics.getOrderMoney();
+                        double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+                        if(orderMoney.compareTo(v) > 0){
+                            discountMoney = orderMoney - v;
+                        }
+                    }
+        
+                }
                 Double orderMoney = Double.valueOf(map.get("orderMoney").toString());
                 map.put("orderMoney", orderMoney - discountMoney);
             }
+    
+            OrderLogistics orderLogistics = this.selectById(orderId);
+            long timeOutCancel = 0L;
+            if(null != orderLogistics.getEstimateArriveTime()){
+                CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", orderLogistics.getCompanyId()));
+                JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent());
+                int driverTimeout = jsonObject.getIntValue("driverTimeout") * 60000;
+                timeOutCancel = orderLogistics.getEstimateArriveTime().getTime() + driverTimeout;
+            }
+            map.put("timeOutCancel", timeOutCancel);
         }
         return maps;
     }
@@ -2554,22 +2688,38 @@
                 integer = orderCancelService.saveData(id, 4, reason, remark, null, amount, 1, 1, uid);
             }
             this.deleteTask(id);//删除定时任务
-        
+    
+    
+            //修改司机为空闲
+            Driver driver = driverService.selectById(orderLogistics.getDriverId());
             new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0);
+                    Integer language1 = driver.getLanguage();
+                    String audioUrl = "";
+                    switch (language1){
+                        case 1:
+                            audioUrl = "http://182.160.16.251:81/files/audio/UserCancelledOrder-CN.mp3";
+                            break;
+                        case 2:
+                            audioUrl = "http://182.160.16.251:81/files/audio/UserCancelledOrder-EN.mp3";
+                            break;
+                        case 3:
+                            audioUrl = "http://182.160.16.251:81/files/audio/UserCancelledOrder-FR.mp3";
+                            break;
+                    }
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0, "");
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState() == 12 ? orderLogistics.getState() : 10, 0, audioUrl);
                 }
             }).start();
-        
-            //修改司机为空闲
-            Driver driver = driverService.selectById(orderLogistics.getDriverId());
             driver.setState(2);
             driverService.updateById(driver);
         }
         
-        //修改行程信息
-        fleetEngineUtil.updateTrip("CANCELED", null, null, orderLogistics.getTripId(), null, null, null, null);
+        if(orderLogistics.getState() == 10 || orderLogistics.getState() == 12){
+            //修改行程信息
+            fleetEngineUtil.updateTrip("CANCELED", null, null, orderLogistics.getTripId(), null, null, null, null);
+        }
         
         //添加消息
         systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功取消包裹订单,谢谢使用!" : language == 2 ? "You've cancelled the delivery order successfully, thank you for using I-GO "
@@ -2671,7 +2821,7 @@
             if(null != query2){
                 Integer orderNum=this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId",orderLogistics.getUserId()).eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())"));
                 if(query2.getDistance()*1000>orderLogistics.getMileage() && query2.getOrderNum()>orderNum){
-                    Double special = query2.getSpecial();
+                    Double special = query2.getLogistics();
                     orderLogistics.setDiscount(special);
                     Double orderMoney = orderLogistics.getOrderMoney();
                     double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
@@ -2682,15 +2832,17 @@
             
             }
         }
-        Map<String, String> geocode = gdMapGeocodingUtil.geocode(map.get("startLon").toString(), map.get("startLat").toString());
-        map.put("startCity", geocode.get("city"));
-        geocode = gdMapGeocodingUtil.geocode(map.get("endLon").toString(), map.get("endLat").toString());
-        map.put("endCity", geocode.get("city"));
+//        Map<String, String> geocode = gdMapGeocodingUtil.geocode(map.get("startLon").toString(), map.get("startLat").toString());
+//        map.put("startCity", geocode.get("city"));
+//        geocode = gdMapGeocodingUtil.geocode(map.get("endLon").toString(), map.get("endLat").toString());
+//        map.put("endCity", geocode.get("city"));
+//        GoogleMapUtil.getReverseGeocode()
+        
 
         String driverId = redisUtil.getValue("DEVICE_" + map.get("driverId"));
         map.put("device", ToolUtil.isNotEmpty(driverId) ? 2 : 1);
         map.put("orderType", orderLogistics.getType());
-        if(state == 6){
+        if(state == 8){
             map.put("receipt", "http://182.160.16.251:81/files/html/parcel_receipt_" + orderId + ".html");
         }else{
             map.put("receipt", "");
@@ -2699,9 +2851,14 @@
         if(null != map.get("driverId")){
             companyId = Integer.valueOf(String.valueOf(map.get("companyId")));
         }
-        CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", companyId));
-        JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent());
-        map.put("timeOutCancel", jsonObject.getIntValue("driverTimeout"));
+        map.put("timeOutCancel", 0);
+        if(null != orderLogistics.getEstimateArriveTime()){
+            CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", companyId));
+            JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent());
+            int driverTimeout = jsonObject.getIntValue("driverTimeout");
+            long timeOutCancel = orderLogistics.getEstimateArriveTime().getTime() + driverTimeout;
+            map.put("timeOutCancel", timeOutCancel);
+        }
         return map;
     }
 
@@ -2714,8 +2871,19 @@
     @Override
     public List<Map<String, Object>> queryCoupon(Integer language, Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception {
         OrderLogistics orderLogistics = this.selectById(orderId);
-        List<Map<String, Object>> list = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 4, orderLogistics.getOrderMoney() -  orderLogistics.getDiscountMoney(), pageNum, size);
-        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 0, orderLogistics.getOrderMoney() -  orderLogistics.getDiscountMoney(), pageNum, size);
+        UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderLogistics.getCompanyId());
+        double v = orderLogistics.getOrderMoney();
+        if(null != query2){
+            Integer orderNum=this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId",orderLogistics.getUserId()).eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())"));
+            if(query2.getDistance()*1000>orderLogistics.getMileage() && query2.getOrderNum()>orderNum){
+                Double special = query2.getLogistics();
+                orderLogistics.setDiscount(special);
+                Double orderMoney = orderLogistics.getOrderMoney();
+                v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            }
+        }
+        List<Map<String, Object>> list = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 4, v, pageNum, size);
+        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 0, v, pageNum, size);
         list.addAll(list1);
         return list;
     }
@@ -2745,25 +2913,26 @@
         JSONObject object = JSON.parseObject(query.getContent());
         long t = object.getInteger("driverTimeout") * 60000L;
         //司机超时未到达起点,免费取消
-        if(orderLogistics.getState() < 3 && orderLogistics.getSnatchOrderTime().getTime() + t < System.currentTimeMillis()){
+        if(orderLogistics.getState() <= 3 && orderLogistics.getEstimateArriveTime().getTime() + t <= System.currentTimeMillis()){
             baseWarpper.setAmount(amount);
             return ResultUtil.success(baseWarpper);
         }
         
-        JSONObject order = object.getJSONObject("order");
-        long m = order.getInteger("orderAcceptanceTime") * 60000L;
-        //超过免费时间,计算费用
-        if(orderLogistics.getSnatchOrderTime().getTime() + m < System.currentTimeMillis()){
-            BigDecimal money = order.getBigDecimal("money");
-            if(null != orderLogistics.getSetOutTime()){
+        //非服务中且未超时
+        if(orderLogistics.getState() != 5){
+            JSONObject order = object.getJSONObject("order");
+            long m = order.getInteger("orderAcceptanceTime") * 60000L;
+            //超过免费时间,且没有超时,计算费用
+            if(orderLogistics.getSnatchOrderTime().getTime() + m < System.currentTimeMillis() && orderLogistics.getEstimateArriveTime().getTime() + t > System.currentTimeMillis()){
+                BigDecimal money = order.getBigDecimal("money");
                 //里程费
-                BigDecimal mileageFee = order.getBigDecimal("mileageFee").multiply(new BigDecimal(orderLogistics.getMileage() / 1000));
+                BigDecimal mileageFee = order.getBigDecimal("mileageFee").multiply(new BigDecimal(orderLogistics.getToStartPointMileage() / 1000));
                 //时长费
-                int s = Double.valueOf((System.currentTimeMillis() - orderLogistics.getSetOutTime().getTime()) / 60000).intValue();
+                int s = Double.valueOf((System.currentTimeMillis() - orderLogistics.getSnatchOrderTime().getTime()) / 60000).intValue();
                 BigDecimal durationFee = order.getBigDecimal("durationFee").multiply(new BigDecimal(s));
                 money = money.add(durationFee).add(mileageFee);
+                amount = money.setScale(2, RoundingMode.HALF_EVEN).doubleValue();
             }
-            amount = money.setScale(2, RoundingMode.HALF_EVEN).doubleValue();
         }
         baseWarpper.setAmount(amount);
         return ResultUtil.success(baseWarpper);
@@ -2901,18 +3070,35 @@
                 orderCancelService.updateById(orderCancel);
 
                 if(null != orderLogistics.getDriverId()){
-                    BigDecimal c =new BigDecimal(amount);//司机收入
-                    incomeService.saveData(2, orderLogistics.getDriverId(), 3, orderLogistics.getId(), 4, c.doubleValue());
-                    Driver driver = driverService.selectById(orderLogistics.getDriverId());
-                    driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-                    driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-                    driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-                    driverService.updateById(driver);
+                    //添加已收入明细
+                    Company company = companyService.selectById(orderLogistics.getCompanyId());
+                    Double speMoney = company.getSameLogisticsMoney();
+                    BigDecimal d = null;//企业收入
+                    BigDecimal c = null;//司机收入
+                    if(company.getIsSpeFixedOrProportional() == 2){//固定
+                        d = new BigDecimal(speMoney);
+                        c = new BigDecimal(amount).subtract(d);//只有出行金额参与抽成,其余归属司机
+                    }
+                    if(company.getIsSpeFixedOrProportional() == 1){//比例
+                        d = new BigDecimal(amount).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN)));
+                        c = new BigDecimal(amount).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                    }
+                    incomeService.saveData(1, orderLogistics.getCompanyId(), 3, orderLogistics.getId(), 4, d.doubleValue());
+                    if(c.doubleValue() > 0){
+                        incomeService.saveData(2, orderLogistics.getDriverId(), 3, orderLogistics.getId(), 4, c.doubleValue());
+                        Driver driver = driverService.selectById(orderLogistics.getDriverId());
+                        driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+                        driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+                        driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+                        driverService.updateById(driver);
+                    }
     
                     this.deleteTask(id);//删除定时任务
-                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0);
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0, "");
+                }else{
+                    incomeService.saveData(1, orderLogistics.getCompanyId(), 3, orderLogistics.getId(), 4, amount.doubleValue());
                 }
-                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0);
+                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0, "");
     
     
                 //添加消息
@@ -2962,21 +3148,38 @@
                 query1.setState(2);
                 orderCancelService.updateById(query1);
             }
-            
-            
+    
+            Double amount = query.getAmount();
             if(null != orderLogistics.getDriverId()){
-                BigDecimal c =new BigDecimal(query.getAmount());//司机收入
-                incomeService.saveData(2, orderLogistics.getDriverId(), 3, orderLogistics.getId(), 4, c.doubleValue());
-                Driver driver = driverService.selectById(orderLogistics.getDriverId());
-                driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-                driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-                driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-                driverService.updateById(driver);
+                //添加已收入明细
+                Company company = companyService.selectById(orderLogistics.getCompanyId());
+                Double speMoney = company.getSameLogisticsMoney();
+                BigDecimal d = null;//企业收入
+                BigDecimal c = null;//司机收入
+                if(company.getIsSpeFixedOrProportional() == 2){//固定
+                    d = new BigDecimal(speMoney);
+                    c = new BigDecimal(amount).subtract(d);//只有出行金额参与抽成,其余归属司机
+                }
+                if(company.getIsSpeFixedOrProportional() == 1){//比例
+                    d = new BigDecimal(amount).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN)));
+                    c = new BigDecimal(amount).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                }
+                incomeService.saveData(1, orderLogistics.getCompanyId(), 3, orderLogistics.getId(), 4, d.doubleValue());
+                if(c.doubleValue() > 0){
+                    incomeService.saveData(2, orderLogistics.getDriverId(), 3, orderLogistics.getId(), 4, c.doubleValue());
+                    Driver driver = driverService.selectById(orderLogistics.getDriverId());
+                    driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+                    driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+                    driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+                    driverService.updateById(driver);
+                }
                 this.deleteTask(orderLogistics.getId());//删除定时任务
                 
-                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0);
+                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0, "");
+            }else{
+                incomeService.saveData(1, orderLogistics.getCompanyId(), 3, orderLogistics.getId(), 4, amount.doubleValue());
             }
-            pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0);
+            pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0, "");
             
             //添加消息
             systemNoticeService.addSystemNotice(1, language == 1 ? "您已使用余额成功支付取消订单费用,谢谢使用!" : language == 2
@@ -3003,7 +3206,22 @@
             orderLogistics.setDestinationLat(endLat);
             orderLogistics.setDestinationLon(endLon);
             this.updateById(orderLogistics);
-            pushUtil.pushModifyAddress(2, orderLogistics.getDriverId(), orderId, 1, 1);
+            
+            Driver driver = driverService.selectById(orderLogistics.getDriverId());
+            Integer language1 = driver.getLanguage();
+            String audioUrl = "";
+            switch (language1){
+                case 1:
+                    audioUrl = "http://182.160.16.251:81/files/audio/ChangeAddress-CN.mp3";
+                    break;
+                case 2:
+                    audioUrl = "http://182.160.16.251:81/files/audio/ChangeAddress-EN.mp3";
+                    break;
+                case 3:
+                    audioUrl = "http://182.160.16.251:81/files/audio/ChangeAddress-FR.mp3";
+                    break;
+            }
+            pushUtil.pushModifyAddress(2, orderLogistics.getDriverId(), orderId, 4, 1, audioUrl);
         }else{
             orderLogistics.setEndAddress(endAddress);
             orderLogistics.setEndLat(Double.valueOf(endLat));
@@ -3045,9 +3263,6 @@
             UserRedPacketRecord userRedPacketRecord = new UserRedPacketRecord();
             userRedPacketRecord.setMoney(money);
             userRedPacketRecord.setRemainingAmount(money);
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTime(new Date());
-            calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + Integer.valueOf(String.valueOf(query.get("effective"))));
             userRedPacketRecord.setInsertTime(new Date());
             userRedPacketRecord.setCompanyId(Integer.valueOf(String.valueOf(query.get("companyId"))));
             userRedPacketRecord.setState(0);
@@ -3180,4 +3395,139 @@
         }
         return list;
     }
+    
+    
+    /**
+     * 获取服务中的订单数据
+     * @param uid
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public OrderServerWarpper queryOrderServer(Integer orderId, Integer uid) throws Exception {
+        OrderLogistics orderLogistics = this.selectById(orderId);
+        //计算预计距离和剩余时间
+        String value = redisUtil.getValue("DRIVER" + orderLogistics.getDriverId());
+        String d = "0";
+        String t = "0";
+        if(null == value || "".equals(value)){
+            System.err.println("司机没有上传位置信息");
+            
+            //调用获取轨迹中的数据
+            File file = new File(filePath + orderId + "_4.txt");
+            if(file.exists()){
+                //读取文件(字符流)
+                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
+                //循环取出数据
+                String str = null;
+                StringBuffer sb = new StringBuffer();
+                while ((str = in.readLine()) != null) {
+                    sb.append(str);
+                }
+                List<OrderPosition> list = JSONArray.parseArray(sb.toString(), OrderPosition.class);
+                if(list.size() > 0){
+                    OrderPosition orderPosition = list.get(list.size() - 1);
+                    value = orderPosition.getLon() + "," + orderPosition.getLat();
+                }
+            }
+        }
+        
+        String lnt = "0";
+        String lat = "0";
+        if(ToolUtil.isNotEmpty(value)){
+            lnt = value.split(",")[0];
+            lat = value.split(",")[1];
+            DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), Double.valueOf(lat), Double.valueOf(lnt));
+            
+            if(null == distancematrix){
+                System.err.println("查询距离出错了");
+            }else if(distancematrix.getDistance() == 0){
+                System.err.println("未获取到有效的距离");
+            }else{
+                d = new BigDecimal(distancematrix.getDistance()).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString();
+                t = new BigDecimal(distancematrix.getDuration()).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + "";
+            }
+        }
+        
+        OrderServerWarpper orderServerWarpper = new OrderServerWarpper();
+        orderServerWarpper.setOrderId(orderLogistics.getId());
+        orderServerWarpper.setOrderType(4);
+        orderServerWarpper.setState(orderLogistics.getState());
+        orderServerWarpper.setLon(lnt);
+        orderServerWarpper.setLat(lat);
+        orderServerWarpper.setReassignNotice(orderLogistics.getReassignNotice());
+        if(orderLogistics.getState() == 2 || orderLogistics.getState() == 3){//前往预约地
+            orderServerWarpper.setReservationMileage(d);
+            orderServerWarpper.setReservationTime(t);
+            orderServerWarpper.setServedMileage("0");
+            orderServerWarpper.setServedTime("0");
+            orderServerWarpper.setLaveMileage("0");
+            orderServerWarpper.setLaveTime("0");
+        }
+        if(orderLogistics.getState() == 5 || orderLogistics.getState() == 6){//服务中
+            DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(lat), Double.valueOf(lnt), orderLogistics.getEndLat(), orderLogistics.getEndLon());
+            if(null == distancematrix){
+                System.err.println("查询距离出错了");
+            }else if(distancematrix.getDistance() == 0){
+                System.err.println("未获取到有效的距离");
+            }else{
+                d = new BigDecimal(distancematrix.getDistance()).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString();
+                t = new BigDecimal(distancematrix.getDuration()).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + "";
+            }
+            orderServerWarpper.setReservationMileage("0");
+            orderServerWarpper.setReservationTime("0");
+            orderServerWarpper.setServedMileage(String.valueOf((null == orderLogistics.getMileage() ? 0 : orderLogistics.getMileage()) / 1000));
+            orderServerWarpper.setServedTime("0");
+            if(null != orderLogistics.getStartServiceTime()){
+                orderServerWarpper.setServedTime(Long.valueOf((new Date().getTime() - orderLogistics.getStartServiceTime().getTime()) / 60000).intValue() + "");
+            }
+            orderServerWarpper.setLaveMileage(d);
+            orderServerWarpper.setLaveTime(t);
+        }
+        File file = new File(filePath + orderId + "_4.txt");
+        if(file.exists()){
+            //读取文件(字符流)
+            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
+            //循环取出数据
+            String str = null;
+            StringBuffer sb = new StringBuffer();
+            while ((str = in.readLine()) != null) {
+                sb.append(str);
+            }
+            List<OrderPosition> list = JSONArray.parseArray(sb.toString(), OrderPosition.class);
+            orderServerWarpper.setOrderPositionList(JSONObject.toJSONString(list));
+        }
+        return orderServerWarpper;
+    }
+    
+    
+    /**
+     * 获取下单推送完后没有司机接单的提醒
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public EndPushWarpper queryEndPush(Integer uid) throws Exception {
+        List<OrderLogistics> list = orderLogisticsMapper.queryByState(uid, null, null, 1);
+        EndPushWarpper endPushWarpper = new EndPushWarpper();
+        if(list.size() > 0){
+            OrderLogistics orderPrivateCar = list.get(0);
+            if(!orderIds.contains(orderPrivateCar.getId())){
+                endPushWarpper.setOrderId(orderPrivateCar.getId());
+                endPushWarpper.setOrderType(4);
+                endPushWarpper.setState(1);
+                List<PushOrder> querys = pushOrderService.querys(null, 2, orderPrivateCar.getCompanyId());//获取需要推送的次数
+                int time = 0;
+                for(int i = 1; i <= querys.size(); i++){
+                    PushOrder pushOrder = pushOrderService.querys(i, 2, orderPrivateCar.getCompanyId()).get(0);
+                    time += pushOrder.getPushTime() * 1000;
+                }
+                //当前时间减去推单总时间大于下单时间
+                if((System.currentTimeMillis() - time) > orderPrivateCar.getInsertTime().getTime()){
+                    endPushWarpper.setState(2);
+                }
+            }
+        }
+        return endPushWarpper;
+    }
 }

--
Gitblit v1.7.1