From bef6b492f8a67db0630662df5af9d69b47b00475 Mon Sep 17 00:00:00 2001
From: yanderong <307678080@qq.com>
Date: 星期二, 14 七月 2026 16:29:35 +0800
Subject: [PATCH] feat: 出租车改为线上支付

---
 DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/IOrderTaxiService.java         |    8 +
 DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderServiceImpl.java   |    2 
 DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java |  255 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 264 insertions(+), 1 deletions(-)

diff --git a/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderServiceImpl.java b/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderServiceImpl.java
index 1cda29a..02f578d 100644
--- a/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderServiceImpl.java
+++ b/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderServiceImpl.java
@@ -1304,7 +1304,7 @@
             case 1:
                 return orderPrivateCarService.queryMoneyInfo(orderId);
             case 2:
-                break;
+                return orderTaxiService.queryMoneyInfo(orderId);
         }
         return null;
     }
diff --git a/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/IOrderTaxiService.java b/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/IOrderTaxiService.java
index 03e095d..f07aae5 100644
--- a/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/IOrderTaxiService.java
+++ b/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/IOrderTaxiService.java
@@ -174,4 +174,12 @@
      * @throws Exception
      */
     List<OrderTaxi> taskMidAxbUnBindSend() throws Exception;
+
+    /**
+     * 获取订单费用明细
+     * @param orderId
+     * @return
+     * @throws Exception
+     */
+    Map<String, Object> queryMoneyInfo(Integer orderId) throws Exception;
 }
diff --git a/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java b/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
index 7ed2d2c..282ff5f 100644
--- a/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
+++ b/DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
@@ -9,6 +9,8 @@
 import com.stylefeng.guns.core.util.ToolUtil;
 import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
 import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
+import com.stylefeng.guns.modular.system.dao.ServerCarModelMapper;
+import com.stylefeng.guns.modular.system.dao.SystemPriceMapper;
 import com.stylefeng.guns.modular.system.dao.UserInfoMapper;
 import com.stylefeng.guns.modular.system.model.*;
 import com.stylefeng.guns.modular.system.service.*;
@@ -16,6 +18,7 @@
 import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
 import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
 import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
+import lombok.Data;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.http.HttpEntity;
@@ -102,8 +105,20 @@
     @Resource
     private RestTemplate internalRestTemplate;
 
+    @Autowired
+    private IAdditionalFeeService additionalFeeService;
 
+    @Autowired
+    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
+    @Resource
+    private ISystemPriceCityService systemPriceCityService;
+
+    @Resource
+    private SystemPriceMapper systemPriceMapper;
+
+    @Resource
+    private ServerCarModelMapper serverCarModelMapper;
 
 
     /**
@@ -1183,4 +1198,244 @@
         orderTaxi.setOrderMoney(sum.setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
         return orderTaxi;
     }
+
+    /**
+     * 获取订单费用明细
+     * @param orderId
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public Map<String, Object> queryMoneyInfo(Integer orderId) throws Exception {
+        OrderTaxi orderTaxi = this.selectById(orderId);
+        // 实时计算费用
+        setMoney(orderTaxi);
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("orderMoney", orderTaxi.getOrderMoney()==null?BigDecimal.ZERO:new BigDecimal(orderTaxi.getOrderMoney().toString()).setScale(2,RoundingMode.HALF_UP));//订单金额
+        map.put("travelMoney", orderTaxi.getTravelMoney());// 行程费
+        map.put("startMileage", 0);//起步价
+        map.put("startMoney", 0);//起步价
+        map.put("mileageKilometers", 0);//里程费
+        map.put("mileageMoney", 0);//里程费
+        map.put("duration", 0);//时长费
+        map.put("durationMoney", 0);//时长费
+        map.put("wait", 0);//等待费
+        map.put("waitMoney", 0);//等待费
+        map.put("longDistance", 0);//远途费
+        map.put("longDistanceMoney", 0);//远途费
+        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());//折扣
+        map.put("holidayFee", orderTaxi.getHolidayFee());//节假日费
+
+        List<OrderAdditionalFee> orderAdditionalFees = orderAdditionalFeeService.selectList(new EntityWrapper<OrderAdditionalFee>().eq("orderType", 2).eq("orderId", orderId));
+        List<Map<String, Object>> list = new ArrayList<>();
+        orderAdditionalFees.forEach(orderAdditionalFee -> {
+            AdditionalFee additionalFee = additionalFeeService.selectById(orderAdditionalFee.getAdditionalFeeId());
+            Map<String, Object> map1 = new HashMap<>();
+            map1.put("name", additionalFee.getName());
+            map1.put("amount", orderAdditionalFee.getAmount());
+            list.add(map1);
+        });
+        map.put("additionalFee", list);
+        return map;
+    }
+
+    public void setMoney(OrderTaxi orderTaxi) {
+        try {
+            Map<String, String> startGeocode = gdMapGeocodingUtil.geocode(String.valueOf(orderTaxi.getStartLon()), String.valueOf(orderTaxi.getStartLat()));
+            if (orderTaxi.getEndLon() != null && orderTaxi.getEndLat() != null && startGeocode != null) {
+                Map<String, String> distance = gdMapElectricFenceUtil.getDistance(
+                        orderTaxi.getStartLon() + "," + orderTaxi.getStartLat(),
+                        orderTaxi.getEndLon() + "," + orderTaxi.getEndLat(),
+                        1
+                );
+                if (distance != null) {
+                    double distanceMeters = Double.parseDouble(distance.get("distance"));
+                    long durationSeconds = Long.parseLong(distance.get("duration"));
+                    Map<String, Object> textPriceMap = getTextPrice(distanceMeters, durationSeconds, 0, 2, startGeocode);
+                    if (textPriceMap != null && textPriceMap.get("zongfeiyong") != null) {
+                        Double estimateAmount = Double.valueOf(textPriceMap.get("zongfeiyong").toString());
+                        orderTaxi.setEstimateAmount(estimateAmount);
+                        orderTaxi.setOrderMoney(estimateAmount);
+                        orderTaxi.setPaymentMode(1);
+                        orderTaxi.setState(7);
+                    } else {
+                        orderTaxi.setPaymentMode(2);
+                    }
+                } else {
+                    orderTaxi.setPaymentMode(2);
+                }
+            } else {
+                orderTaxi.setPaymentMode(2);
+            }
+        } catch (Exception e) {
+            orderTaxi.setPaymentMode(2);
+            orderTaxi.setState(1);
+        }
+    }
+
+
+    public Map<String, Object> getTextPrice(double distance, long duration, long wait, Integer type, Map<String, String> geocode) throws Exception {
+        String provinceCode = geocode.get("provinceCode");
+        String cityCode = geocode.get("cityCode");
+        String districtCode = geocode.get("districtCode");
+        //获取匹配的城市价格配置
+        SystemPriceCity systemPriceCity = systemPriceCityService.queryOne(provinceCode, cityCode, districtCode);
+        if (null == systemPriceCity) {
+            return null;
+        }
+        Map<String, Object> query1 = systemPriceMapper.query(systemPriceCity.getId(), type, null);
+        if (null == query1) {//排除没有设置价格的车型
+            return null;
+        }
+
+        Map<String, Object> map = new HashMap<>();
+        double d = distance / 1000;//实际公里
+        double t = duration / 60;//实际时间
+        JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费
+        Double num1 = jsonObject.getDouble("num1");
+        Double num2 = jsonObject.getDouble("num2");
+        JSONArray mileageList = jsonObject.getJSONArray("mileageList");
+        Double num4 = jsonObject.getDouble("num4");
+        Double num5 = jsonObject.getDouble("num5");
+        String num6 = jsonObject.getString("num6");
+        Double num7 = jsonObject.getDouble("num7");
+        Double num8 = jsonObject.getDouble("num8");
+
+        String[] split = num6.split(" - ");
+        Integer time1 = Integer.valueOf(split[0].replace(":", ""));
+        Integer time2 = Integer.valueOf(split[1].replace(":", ""));
+        long start_date = 0;
+        long end_date = 0;
+        if(time1.compareTo(time2) > 0){
+            //跨天
+            String[] split1 = split[1].split(":");
+            Calendar calendar = Calendar.getInstance();
+            calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1);
+            calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split1[0]));
+            calendar.set(Calendar.MINUTE, Integer.valueOf(split1[1]));
+            calendar.set(Calendar.SECOND, 59);
+            end_date = calendar.getTimeInMillis();
+
+            String[] split2 = split[0].split(":");
+            calendar = Calendar.getInstance();
+            calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split2[0]));
+            calendar.set(Calendar.MINUTE, Integer.valueOf(split2[1]));
+            calendar.set(Calendar.SECOND, 0);
+            start_date = calendar.getTimeInMillis();
+        }else{
+            String[] split1 = split[1].split(":");
+            Calendar calendar = Calendar.getInstance();
+            calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split1[0]));
+            calendar.set(Calendar.MINUTE, Integer.valueOf(split1[1]));
+            calendar.set(Calendar.SECOND, 59);
+            end_date = calendar.getTimeInMillis();
+
+            String[] split2 = split[0].split(":");
+            calendar = Calendar.getInstance();
+            calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split2[0]));
+            calendar.set(Calendar.MINUTE, Integer.valueOf(split2[1]));
+            calendar.set(Calendar.SECOND, 0);
+            start_date = calendar.getTimeInMillis();
+        }
+
+        Double amount = 0D;
+        if (System.currentTimeMillis() > start_date && System.currentTimeMillis() <= end_date) {
+            amount = num7;
+            BigDecimal multiply = BigDecimal.ZERO;
+            BigDecimal yt = BigDecimal.ZERO;
+            if (d > num8) {
+
+                if(null != mileageList){
+                    List<MileageObject> list = new ArrayList<>();
+                    for (int i = 0; i < mileageList.size(); i++) {
+                        MileageObject mileageObject = mileageList.getObject(i, MileageObject.class);
+                        list.add(mileageObject);
+                    }
+                    //根据配置的里程倒序排序
+                    list.sort(new Comparator<MileageObject>() {
+                        @Override
+                        public int compare(MileageObject o1, MileageObject o2) {
+                            return o1.getMileage().compareTo(o2.getMileage()) * -1;
+                        }
+                    });
+                    //计算每个阶段的增加费用
+                    Double last = new BigDecimal(d).setScale(0, RoundingMode.DOWN).doubleValue();
+                    for (int i = 0; i < list.size(); i++) {
+                        Double mileage = list.get(i).getMileage();
+                        Double price = list.get(i).getPrice();
+                        if(d > mileage){
+                            if(last <= num2){
+                                break;
+                            }
+                            multiply = multiply.add((new BigDecimal(last).subtract(new BigDecimal(mileage))).multiply(new BigDecimal(price)));
+                            last = mileage;
+                        }
+                    }
+                }
+                if (d > num4) {
+                    yt = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5));
+                }
+                amount = new BigDecimal(num7).add(multiply).add(yt).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
+            }
+            map.put("qibujia", num7);
+            map.put("lichengfei", multiply.doubleValue());
+            map.put("yuantufei", yt.doubleValue());
+            map.put("zongfeiyong", amount);
+        } else {
+            amount = num1;
+            BigDecimal multiply = BigDecimal.ZERO;
+            BigDecimal yt = BigDecimal.ZERO;
+            if (d > num2) {
+                if(null != mileageList){
+                    List<MileageObject> list = new ArrayList<>();
+                    for (int i = 0; i < mileageList.size(); i++) {
+                        MileageObject mileageObject = mileageList.getObject(i, MileageObject.class);
+                        list.add(mileageObject);
+                    }
+                    //根据配置的里程倒序排序
+                    list.sort(new Comparator<MileageObject>() {
+                        @Override
+                        public int compare(MileageObject o1, MileageObject o2) {
+                            return o1.getMileage().compareTo(o2.getMileage()) * -1;
+                        }
+                    });
+                    //计算每个阶段的增加费用
+                    Double last = new BigDecimal(d).setScale(0, RoundingMode.DOWN).doubleValue();
+                    for (int i = 0; i < list.size(); i++) {
+                        Double mileage = list.get(i).getMileage();
+                        Double price = list.get(i).getPrice();
+                        if(d > mileage){
+                            if(last <= num2){
+                                break;
+                            }
+                            multiply = multiply.add((new BigDecimal(last).subtract(new BigDecimal(mileage))).multiply(new BigDecimal(price)));
+                            last = mileage;
+                        }
+                    }
+                }
+
+                if (d > num4) {
+                    yt = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5));
+                }
+                amount = new BigDecimal(num1).add(multiply).add(yt).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
+            }
+            map.put("qibujia", num1);
+            map.put("lichengfei", multiply.doubleValue());
+            map.put("yuantufei", yt.doubleValue());
+            map.put("zongfeiyong", amount);
+        }
+        return map;
+    }
+
+    @Data
+    public static class MileageObject{
+        private Double mileage;
+        private Double price;
+    }
 }

--
Gitblit v1.7.1