From f4e12a183070e9fc1db174dfb7f1c9a59f7763a1 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 17 四月 2025 09:08:23 +0800
Subject: [PATCH] 新增加功能

---
 UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java |  185 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 179 insertions(+), 6 deletions(-)

diff --git a/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java b/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
index 03da92f..ee538fd 100644
--- a/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
+++ b/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
@@ -29,6 +29,7 @@
 import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
 import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
 import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
+import com.stylefeng.guns.modular.taxi.warpper.ForecastPriceWarpper;
 import com.stylefeng.guns.modular.taxi.warpper.OrderTaxiWarpper;
 import org.bouncycastle.crypto.tls.MACAlgorithm;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -155,6 +156,9 @@
 
     @Autowired
     private IOrderPrivateCarService orderPrivateCarService;
+    
+    @Resource
+    private SystemPriceMapper systemPriceMapper;
 
     @Autowired
     private IOrderCrossCityService orderCrossCityService;
@@ -245,6 +249,13 @@
         UserInfo userInfo = userInfoService.selectById(uid);
         orderTaxi.setPassengersPhone(userInfo.getPhone());
         orderTaxi.setPassengers(userInfo.getNickName());
+        //获取费用金额
+        ForecastPriceWarpper warpper = new ForecastPriceWarpper();
+        warpper.setPayManner(orderTaxi.getPayManner());
+        warpper.setStartLat(orderTaxi.getStartLat());
+        warpper.setStartLon(orderTaxi.getStartLon());
+        warpper.setEndLat(orderTaxi.getEndLat());
+        warpper.setEndLon(orderTaxi.getEndLon());
 
         if (!StringUtils.hasLength(orderTaxi.getPassengers())  || StringUtils.hasLength(orderTaxi.getPassengersPhone()) ){
             // 如果没有填写乘车人电话或者姓名 那么用用户的
@@ -333,8 +344,152 @@
         baseWarpper.setId(orderTaxi.getId());
         return ResultUtil.success(baseWarpper);
     }
-
-
+    
+    
+    @Override
+    public ResultUtil<Double> getForecastPrice(ForecastPriceWarpper warpper) {
+        try {
+            Company query = companyCityService.query(String.valueOf(warpper.getStartLon()), String.valueOf(warpper.getStartLat()));//获取起点所属分公司
+            if(null == query){
+                return ResultUtil.error("获取企业失败");
+            }
+            Map<String, String> distance = gdMapElectricFenceUtil.getDistance(warpper.getStartLon() + "," + warpper.getStartLat(),
+                    warpper.getEndLon() + "," + warpper.getEndLat(), 1);
+            if(null == distance){
+                return ResultUtil.error("计算行驶距离失败");
+            }
+            double d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            double t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            double amount = setMoney2(query.getId(), d, t);
+            if(warpper.getPayManner() == 2){//其他支付,不需要操作,直接完成订单
+                amount = amount + (new BigDecimal(Math.random()).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+            }
+            return ResultUtil.success(amount);
+        }catch (Exception e){
+            e.printStackTrace();
+            return ResultUtil.runErr();
+        }
+    }
+    
+    
+    
+    /**
+     * 计算价格
+     * @return
+     * @throws Exception
+     */
+    public double setMoney2(Integer companyId, Double mileage, Double time) throws Exception {
+        Map<String, Object> query1 = systemPriceMapper.query1(companyId, 2);
+        //开始根据不同的方式计算金额
+        JSONObject jsonObject = JSON.parseObject(String.valueOf(query1.get("content")));
+        double amount = calculationPrice(jsonObject, mileage, time);
+        return amount;
+    }
+    
+    public double calculationPrice(JSONObject rule, double d, double t) throws Exception {
+        double amount = 0.0;
+        //等待费
+        Date date = new Date();
+        double d1 = (d - rule.getDouble("num2")) < 0 ? 0 : d - rule.getDouble("num2");//超出起步里程的公里
+        double t1 = (t - rule.getDouble("num3")) < 0 ? 0 : t - rule.getDouble("num3");//超过起步分钟数的时间
+        double yt1 = 0;//远途1段
+        double yt2 = 0;//远途2段
+        double yt3 = 0;//远途3段
+        
+        
+        //夜间服务处理逻辑
+        Calendar s = Calendar.getInstance();
+        s.setTime(date);
+        s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[0]));
+        s.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[1]));
+        
+        Calendar e = Calendar.getInstance();
+        e.setTime(date);
+        e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[0]));
+        e.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[1]));
+        
+        if(date.getTime() > s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){
+            if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){
+                yt1 = rule.getDouble("num18") * d;
+            }
+            if(d >  rule.getDouble("num9") && d < rule.getDouble("num10")){
+                yt1 = rule.getDouble("num18") * rule.getDouble("num7");
+                yt2 = rule.getDouble("num19") * (d - rule.getDouble("num9"));
+            }
+            if(d > rule.getDouble("num12")){
+                yt1 = rule.getDouble("num18") * rule.getDouble("num7");
+                yt2 = rule.getDouble("num19") * (rule.getDouble("num10") - rule.getDouble("num9"));
+                yt3 = rule.getDouble("num20") * (d - rule.getDouble("num12"));
+            }
+            Double startMoney = rule.getDouble("num15");//起步价
+            Double mileageMoney = (new BigDecimal(d1 * rule.getDouble("num16")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
+            Double durationMoney = (new BigDecimal(t1 * rule.getDouble("num17")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
+            Double longDistanceMoney = (new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
+            amount = startMoney + mileageMoney + durationMoney + longDistanceMoney;
+        }else{
+            Calendar s1 = Calendar.getInstance();
+            s1.setTime(date);
+            s1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[0]));
+            s1.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[1]));
+            
+            Calendar e1 = Calendar.getInstance();
+            e1.setTime(date);
+            e1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[0]));
+            e1.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[1]));
+            
+            Calendar s2 = Calendar.getInstance();
+            s2.setTime(date);
+            s2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[0]));
+            s2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[1]));
+            
+            Calendar e2 = Calendar.getInstance();
+            e2.setTime(date);
+            e2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[0]));
+            e2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[1]));
+            //高峰时段处理逻辑
+            if((date.getTime() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())){
+                if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){
+                    yt1 = rule.getDouble("num26") * d;
+                }
+                if(d >  rule.getDouble("num9") && d < rule.getDouble("num10")){
+                    yt1 = rule.getDouble("num26") * rule.getDouble("num7");
+                    yt2 = rule.getDouble("num27") * (d - rule.getDouble("num9"));
+                }
+                if(d > rule.getDouble("num12")){
+                    yt1 = rule.getDouble("num26") * rule.getDouble("num7");
+                    yt2 = rule.getDouble("num27") * (rule.getDouble("num10") - rule.getDouble("num9"));
+                    yt3 = rule.getDouble("num28") * (d - rule.getDouble("num12"));
+                }
+                Double startMoney = (rule.getDouble("num23"));//起步价
+                Double mileageMoney = (new BigDecimal(d1 * rule.getDouble("num24")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
+                Double durationMoney = (new BigDecimal(t1 * rule.getDouble("num25")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
+                Double longDistanceMoney = (new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
+                amount = startMoney + mileageMoney + durationMoney + longDistanceMoney;
+            }else{
+                //其他时间段的计算
+                if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){
+                    yt1 = rule.getDouble("num8") * d;
+                }
+                if(d >  rule.getDouble("num9") && d < rule.getDouble("num10")){
+                    yt1 = rule.getDouble("num8") * rule.getDouble("num7");
+                    yt2 = rule.getDouble("num11") * (d - rule.getDouble("num9"));
+                }
+                if(d > rule.getDouble("num12")){
+                    yt1 = rule.getDouble("num8") * rule.getDouble("num7");
+                    yt2 = rule.getDouble("num11") * (rule.getDouble("num10") - rule.getDouble("num9"));
+                    yt3 = rule.getDouble("num13") * (d - rule.getDouble("num12"));
+                }
+                Double startMoney = (rule.getDouble("num1"));//起步价
+                Double mileageMoney = (new BigDecimal(d1 * rule.getDouble("num4")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
+                Double durationMoney = (new BigDecimal(t1 * rule.getDouble("num5")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
+                Double longDistanceMoney = (new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
+                amount = startMoney + mileageMoney + durationMoney + longDistanceMoney;
+            }
+        }
+        return amount;
+    }
+    
+    
     /**
      * 继续执行推动等待操作
      * @param id
@@ -654,8 +809,8 @@
         UserInfo userInfo = userInfoService.selectById(uid);
         map.put("balance", userInfo.getBalance());
         OrderTaxi orderTaxi = this.selectById(orderId);
-        int i = userCouponRecordService.queryAvailable(uid, orderTaxi.getCompanyId(), 1, 2, orderTaxi.getOrderMoney());
-        i = i + userCouponRecordService.queryAvailable(uid, orderTaxi.getCompanyId(), 1, 0, orderTaxi.getOrderMoney());
+        int i = userCouponRecordService.queryAvailable(uid, null, 1, 2, orderTaxi.getOrderMoney());
+        i = i + userCouponRecordService.queryAvailable(uid, null, 1, 0, orderTaxi.getOrderMoney());
         map.put("coupon", i);
         return map;
     }
@@ -670,8 +825,22 @@
     @Override
     public List<Map<String, Object>> queryCoupon(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception {
         OrderTaxi orderTaxi = this.selectById(orderId);
-        List<Map<String, Object>> list = userCouponRecordService.queryCoupon(uid, null, 1, 2, orderTaxi.getOrderMoney(), pageNum, size);
-        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(uid, null, 1, 0, orderTaxi.getOrderMoney(), pageNum, size);
+        Driver driver = driverService.selectById(orderTaxi.getDriverId());
+        Integer companyId = driver.getCompanyId();
+        List<CompanyCity> companyCityList = companyCityService.selectList(new EntityWrapper<CompanyCity>().eq("companyId", companyId));
+        List<Map<String, Integer>> cityCode = new ArrayList<>();
+        for (CompanyCity companyCity : companyCityList) {
+            Map<String, Integer> city = new HashMap<>();
+            if(ToolUtil.isNotEmpty(companyCity.getAreaCode())){
+                city.put("code", Integer.valueOf(companyCity.getAreaCode()));
+            }else if(ToolUtil.isEmpty(companyCity.getAreaCode()) && ToolUtil.isNotEmpty(companyCity.getCityCode())){
+                city.put("code", Integer.valueOf(companyCity.getCityCode()));
+            }else if(ToolUtil.isEmpty(companyCity.getCityCode()) && ToolUtil.isNotEmpty(companyCity.getProvinceCode())){
+                city.put("code", Integer.valueOf(companyCity.getProvinceCode()));
+            }
+        }
+        List<Map<String, Object>> list = userCouponRecordService.queryCoupon1(uid, JSON.toJSONString(cityCode), 1, 2, orderTaxi.getOrderMoney(), pageNum, size);
+        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon1(uid, JSON.toJSONString(cityCode), 1, 0, orderTaxi.getOrderMoney(), pageNum, size);
         list.addAll(list1);
         return list;
     }
@@ -1366,6 +1535,10 @@
 
 
             systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功完成出行订单支付,谢谢使用!", orderTaxi.getUserId(), 1);
+            //添加司机消息提醒
+            systemNoticeService.addSystemNotice(2, "用户已线上完成支付", driver.getId(), 1);
+            //推送状态,让司机端播报语音
+            pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
         }else{
             System.err.println("预支付数据异常(orderId = "  + id + ")");
         }

--
Gitblit v1.7.1