From 8c1cf98149c48f3ccc6db8574d6bdb76ff541772 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 04 七月 2025 15:25:24 +0800
Subject: [PATCH] bug修改

---
 DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java |  217 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 163 insertions(+), 54 deletions(-)

diff --git a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
index 3de1ab6..7d0ed6a 100644
--- a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
+++ b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
@@ -34,6 +34,8 @@
 
     @Autowired
     private IDriverService driverService;
+    @Autowired
+    private ICompanyService companyService;
 
     @Autowired
     private IUserRedPacketRecordService userRedPacketRecordService;
@@ -44,7 +46,8 @@
 
     @Autowired
     private GDMapElectricFenceUtil gdMapElectricFenceUtil;
-
+    @Autowired
+    private ITransactionDetailsService transactionDetailsService;
     @Autowired
     private GDFalconUtil gdFalconUtil;
 
@@ -75,6 +78,12 @@
     @Resource
     private UserInfoMapper userInfoMapper;
 
+    @Resource
+    private TUseMoneyMapper useMoneyMapper;
+
+
+    @Autowired
+    private TransactionDetailsMapper transactionDetailsMapper;
 
 
 
@@ -196,17 +205,33 @@
 //        String track = gdFalconUtil.createTrack(s);
 //        orderTaxi.setTrackId(track);
         if (orderTaxi.getAudioLinkUrl()!=null){
-            List<TUseMoney> money = useMoneyMapper.selectList(null);
+//            List<TUseMoney> money = useMoneyMapper.selectList(null);
+            Company company = companyService.selectById(driver.getCompanyId());
             orderTaxi.setState(9);
             driver.setState(2);
-            driver.setBalance(driver.getBalance() - money.get(0).getMoney());
+//            driver.setBalance(driver.getBalance() - company.getFixedDeduction());
+
+            if(Objects.isNull(company)){
+                company = companyService.selectById(driver.getCompanyId());
+            }
+            // 平台收入
+            double money;
+            if(orderTaxi.getOrderSource() == 2 || orderTaxi.getOrderSource() == 3){
+                double v = company.getPercentageDeduction() / 100;
+                money = v * orderTaxi.getOrderMoney();
+            }else {
+                money = company.getFixedDeduction();
+            }
+            driver.setBalance(driver.getBalance() - money);
+            // 新增扣除使用费记录
+            transactionDetailsService.saveData(driver.getId(), "软件使用费", money, 2, 1, 2, 6, orderTaxi.getId(),company.getId());
 
             driverService.updateById(driver);
             Car car = carService.selectById(driver.getCarId());
 //            String s = MsgUtil.SendDriverPost(orderTaxi.getPassengersPhone(), car.getCarLicensePlate(),driver.getName(), driver.getPhone());
-            String s = aLiSendSms.sendSms(orderTaxi.getPassengersPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" +car.getCarLicensePlate() + "\"}");
-            System.err.println("====电话回调==="+s);
-
+//            String s = aLiSendSms.sendSms(orderTaxi.getPassengersPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" +car.getCarLicensePlate() + "\"}");
+//            System.err.println("====电话回调==="+s);
+            SMSUtil.send(orderTaxi.getPassengersPhone(), "您的订单已被司机" + driver.getName() + "接单,联系电话" + driver.getPhone() + "车牌号" + car.getCarLicensePlate() + "请耐心等待。", "2431012312845");
         }
 
         //调用移动的小号接口
@@ -279,7 +304,9 @@
         //发送短信
         try{
             UserInfo userInfo = userInfoMapper.selectById(orderTaxi.getUserId());
-            String sData = aLiSendSms.sendSms(userInfo.getPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" +carService.selectById(orderTaxi.getCarId()) .getCarLicensePlate() + "\"}");
+            Car car = carService.selectById(orderTaxi.getCarId());
+//            String sData = aLiSendSms.sendSms(userInfo.getPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" + car.getCarLicensePlate() + "\"}");
+            SMSUtil.send(userInfo.getPhone(), "您的订单已被司机" + driver.getName() + "接单,联系电话" + driver.getPhone() + "车牌号" + car.getCarLicensePlate() + "请耐心等待。", "2431012312845");
 
         }catch (Exception e){
 
@@ -370,7 +397,9 @@
 //发送短信
         try{
             UserInfo userInfo = userInfoMapper.selectById(orderTaxi.getUserId());
-            String sData = aLiSendSms.sendSms(userInfo.getPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" +carService.selectById(orderTaxi.getCarId()) .getCarLicensePlate() + "\"}");
+            Car car = carService.selectById(orderTaxi.getCarId());
+//            String sData = aLiSendSms.sendSms(userInfo.getPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" + car.getCarLicensePlate() + "\"}");
+            SMSUtil.send(userInfo.getPhone(), "您的订单已被司机" + driver.getName() + "接单,联系电话" + driver.getPhone() + "车牌号" + car.getCarLicensePlate() + "请耐心等待。", "2431012312845");
 
         }catch (Exception e){
 
@@ -393,13 +422,6 @@
     public Map<String, Object> queryOrderInfo(Integer orderId) throws Exception {
         return orderTaxiMapper.queryOrderInfo(orderId);
     }
-
-    @Resource
-    private TUseMoneyMapper useMoneyMapper;
-
-
-    @Autowired
-    private TransactionDetailsMapper transactionDetailsMapper;
     /**
      * 走订单流程操作
      * @param orderId
@@ -436,25 +458,13 @@
                 orderTaxi.setGetoffLat(lat);
                 orderTaxi.setGetoffAddress(address);
                 orderTaxi.setGetoffTime(new Date());
-                orderTaxi.setState(6);
                 orderTaxi.setEndServiceTime(new Date());
-
-                List<TUseMoney> money = useMoneyMapper.selectList(null);
+                orderTaxi.setState(6);
+                //回滚司机状态为空闲
                 Driver driver = driverService.selectById(orderTaxi.getDriverId());
-                driver.setBalance(driver.getBalance() - money.get(0).getMoney());
-                // 新增扣除使用费记录
-                TransactionDetails transactionDetails = new TransactionDetails();
-                transactionDetails.setUserId(driver.getId());
-                transactionDetails.setInsertTime(new Date());
-                transactionDetails.setRemark("软件使用费");
-                transactionDetails.setMoney(money.get(0).getMoney());
-                transactionDetails.setState(2);
-                transactionDetails.setType(1);
-                transactionDetails.setUserType(2);
-                transactionDetails.setOrderType(6);
-                transactionDetails.setOrderId(orderTaxi.getId());
-                transactionDetailsMapper.insert(transactionDetails);
+                driver.setState(2);
                 driverService.updateById(driver);
+                
                 pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据
                 systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId());
                 break;
@@ -462,11 +472,12 @@
         this.updateById(orderTaxi);
 
         // TODO: 2020/6/5 推送状态
+        OrderTaxi finalOrderTaxi = orderTaxi;
         new Thread(new Runnable() {
             @Override
             public void run() {
-                pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState());
-                pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState());
+                pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
+                pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
             }
         }).start();
         return ResultUtil.success();
@@ -486,20 +497,72 @@
     @Override
     public ResultUtil confirmFees(Integer orderId, Integer type, Double travelFee, Double parkingFee, Double crossingFee) throws Exception {
         OrderTaxi orderTaxi = this.selectById(orderId);
-        orderTaxi.setPayManner(type);
-        if(type == 2){//其他支付,不需要操作,直接完成订单
-            orderTaxi = this.setMoney1(orderTaxi, travelFee, parkingFee, crossingFee);
-            orderTaxi.setState(8);
-        }else{
+        if(2 == type && orderTaxi.getPayManner()==3){
+            orderTaxi.setState(9);
+            Driver driver = driverService.selectById(orderTaxi.getDriverId());
+        
+            Company company = companyService.selectById(driver.getFranchiseeId());
+            if(Objects.isNull(company)){
+                company = companyService.selectById(driver.getCompanyId());
+            }
+            TransactionDetails transactionDetails = new TransactionDetails();
+            driver.setBalance(driver.getBalance() - company.getFixedDeduction());
+            transactionDetails.setMoney(company.getFixedDeduction());
+            // 新增扣除使用费记录
+            transactionDetails.setUserId(driver.getId());
+            transactionDetails.setInsertTime(new Date());
+            transactionDetails.setRemark("软件使用费");
+            transactionDetails.setState(2);
+            transactionDetails.setType(1);
+            transactionDetails.setUserType(2);
+            transactionDetails.setOrderType(6);
+            transactionDetails.setOrderId(orderTaxi.getId());
+            transactionDetailsMapper.insert(transactionDetails);
+            driverService.updateById(driver);
+        }
+        //打表计费,直接订单完成支付,
+        if(2 == type && orderTaxi.getPayManner()==2){
             orderTaxi = this.setMoney2(orderTaxi, parkingFee, crossingFee);
+            //在线上计费的基础上随机加0.01-1的金额
+            Double orderMoney = orderTaxi.getOrderMoney() + (new BigDecimal(Math.random()).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
+            orderTaxi.setState(8);
+            orderTaxi.setOrderMoney(orderMoney);
+            orderTaxi.setPayMoney(orderMoney);
+            Driver driver = driverService.selectById(orderTaxi.getDriverId());
+        
+            Company company = companyService.selectById(driver.getFranchiseeId());
+            if(Objects.isNull(company)){
+                company = companyService.selectById(driver.getCompanyId());
+            }
+            TransactionDetails transactionDetails = new TransactionDetails();
+            Double meterPrintingFee = company.getMeterPrintingFee();
+            Double laveBusinessMoney = driver.getLaveBusinessMoney();
+            Double laveActivityMoney = driver.getLaveActivityMoney();
+            if(null != laveBusinessMoney && laveBusinessMoney.compareTo(meterPrintingFee) >= 0){
+                driver.setLaveBusinessMoney(new BigDecimal(laveBusinessMoney).subtract(new BigDecimal(meterPrintingFee)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+            }else if(null != laveActivityMoney && laveActivityMoney.compareTo(meterPrintingFee) >= 0){
+                driver.setLaveActivityMoney(new BigDecimal(laveActivityMoney).subtract(new BigDecimal(meterPrintingFee)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+            }
+            driver.setBalance(driver.getBalance() - meterPrintingFee);
+            transactionDetails.setMoney(meterPrintingFee);
+            // 新增扣除使用费记录
+            transactionDetails.setUserId(driver.getId());
+            transactionDetails.setInsertTime(new Date());
+            transactionDetails.setRemark("软件使用费");
+            transactionDetails.setState(2);
+            transactionDetails.setType(1);
+            transactionDetails.setUserType(2);
+            transactionDetails.setOrderType(6);
+            transactionDetails.setOrderId(orderTaxi.getId());
+            transactionDetailsMapper.insert(transactionDetails);
+            driverService.updateById(driver);
+        }
+        //线上计费,计算费用后修改为待支付
+        if(1 == type && orderTaxi.getPayManner()==1){
+            orderTaxi = this.setMoney2(orderTaxi, crossingFee, crossingFee);
             orderTaxi.setState(7);
         }
         this.updateById(orderTaxi);
-
-        //回滚司机状态为空闲
-        Driver driver = driverService.selectById(orderTaxi.getDriverId());
-        driver.setState(2);
-        driverService.updateById(driver);
 
         OrderTaxi finalOrderTaxi = orderTaxi;
         new Thread(new Runnable() {
@@ -712,6 +775,9 @@
             System.err.println("订单数据异常:" + orderId);
             return false;
         }
+        if(orderTaxi.getState() != 5){
+            return false;
+        }
         OrderPosition orderPosition = orderPositionService.queryNew(orderId, 2);
         String now = lon + "," + lat;
         String old = null;
@@ -759,6 +825,52 @@
     public List<OrderTaxi> taskMidAxbUnBindSend() throws Exception {
         return orderTaxiMapper.taskMidAxbUnBindSend();
     }
+
+    @Override
+    public Map<String, Object> queryMoneyInfo(Integer orderId) throws Exception {
+        OrderTaxi orderTaxi = this.selectById(orderId);
+        if(orderTaxi.getState() == 5 || orderTaxi.getState() == 6){//服务中的时候获取实时费用数据
+            if(orderTaxi.getPayManner() == 2){//其他支付,不需要操作,直接完成订单
+                orderTaxi = this.setMoney1(orderTaxi, 0D, 0D, 0D);
+            }else if(orderTaxi.getPayManner() == 1){
+                orderTaxi = this.setMoney2(orderTaxi, 0D, 0D);
+            }else {
+                // 无
+            }
+        }
+
+        // 查询平台服务费
+        TransactionDetails transactionDetails = transactionDetailsService.selectOne(new EntityWrapper<TransactionDetails>()
+                .eq("orderId", orderId)
+                .eq("orderType", 6)
+                .last("LIMIT 1"));
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("orderMoney", orderTaxi.getOrderMoney());//订单金额
+        map.put("startMileage", orderTaxi.getStartMileage());//起步价
+        map.put("startMoney", orderTaxi.getStartMoney());//起步价
+        map.put("mileageKilometers", orderTaxi.getMileageKilometers());//里程费
+        map.put("mileageMoney", orderTaxi.getMileageMoney());//里程费
+        map.put("duration", orderTaxi.getDuration());//时长费
+        map.put("durationMoney", orderTaxi.getDurationMoney());//时长费
+        map.put("wait", orderTaxi.getWait());//等待费
+        map.put("waitMoney", orderTaxi.getWaitMoney());//等待费
+        map.put("longDistance", orderTaxi.getLongDistance());//远途费
+        map.put("longDistanceMoney", orderTaxi.getLongDistanceMoney());//远途费
+        map.put("parkMoney", orderTaxi.getParkMoney());//停车费
+        map.put("roadTollMoney", orderTaxi.getRoadTollMoney());//过路费
+        map.put("redPacketMoney", orderTaxi.getRedPacketMoney());//红包抵扣金额
+        map.put("couponMoney", orderTaxi.getCouponMoney());//优惠券抵扣金额
+        map.put("discountMoney", orderTaxi.getDiscountMoney());//折扣抵扣金额
+        map.put("discount", orderTaxi.getDiscount());//折扣
+        if(Objects.isNull(transactionDetails)){
+            map.put("platformFee", 0);//折扣
+        }else {
+            map.put("platformFee", transactionDetails.getMoney());//折扣
+        }
+        return map;
+    }
+
     /**
      * 计算价格
      * @param orderTaxi
@@ -808,19 +920,16 @@
      * @throws Exception
      */
     public OrderTaxi setMoney2(OrderTaxi orderTaxi, Double parkingFee, Double crossingFee) throws Exception {
-        Map<String, Object> query1 = systemPriceMapper.query1(orderTaxi.getCompanyId(), 1);
+        Map<String, Object> query1 = systemPriceMapper.query1(orderTaxi.getCompanyId(), 2);
         //开始根据不同的方式计算金额
         double amount = 0;
         JSONObject jsonObject = JSON.parseObject(String.valueOf(query1.get("content")));
-
-        JSONObject contentExclusive = JSON.parseObject(query1.get("contentExclusive").toString());//独享
-        System.out.println("独享内容"+contentExclusive);
         //乘车类型(1=独享,2=一口价,3=拼车)
         double d = (null == orderTaxi.getMileage() ? 0D : orderTaxi.getMileage());
         System.out.println("行驶里程数"+d);
         //在价格区间按照一口价算,不在区间按实时价格算
         System.out.println("不在区间====================");
-        orderTaxi = calculationPrice(orderTaxi,contentExclusive,jsonObject.getLongValue("num1"),jsonObject.getDouble("num2"),parkingFee,crossingFee);
+        orderTaxi = calculationPrice(orderTaxi,jsonObject,jsonObject.getLongValue("num29"),jsonObject.getDouble("num30"),parkingFee,crossingFee);
         System.out.println("返回订单数据"+orderTaxi);
         return orderTaxi;
     }
@@ -880,8 +989,8 @@
 //            OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
             OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
             OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
-            OrderTaxi.setParkMoney(parkingFee);//停车费
-            OrderTaxi.setRoadTollMoney(crossingFee);//过路费
+            OrderTaxi.setParkMoney(Objects.isNull(parkingFee)?0D:parkingFee);//停车费
+            OrderTaxi.setRoadTollMoney(Objects.isNull(crossingFee)?0D:crossingFee);//过路费
             OrderTaxi.setRedPacketMoney(0D);//红包抵扣
             OrderTaxi.setCouponMoney(0D);//优惠券抵扣
             OrderTaxi.setDiscount(0D);//优惠抵扣
@@ -938,8 +1047,8 @@
 //                OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                 OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                 OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
-                OrderTaxi.setParkMoney(parkingFee);//停车费
-                OrderTaxi.setRoadTollMoney(crossingFee);//过路费
+                OrderTaxi.setParkMoney(Objects.isNull(parkingFee)?0D:parkingFee);//停车费
+                OrderTaxi.setRoadTollMoney(Objects.isNull(crossingFee)?0D:crossingFee);//过路费
                 OrderTaxi.setRedPacketMoney(0D);//红包抵扣
                 OrderTaxi.setCouponMoney(0D);//优惠券抵扣
                 OrderTaxi.setDiscount(0D);//优惠抵扣
@@ -982,8 +1091,8 @@
 //                OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                 OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                 OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
-                OrderTaxi.setParkMoney(parkingFee);//停车费
-                OrderTaxi.setRoadTollMoney(crossingFee);//过路费
+                OrderTaxi.setParkMoney(Objects.isNull(parkingFee)?0D:parkingFee);//停车费
+                OrderTaxi.setRoadTollMoney(Objects.isNull(crossingFee)?0D:crossingFee);//过路费
                 OrderTaxi.setRedPacketMoney(0D);//红包抵扣
                 OrderTaxi.setCouponMoney(0D);//优惠券抵扣
                 OrderTaxi.setDiscount(0D);//优惠抵扣

--
Gitblit v1.7.1