longz
2026-06-04 da780b14b8db78043d2c0f27d3bfd73111e6d550
DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/OrderCrossCityServiceImpl.java
@@ -82,9 +82,6 @@
    private DateUtil dateUtil;
    @Resource
    private LinePriceMapper linePriceMapper;
    @Resource
    private LineMapper lineMapper;
    @Resource
@@ -255,6 +252,7 @@
                serverMoney += income.getMoney();
            }
        }
        String dispatchPhone = null;
        if (orderCrossCity.getLineId() <= -1) {
            LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(orderCrossCity.getLineShiftDriverId());
            DriverSelfTrip driverSelfTrip = driverSelfTripMapper.selectById(lineShiftDriver.getCustomerId());
@@ -262,8 +260,9 @@
            map.put("lineId", orderCrossCity.getLineId());
        } else {
            Line line = lineService.selectById(orderCrossCity.getLineId());
            map.put("line", line.getName());
            map.put("line", line == null ? "" : line.getName());
            map.put("lineId", orderCrossCity.getLineId());
            dispatchPhone = line == null ? null : line.getDispatchPhone();
        }
        map.put("peopleNumber", num);
        map.put("orderNumber", orderCrossCity.getOrderNum());
@@ -271,7 +270,7 @@
        map.put("serverMoney", new BigDecimal(serverMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
        OpenCity openCity = openCityService.openCity1(orderCrossCity.getStartLon().toString(), orderCrossCity.getStartLat().toString());
        Phone phone = phoneMapper.queryInfo(openCity == null ? 0 : openCity.getId(), 1, 1);
        map.put("emergencyCall", null != phone ? phone.getPhone() : "110");
        map.put("emergencyCall", StringUtils.isNotBlank(dispatchPhone) ? dispatchPhone : (null != phone ? phone.getPhone() : "110"));
        if (!order.isEmpty()){
            map.put("lineShiftDriverId", order.get(0).get("lineShiftDriverId"));
        }
@@ -1161,98 +1160,10 @@
        }
        Map<String, Object> map = new HashMap<>();
        double distance1 = distance.doubleValue() / 1000;//公里
        map.put("distance", distance);
        /**
         * 1.固定价格的包车是整车价格
         * 2.五座车和七座车的优惠系数是中间特殊位置的优惠折扣
         * 3.包车的情况不享受中间特殊位置的优惠折扣
         * 4.浮动计费拼车如果选中中间特殊位置既享受优惠系数又享受中间特殊位置的优惠折扣
         */
        Map<String, Object> query = linePriceMapper.query(lineId, serverCarModelId);
        if(null == query){
            map.put("distance", 0);
            map.put("price", 0);
            return ResultUtil.success(map);
        }
        String content = query.get("content").toString();
        JSONObject jsonObject = JSON.parseObject(content);
        if(Integer.valueOf(query.get("type").toString()) == 1){//固定金额
            double num1 = Double.valueOf(jsonObject.getString("num1")).doubleValue();
            double num2 = Double.valueOf(jsonObject.getString("num2")).doubleValue();
            double num3 = Double.valueOf(jsonObject.getString("num3")).doubleValue();
            double num4 = Double.valueOf(jsonObject.getString("num4")).doubleValue();
            if(travelMode == 1){//拼车
                String[] split = seatNumber.split(",");
                boolean b = false;
                for(String s : split){
                    if((totalSeat == 4 && s.equals("3")) || (totalSeat == 6 && s.equals("5"))){
                        b = true;
                        break;
                    }
                }
                double price1 = 0D;
                if(b){
                    price1 = num1 * (totalSeat == 4 ? num3 : num4);
                    peopleNumber -= 1;
                }
                double price = (num1 * peopleNumber) + price1;
                map.put("price", new BigDecimal(price).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            }else{
                map.put("price", num2);//包车价
            }
        }else{//浮动计费
            //计算公式:实际历程 * 基础单价 * (参考费用 / (参考里程 * 基础单价)) + (实际历程 - 参考里程) * 基础单价 * 优惠系数
            double num1 = Double.valueOf(jsonObject.getString("num1")).doubleValue();//参考价格
            double num2 = Double.valueOf(jsonObject.getString("num2")).doubleValue();//参考里程
            double num3 = Double.valueOf(jsonObject.getString("num3")).doubleValue();//保底价
            double num4 = Double.valueOf(jsonObject.getString("num4")).doubleValue();//超出参考里程优惠系数
            double num5 = Double.valueOf(jsonObject.getString("num5")).doubleValue();//低于参考里程优惠系数
            double num6 = Double.valueOf(jsonObject.getString("num6")).doubleValue();//包车系数
            double num7 = Double.valueOf(jsonObject.getString("num7")).doubleValue();//五座系数
            double num8 = Double.valueOf(jsonObject.getString("num8")).doubleValue();//七座系数
            /**
             * 1、实际里程>=参考里程
             *    参考价+((实际里程-参考里程)*(参考价/参考里程)*超出参考里程优惠系数)
             *
             * 2、实际里程<参考里程
             *    参考价-(参考里程-实际路程)*(参考价/参考里程)*低于参考里程优惠系数
             */
            double unitPrice = 0d;
            if(distance1 > num2){//1
                unitPrice = num1 + ((distance1 - num2) * (num1 / num2) * num4);
            }
            if(distance1 < num2){//2
                unitPrice = num1 - ((num2 - distance1) * (num1 / num2) * num5);
            }
            if(distance1 == num2){
                unitPrice = num1;
            }
            if(travelMode == 1){//拼车
                String[] split = seatNumber.split(",");
                boolean b = false;
                for(String s : split){
                    if((totalSeat == 4 && s.equals("3")) || (totalSeat == 6 && s.equals("5"))){
                        b = true;
                        break;
                    }
                }
                double price1 = 0D;
                if(b){
                    price1 = unitPrice * (totalSeat == 4 ? num7 : num8);
                    peopleNumber -= 1;
                }
                double price = (unitPrice * peopleNumber) + price1;
                map.put("price", new BigDecimal(num3 > price ? num3 : price).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            }else{
                double price = unitPrice * totalSeat * num6;
                map.put("price", new BigDecimal(num3 > price ? num3 : price).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            }
        }
        Integer pricePeopleNumber = travelMode != null && travelMode == 2 && totalSeat != null && totalSeat > 0 ? totalSeat : peopleNumber;
        BigDecimal unitPrice = queryDefaultLineDestinationPrice(lineId, totalSeat);
        map.put("price", unitPrice == null ? -1 : multiplyPeopleNumber(unitPrice, pricePeopleNumber).doubleValue());
        return ResultUtil.success(map);
    }
@@ -1285,10 +1196,7 @@
            Map<String, Object> destination = lineMapper.queryLineDestinationById(lineDestinationId, lineId);
            BigDecimal unitPrice = null;
            if (destination != null) {
                unitPrice = totalSeat != null && totalSeat == 6 ? getBigDecimal(destination.get("price7")) : getBigDecimal(destination.get("price5"));
                if (unitPrice == null) {
                    unitPrice = getBigDecimal(destination.get("price5"));
                }
                unitPrice = getDestinationPrice(destination, totalSeat);
            }
            map.put("price", unitPrice == null ? -1 : multiplyPeopleNumber(unitPrice, peopleNumber).doubleValue());
            return ResultUtil.success(map);
@@ -1310,18 +1218,15 @@
            map.put("price", -1);
            return ResultUtil.success(map);
        }
        BigDecimal defaultPrice5 = getBigDecimal(destinations.get(0).get("price5"));
        BigDecimal defaultPrice = getDestinationPrice(destinations.get(0), totalSeat);
        BigDecimal matchedPrice = null;
        for (Map<String, Object> destination : destinations) {
            if (isPointInDestinationFence(destination, endLon, endLat)) {
                matchedPrice = totalSeat != null && totalSeat == 6 ? getBigDecimal(destination.get("price7")) : getBigDecimal(destination.get("price5"));
                if (matchedPrice == null) {
                    matchedPrice = getBigDecimal(destination.get("price5"));
                }
                matchedPrice = getDestinationPrice(destination, totalSeat);
                break;
            }
        }
        BigDecimal finalPrice = matchedPrice == null ? defaultPrice5 : matchedPrice;
        BigDecimal finalPrice = matchedPrice == null ? defaultPrice : matchedPrice;
        map.put("price", finalPrice == null ? -1 : multiplyPeopleNumber(finalPrice, peopleNumber).doubleValue());
        return ResultUtil.success(map);
    }
@@ -1366,18 +1271,14 @@
        if (destinations == null || destinations.size() == 0) {
            return null;
        }
        BigDecimal defaultPrice5 = getBigDecimal(destinations.get(0).get("price5"));
        BigDecimal defaultPrice = getDestinationPrice(destinations.get(0), lineShiftDriver.getTotalSeat());
        for (Map<String, Object> destination : destinations) {
            if (isPointInDestinationFence(destination, endLon, endLat)) {
                if (lineShiftDriver.getTotalSeat() != null && lineShiftDriver.getTotalSeat() == 6) {
                    BigDecimal price7 = getBigDecimal(destination.get("price7"));
                    return price7 == null ? defaultPrice5 : price7;
                }
                BigDecimal price5 = getBigDecimal(destination.get("price5"));
                return price5 == null ? defaultPrice5 : price5;
                BigDecimal price = getDestinationPrice(destination, lineShiftDriver.getTotalSeat());
                return price == null ? defaultPrice : price;
            }
        }
        return defaultPrice5;
        return defaultPrice;
    }
    private boolean isPointInDestinationFence(Map<String, Object> destination, Double lon, Double lat) {
@@ -1441,6 +1342,24 @@
        }
    }
    private BigDecimal queryDefaultLineDestinationPrice(Integer lineId, Integer totalSeat) {
        List<Map<String, Object>> destinations = lineMapper.queryLineDestinations(lineId);
        if (destinations == null || destinations.size() == 0) {
            return null;
        }
        return getDestinationPrice(destinations.get(0), totalSeat);
    }
    private BigDecimal getDestinationPrice(Map<String, Object> destination, Integer totalSeat) {
        if (destination == null) {
            return null;
        }
        BigDecimal price = totalSeat != null && totalSeat == 6
                ? getBigDecimal(destination.get("price7"))
                : getBigDecimal(destination.get("price5"));
        return price == null ? getBigDecimal(destination.get("price5")) : price;
    }
    private BigDecimal multiplyPeopleNumber(BigDecimal price, Integer peopleNumber) {
        if (price == null || peopleNumber == null || peopleNumber <= 0) {
            return null;
@@ -1459,7 +1378,7 @@
     * @throws Exception
     */
    public synchronized String getOrderNum(Integer driverId, Integer lineShiftDriverId) throws Exception{
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.queryOrders(driverId, lineShiftDriverId, Arrays.asList(2, 3, 4, 7));
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.queryOrders(driverId, lineShiftDriverId, Arrays.asList(2, 3, 4, 5, 6, 7));
        if(orderCrossCities.size() > 0){
            return orderCrossCities.get(0).getOrderNum();
        }
@@ -1859,7 +1778,7 @@
            return ResultUtil.success(response);
        } else if (type == 3) {
            order.setState(2);
            order.setPayMoney(0.00);
            order.setPayMoney(order.getOrderMoney());
            orderCrossCityMapper.updateById(order);