2.6
luo
2024-02-06 e02092458a5794ee9d4c76d10de3356a87260c07
DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -1,5 +1,7 @@
package com.stylefeng.guns.modular.smallLogistics.server.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
@@ -230,7 +232,16 @@
        return map;
    }
    @Autowired
    private ISettlementDetailService settlementDetailService;
    @Autowired
    private ISettlementAllocationService settlementAllocationService;
    @Autowired
    private ISettlementRecordService settlementRecordService;
    @Autowired
    private  OrderLogisticsSpreadService spreadService;
    /**
     * 走订单流程
     * @param orderId
@@ -253,6 +264,9 @@
                return ResultUtil.error(language == 1 ? "验证失败" : language == 2 ? "Verification failed" : "Echec de la validation");
            }
        }
        List<OrderLogisticsSpread> orderLogisticsId = spreadService.selectList(new EntityWrapper<OrderLogisticsSpread>().eq("orderLogisticsId", orderLogistics.getId()).eq("payType",4));
        switch (state){
            case 3://出发前往预约点
@@ -307,6 +321,73 @@
                    driverService.updateById(driver);
                }
                if (orderLogistics.getPayType()==4||!orderLogisticsId.isEmpty()){
                    double sum = 0;
                    if (orderLogistics.getPayType()==4){
                        sum= orderLogistics.getOrderMoney();
                    }
                    if (!orderLogisticsId.isEmpty()){
                        for (OrderLogisticsSpread orderLogisticsSpread : orderLogisticsId) {
                            sum = sum +orderLogisticsSpread.getPrice();
                        }
                    }
                    Company company = companyService.selectById(orderLogistics.getCompanyId());
                    Double speMoney = company.getSameLogisticsMoney();
                    BigDecimal d = null;//企业收入
                    BigDecimal c = null;//司机收入
                    if(company.getIsSameLogisticsFixedOrProportional() == 2){//固定
                        d = new BigDecimal(speMoney);
                        c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机
                    }
                    if(company.getIsSameLogisticsFixedOrProportional() == 1){//比例
                        Double price = orderLogistics.getOrderMoney();
                        d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN)));
                        c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                    }
                    //记录司机待结算金额
                    if(d.compareTo(new BigDecimal(0)) > 0){
                        SettlementDetail settlementDetail = new SettlementDetail();
                        settlementDetail.setOrderId(orderId);
                        settlementDetail.setOrderType(1);
                        settlementDetail.setDriverId(orderLogistics.getDriverId());
                        settlementDetail.setOrderMoney(sum);
                        settlementDetail.setPrice(d.doubleValue());
                        settlementDetail.setCreateTime(new Date());
                        settlementDetailService.insert(settlementDetail);
                        SettlementAllocation settlementAllocation = settlementAllocationService.selectOne(null);
                        if(null != settlementAllocation){
                            JSONObject jsonObject = JSON.parseObject(settlementAllocation.getContent());
                            Double maxPrice = jsonObject.getDouble("maxPrice");
                            List<SettlementDetail> settlementDetailList = settlementDetailService.selectList(new EntityWrapper<SettlementDetail>().eq("driverId", orderLogistics.getDriverId()).isNull("settlementRecordId").last(" and DATE_FORMAT(now(), '%Y-%m-%d') = DATE_FORMAT(createTime, '%Y-%m-%d')"));
                            BigDecimal total = new BigDecimal(0);
                            for (SettlementDetail detail : settlementDetailList) {
                                total = total.add(new BigDecimal(detail.getPrice()));
                            }
                            if(maxPrice.compareTo(total.doubleValue()) <= 0){
                                SettlementRecord settlementRecord = new SettlementRecord();
                                settlementRecord.setDay(new Date());
                                settlementRecord.setDriverId(orderLogistics.getDriverId());
                                settlementRecord.setType(1);
                                settlementRecord.setPaymentStatus(1);
                                settlementRecord.setPayMoney(sum);
                                settlementRecord.setInsertTime(new Date());
                                settlementRecordService.insert(settlementRecord);
                                for (SettlementDetail detail : settlementDetailList) {
                                    detail.setSettlementRecordId(settlementRecord.getId());
                                    settlementDetailService.updateById(detail);
                                }
                            }
                        }
                    }
                }
                break;
        }
        this.updateById(orderLogistics);