Pu Zhibing
2025-04-28 c399be7463c16b3787b3e591d3006628a11ab858
DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
@@ -4,6 +4,7 @@
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.system.dao.DriverWorkMapper;
import com.stylefeng.guns.modular.system.dao.TUseMoneyMapper;
import com.stylefeng.guns.modular.system.dao.UserCouponRecordMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.ChinaMobileUtil;
@@ -444,6 +445,113 @@
        }
    }
    @Autowired
    private IPaymentRecordService paymentRecordService;
    @Autowired
    private ITransactionDetailsService transactionDetailsService;
    @Autowired
    private UserCouponRecordMapper userCouponRecordMapper;
    /**
     * 司机手动确认收款
     * @param orderId
     * @param orderType
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/order/confirm")
    @ApiOperation(value = "司机手动确认收款", tags = {"司机端-2.0新增"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
            @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城)", name = "orderType", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil process(Integer orderId, Integer orderType, HttpServletRequest request){
        try {
            Integer uid = driverService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
            paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderTaxi.getOrderMoney(), "", 1);//添加预支付数据
            orderTaxi.setState(8);
            orderTaxi.setPayType(3);
            orderTaxi.setPayMoney(orderTaxi.getOrderMoney());
            Integer placeOrderWay = null;
            switch (orderTaxi.getOrderSource()){
                case 2:
                    placeOrderWay = 4;
                    break;
                case 3:
                    placeOrderWay = 4;
                    break;
                case 6:
                    placeOrderWay = 1;
                    break;
                case 7:
                    placeOrderWay = 2;
                    break;
                case 5:
                    placeOrderWay = 3;
                    break;
            }
            // 司机收入
            double moneyTwo;
            // 平台收入
            double money;
            Driver driver = driverService.selectById(orderTaxi.getDriverId());
            Company company = companyService.selectById(driver.getCompanyId());
            if(orderTaxi.getOrderSource() == 2 || orderTaxi.getOrderSource() == 3){
                double v = company.getPercentageDeduction() / 100;
                money = v * orderTaxi.getOrderMoney();
                moneyTwo = orderTaxi.getOrderMoney()-money;
            }else {
                money = company.getFixedDeduction();
                moneyTwo = orderTaxi.getOrderMoney()-money;
            }
            Double orderMoney = orderTaxi.getOrderMoney();
            if (orderTaxi.getCouponId()!=null){
                UserCouponRecord userCouponRecord = userCouponRecordMapper.selectById(orderTaxi.getCouponId());
//                    if(userCouponRecord.getCompanyId() != orderTaxi.getCompanyId()){
//                        return ResultUtil.error("优惠券不能用于此订单", "");
//                    }
//                    if(userCouponRecord.getState() == 2){
//                        return ResultUtil.error("优惠券已使用", "");
//                    }
//                    if(userCouponRecord.getState() == 3){
//                        return ResultUtil.error("优惠券已过期", "");
//                    }
//                    if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 2){
//                        return ResultUtil.error("优惠券不能用于此类型订单", "");
//                    }
//                    if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){
//                        return ResultUtil.error("优惠券不能用于此订单", "");
//                    }
                    orderMoney = orderMoney - userCouponRecord.getMoney();
                    orderTaxi.setCouponMoney(userCouponRecord.getMoney());
                    orderTaxi.setCouponId(orderTaxi.getCouponId());
            }
            orderTaxi.setPayMoney(orderMoney);
            orderTaxiService.updateById(orderTaxi);
            driver.setBalance(driver.getBalance() + moneyTwo);
            // 新增扣除使用费记录
            transactionDetailsService.saveDataTaxi(driver.getId(), "软件使用费", money, 2, 1, 2, 6, orderTaxi.getId(),placeOrderWay,company.getId());
            // 司机订单收入
            transactionDetailsService.saveDataTaxi(driver.getId(), "完成订单", moneyTwo, 1, 1, 2, 2, orderTaxi.getId(),placeOrderWay,company.getId());
            driverService.updateById(driver);
            pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState());
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    /**