liujie
2023-08-10 aa241a47c90ed776062adf0b8daccf288a21836f
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -1,5 +1,6 @@
package com.supersavedriving.user.modular.system.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -115,6 +116,9 @@
    @Autowired
    private IOrderService orderService;
    @Autowired
    private ICompanyFundFlowService companyFundFlowService;
    @Value("${wx.appletsAppid}")
    private String appletsAppid;
@@ -210,7 +214,9 @@
     */
    public Order getOrderPrice(Integer type, Double distance, Integer waitTime, Order order, String city){
        order = getOrderInitialPrice(order);
        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5));
        Integer driverId = order.getDriverId();
        Driver driver = driverService.selectById(driverId);
        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5).eq("companyId",driver.getBranchOfficeId()));
        if(null == systemConfig){
            if(type == 1){//预估金额
                order.setEstimatedPrice(0D);
@@ -311,6 +317,9 @@
        Double num7 = extraCost.getDouble("num7");//恶劣天气超出公里
        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){
@@ -324,13 +333,13 @@
        }
        //恶劣天气
        systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8));
        systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8).eq("companyId",driver.getBranchOfficeId()));
        if(null != systemConfig){
            JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent());
            Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价
            if(1 == num11){
                boolean badWeather = WeatherUtil.isBadWeather(city);
                if(badWeather){
//                boolean badWeather = WeatherUtil.isBadWeather(city);
//                if(badWeather){
                    order.setBadWeatherDistance(num5);//恶劣天气公里
                    order.setBadWeatherPrice(num6);//恶劣天气费
                    if(distance.compareTo(num7) > 0){
@@ -350,14 +359,27 @@
                            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());
            }
        }
        //计算总金额
        BigDecimal bigDecimal = new BigDecimal(order.getStartPrice() + order.getOverDrivePrice() + order.getLongDistancePrice() + order.getOverLongDistancePrice() +
                order.getWaitTimePrice() + order.getOutWaitTimePrice() + order.getBadWeatherPrice() + order.getOverBadWeatherPrice() - order.getDiscountAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                order.getWaitTimePrice() + order.getOutWaitTimePrice() + order.getBadWeatherPrice() + order.getOverBadWeatherPrice()+order.getHolidayPrice() - order.getDiscountAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN);
        if(type == 1){//预估价
            order.setEstimatedPrice(bigDecimal.doubleValue());
@@ -396,6 +418,7 @@
        order.setCouponId(null);//优惠券
        order.setDiscountAmount(0D);//折扣优惠金额
        order.setDiscount(0D);//折扣
        order.setHolidayPrice(0D);
        return order;
    }
@@ -419,18 +442,6 @@
        if(null != order){
            return ResultUtil.error("您还有正在进行的订单");
        }
        String value = redisUtil.getValue("USER" + uid);
        if(ToolUtil.isEmpty(value)){
            redisUtil.setStrValue("USER" + uid, System.currentTimeMillis() + "", 60);
        }else{
            Long s = System.currentTimeMillis() - Long.valueOf(value);
            if(s.compareTo(60000L) < 0){//1分钟
                return ResultUtil.error("数据处理中");
            }
            redisUtil.setStrValue("USER" + uid, System.currentTimeMillis() + "", 60);
        }
        String startAddress = travelOrder.getStartAddress();
        startAddress = startAddress.replaceAll("& #40;", "(");
@@ -844,6 +855,12 @@
    @Override
    public ResultUtil editOrderEndAddress(Integer uid, EditOrderEndAddress editOrderEndAddress) throws Exception {
        Order order = this.selectById(editOrderEndAddress.getOrderId());
        String endAddress = editOrderEndAddress.getEndAddress();
        endAddress = endAddress.replaceAll("& #40;", "(");
        endAddress = endAddress.replaceAll("& #41;", ")");
        editOrderEndAddress.setEndAddress(endAddress);
        order.setEndAddress(editOrderEndAddress.getEndAddress());
        order.setEndLat(editOrderEndAddress.getEndLat().toString());
        order.setEndLng(editOrderEndAddress.getEndLng().toString());
@@ -1494,6 +1511,7 @@
            accountChangeDetailService.saveData(accountChangeDetail);
            //补贴中分账
            Double balance = revenueService.queryCompanyBalance();//平台账户余额
            Double discountedPrice = order.getDiscountedPrice();
            List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime"));
            for (RechargeRecord rechargeRecord : rechargeRecords) {
@@ -1519,6 +1537,13 @@
                }
            }
            CompanyFundFlow companyFundFlow = new CompanyFundFlow();
            companyFundFlow.setBalance(new BigDecimal(balance));
            companyFundFlow.setObjectType(1);
            companyFundFlow.setType(5);
            companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice()));
            companyFundFlow.setCreateTime(new Date());
            companyFundFlowService.insert(companyFundFlow);
        }
    }
@@ -1967,6 +1992,7 @@
                    }
                    //处理代理商抽佣
                    if(num3 > 0 && null != driver){
                        Double balance = revenueService.queryAgentBalance(driver.getAgentId());
                        Revenue revenue = new Revenue();
                        revenue.setType(1);
                        revenue.setUserType(3);
@@ -2000,6 +2026,15 @@
                                }
                            }
                        }
                        CompanyFundFlow companyFundFlow = new CompanyFundFlow();
                        companyFundFlow.setType(3);
                        companyFundFlow.setObjectType(2);
                        companyFundFlow.setObjectId(driver.getAgentId());
                        companyFundFlow.setBalance(new BigDecimal(balance));
                        companyFundFlow.setMoney(new BigDecimal(num3));
                        companyFundFlow.setCreateTime(new Date());
                        companyFundFlowService.insert(companyFundFlow);
                    }
                }
            }
@@ -2085,6 +2120,7 @@
            accountChangeDetailService.saveData(accountChangeDetail);
            //补贴中分账
            Double balance = revenueService.queryCompanyBalance();
            Double discountedPrice = order.getDiscountedPrice();
            List<RechargeRecord> rechargeRecords1 = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime"));
            for (RechargeRecord rechargeRecord : rechargeRecords1) {
@@ -2109,6 +2145,13 @@
                    }
                }
            }
            CompanyFundFlow companyFundFlow = new CompanyFundFlow();
            companyFundFlow.setBalance(new BigDecimal(balance));
            companyFundFlow.setObjectType(1);
            companyFundFlow.setType(5);
            companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice()));
            companyFundFlow.setCreateTime(new Date());
            companyFundFlowService.insert(companyFundFlow);
        }
        // TODO: 2023/6/25 折扣优惠由司机承担
@@ -2249,6 +2292,7 @@
            driverService.updateById(driver);
            accountChangeDetailService.saveData(accountChangeDetail);
            //补贴中分账
            Double balance = revenueService.queryCompanyBalance();
            Double discountedPrice = order.getDiscountedPrice();
            List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime"));
            for (RechargeRecord rechargeRecord : rechargeRecords) {
@@ -2274,6 +2318,14 @@
                }
            }
            CompanyFundFlow companyFundFlow = new CompanyFundFlow();
            companyFundFlow.setBalance(new BigDecimal(balance));
            companyFundFlow.setObjectType(1);
            companyFundFlow.setType(5);
            companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice()));
            companyFundFlow.setCreateTime(new Date());
            companyFundFlowService.insert(companyFundFlow);
        }
    }