puzhibing
2023-08-30 34eb869e7350173ff036881fc776bc27d5be6d7a
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -33,6 +33,7 @@
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
@@ -115,8 +116,11 @@
    @Autowired
    private IOrderService orderService;
    @Autowired
    @Resource
    private ICompanyFundFlowService companyFundFlowService;
    @Autowired
    private IBranchOfficeService branchOfficeService;
    @Value("${wx.appletsAppid}")
    private String appletsAppid;
@@ -150,15 +154,28 @@
            estimatedCostsWarpper.setTravelTime(Integer.valueOf(distance.get("duration")) / 60);
        }
        String city = "";
        Integer branchOfficeId = null;
        District geocode = MapUtil.geocode(estimatedCosts.getStartLng().toString(), estimatedCosts.getStartLat().toString());
        if(null != geocode){
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
                    .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
            city = null != weatherCity ? weatherCity.getId().toString() : "";
            String districtCode = geocode.getDistrictCode();
            BranchOffice branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("districtCode", districtCode));
            if(null == branchOffice){
                String cityCode = geocode.getCityCode();
                branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("cityCode", cityCode));
                if(null == branchOffice){
                    String provinceCode = geocode.getProvinceCode();
                    branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("provinceCode", provinceCode));
                }
            }
            if(null == branchOffice){
                return ResultUtil.error("起点暂无企业服务");
            }
            branchOfficeId = branchOffice.getId();
        }
        Order order1 = new Order();
        order1.setCreateTime(new Date());
        Order order = getOrderPrice(1, d, 0, order1, city);
        Order order = getOrderPrice(1, d, 0, order1, city, branchOfficeId);
        Double estimatedPrice = order.getEstimatedPrice();
        Coupon coupon = userToCouponService.queryCoupon(uid, estimatedPrice);
        if(null != coupon){
@@ -211,11 +228,9 @@
     * @param city          查询天气的城市
     * @return
     */
    public Order getOrderPrice(Integer type, Double distance, Integer waitTime, Order order, String city){
    public Order getOrderPrice(Integer type, Double distance, Integer waitTime, Order order, String city, Integer branchOfficeId){
        order = getOrderInitialPrice(order);
        Integer driverId = order.getDriverId();
        Driver driver = driverService.selectById(driverId);
        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5).eq("companyId",driver.getBranchOfficeId()));
        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5).eq("companyId", branchOfficeId));
        if(null == systemConfig){
            if(type == 1){//预估金额
                order.setEstimatedPrice(0D);
@@ -317,8 +332,6 @@
        Double num8 = extraCost.getDouble("num8");//恶劣天气超出公里单价 X/公里
        Double num9 = extraCost.getDouble("num9");//恶劣天气最高收取金额
        Double num10 = extraCost.getDouble("num10");//节假日收费
//        Double num11 = extraCost.getDouble("num11");//恶劣天气最高收取金额
//        Double num12 = extraCost.getDouble("num12");//恶劣天气最高收取金额
        //等待费用
        if(waitTime.compareTo(num1 * 60) >= 0){
@@ -332,46 +345,34 @@
        }
        //恶劣天气
        systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8).eq("companyId",driver.getBranchOfficeId()));
        systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8).eq("companyId", branchOfficeId));
        if(null != systemConfig){
            JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent());
            Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价
            Integer num31 = jsonObject1.getInteger("num3");
            if(1 == num11){
//                boolean badWeather = WeatherUtil.isBadWeather(city);
//                if(badWeather){
                    order.setBadWeatherDistance(num5);//恶劣天气公里
                    order.setBadWeatherPrice(num6);//恶劣天气费
                    if(distance.compareTo(num7) > 0){
                        BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7));
                        BigDecimal multiply = subtract.multiply(new BigDecimal(num8));
                        order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里
                        order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费
                    }
                order.setBadWeatherDistance(num5);//恶劣天气公里
                order.setBadWeatherPrice(num6);//恶劣天气费
                if(distance.compareTo(num7) > 0){
                    BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7));
                    BigDecimal multiply = subtract.multiply(new BigDecimal(num8));
                    order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里
                    order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费
                }
                    double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额)
                        if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额
                            order.setBadWeatherPrice(num9);//恶劣天气费
                            order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费
                        }else{
                            BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add));
                            order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费
                        }
                double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额)
                    if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额
                        order.setBadWeatherPrice(num9);//恶劣天气费
                        order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费
                    }else{
                        BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add));
                        order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费
                    }
//                }
                }
            }
        }
        //节假日
        systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 9).eq("companyId",driver.getBranchOfficeId()));
        if(null != systemConfig){
            JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent());
            Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价
            if(1 == num11){
                BigDecimal bigDecimal = new BigDecimal(num10);
                order.setHolidayPrice(bigDecimal.doubleValue());
            if(1 == num31){//节假日
                order.setHolidayPrice(num10);
            }
        }
@@ -413,6 +414,7 @@
        order.setBadWeatherPrice(0D);//恶劣天气里程费
        order.setOverBadWeatherDistance(0D);//恶劣天气超出里程
        order.setOverBadWeatherPrice(0D);//恶劣天气超出里程费
        order.setHolidayPrice(0D);//节假日
        order.setDiscountedPrice(0D);//优惠金额
        order.setCouponId(null);//优惠券
        order.setDiscountAmount(0D);//折扣优惠金额
@@ -476,14 +478,27 @@
            order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60);
        }
        String city = "";
        District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat());
        Integer branchOfficeId = null;
        District geocode = MapUtil.geocode(order.getStartLng().toString(), order.getStartLat().toString());
        if(null != geocode){
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
                    .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
            city = null != weatherCity ? weatherCity.getId().toString() : "";
            String districtCode = geocode.getDistrictCode();
            BranchOffice branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("districtCode", districtCode));
            if(null == branchOffice){
                String cityCode = geocode.getCityCode();
                branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("cityCode", cityCode));
                if(null == branchOffice){
                    String provinceCode = geocode.getProvinceCode();
                    branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("provinceCode", provinceCode));
                }
            }
            if(null == branchOffice){
                return ResultUtil.error("起点暂无企业服务");
            }
            branchOfficeId = branchOffice.getId();
        }
        order.setCreateTime(new Date());
        order = getOrderPrice(1, d, 0, order, city);
        order = getOrderPrice(1, d, 0, order, city, branchOfficeId);
        if(null != travelOrder.getDriverId()){
            DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", travelOrder.getDriverId()).eq("status", 1));
            if(null == driverWork){
@@ -880,15 +895,27 @@
            order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60);
        }
        String city = "";
        Integer branchOfficeId = null;
        District geocode = MapUtil.geocode(order.getStartLng().toString(), order.getStartLat().toString());
        if(null != geocode){
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
                    .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
            city = null != weatherCity ? weatherCity.getId().toString() : "";
            String districtCode = geocode.getDistrictCode();
            BranchOffice branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("districtCode", districtCode));
            if(null == branchOffice){
                String cityCode = geocode.getCityCode();
                branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("cityCode", cityCode));
                if(null == branchOffice){
                    String provinceCode = geocode.getProvinceCode();
                    branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("status", 1).eq("provinceCode", provinceCode));
                }
            }
            if(null == branchOffice){
                return ResultUtil.error("起点暂无企业服务");
            }
            branchOfficeId = branchOffice.getId();
        }
        Order order1 = new Order();
        BeanUtils.copyProperties(order, order1);
        Order orderPrice = getOrderPrice(1, d, 0, order1, city);
        Order orderPrice = getOrderPrice(1, d, 0, order1, city, branchOfficeId);
        order.setEstimatedPrice(orderPrice.getEstimatedPrice());
        this.updateById(order);
@@ -941,6 +968,7 @@
        if(order.getState() < 107){
            orderPriceWarpper.setPayMoney(order.getOrderMoney());
        }
        orderPriceWarpper.setHolidayPrice(order.getHolidayPrice());
        return orderPriceWarpper;
    }