xuhy
2024-02-05 5b8a25c22f5d3d20d20475503cc9f3c31ea344ab
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -11,6 +11,7 @@
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogisticsSpread;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsSpreadService;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.system.dao.*;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
@@ -83,7 +84,8 @@
    @Autowired
    private IUserInfoService userInfoService;
    @Resource
    private UserActivityDiscount1Mapper userActivityDiscount1Mapper;
    @Autowired
    private IPaymentRecordService paymentRecordService;
@@ -479,7 +481,7 @@
     * @throws Exception
     */
    @Override
    public ResultUtil payLogisticsOrder(Integer payType, Integer bankCardId, Integer orderId, Integer type, Integer language) throws Exception {
    public ResultUtil payLogisticsOrder(Integer payType, Integer bankCardId, Integer orderId,Integer couponId, Integer type, Integer language) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(orderLogistics.getState() != 7){
            return ResultUtil.error(language == 1 ? "订单已完成支付,不允许重复支付" : language == 2 ? "The order has been paid, recurring payments is not allowed." : "La commande a été payée, les paiements récurrents ne sont pas autorisés.", "");
@@ -491,6 +493,32 @@
        }
        UserInfo userInfo = userInfoService.selectById(uid);
        ResultUtil resultUtil = ResultUtil.success("");
        orderLogistics.setCouponMoney(0D);//初始化历史数据
        orderLogistics.setCouponId(null);
        //计算优惠券
        UserCouponRecord userCouponRecord = null;
        if(null != couponId){
            userCouponRecord = userCouponRecordService.selectById(couponId);
            if(userCouponRecord.getCompanyId() != orderLogistics.getCompanyId()){
                return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", "");
            }
            if(userCouponRecord.getState() == 2){
                return ResultUtil.error(language == 1 ? "优惠券已使用" : language == 2 ? "Coupon has been used." : "Le coupon a été utilisé.", "");
            }
            if(userCouponRecord.getState() == 3){
                return ResultUtil.error(language == 1 ? "优惠券已过期" : language == 2 ? "Coupon is expired." : "Le coupon a expiré.", "");
            }
            if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 4){
                return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", "");
            }
            if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){
                return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", "");
            }
            orderMoney = orderMoney - userCouponRecord.getMoney();
            orderLogistics.setCouponMoney(userCouponRecord.getMoney());
            orderLogistics.setCouponId(couponId);
        }
        orderMoney=new BigDecimal(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
        if(payType == 1) {//手机支付
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
@@ -554,6 +582,13 @@
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            //处理优惠券
            if(null != userCouponRecord){
                userCouponRecord.setState(2);
                userCouponRecord.setEndTime(new Date());
                userCouponRecordService.updateById(userCouponRecord);
            }
            //添加交易明细
            transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId);
            userInfoService.updateById(userInfo);
@@ -579,6 +614,13 @@
        if(payType == 4){//现金支付
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            //处理优惠券和红包
            if(null != userCouponRecord){
                userCouponRecord.setState(2);
                userCouponRecord.setEndTime(new Date());
                userCouponRecordService.updateById(userCouponRecord);
            }
            //添加交易明细
            transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId);
@@ -748,8 +790,8 @@
            //添加已收入明细
            Company company = companyService.selectById(orderLogistics.getCompanyId());
            Double speMoney =  orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney();
            BigDecimal d = null;
            BigDecimal c = null;
            BigDecimal d = BigDecimal.ZERO;
            BigDecimal c = BigDecimal.ZERO;
            if(company.getIsSpeFixedOrProportional() == 2){//固定
                d = new BigDecimal(speMoney);
                c = new BigDecimal(orderMoney).subtract(d);
@@ -763,6 +805,7 @@
            income.setMoney(income.getMoney() + d.doubleValue());
            incomeService.updateById(income);
            income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
            System.out.println("小件物流补差价income======"+income);
            income.setMoney(income.getMoney() + c.doubleValue());
            incomeService.updateById(income);
            Driver driver = driverService.selectById(orderLogistics.getDriverId());
@@ -808,6 +851,14 @@
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
            userInfoService.updateById(userInfo);
            //处理优惠券和红包
            if(null != orderLogistics.getCouponId()){
                UserCouponRecord userCouponRecord = userCouponRecordService.selectById(orderLogistics.getCouponId());
                userCouponRecord.setState(2);
                userCouponRecord.setEndTime(new Date());
                userCouponRecordService.updateById(userCouponRecord);
            }
            query.setState(2);
            query.setCode(order_id);
@@ -1112,6 +1163,29 @@
            transactionDetailsService.saveData(orderLogistics.getUserId(), "包裹取消退款", orderLogistics.getPayMoney(), 1, 1, 1, 4, orderLogistics.getId());
        }
        if(null != orderLogistics.getPayType() && orderLogistics.getPayType() == 4){//现金
//            UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId());
//            userInfo.setBalance(userInfo.getBalance() + orderLogistics.getPayMoney());
//            userInfoService.updateById(userInfo);
            OrderCancel orderCancel = new OrderCancel();
            orderCancel.setOrderId(id);
            orderCancel.setOrderType(orderLogistics.getType());
            orderCancel.setReason(reason);
            orderCancel.setRemark(remark);
            orderCancel.setState(2);
            orderCancel.setInsertTime(new Date());
            orderCancel.setUserType(1);
            orderCancelService.insert(orderCancel);
            orderLogistics.setState(10);
            this.updateById(orderLogistics);
            integer = orderCancel.getId();
            //添加交易明细
            transactionDetailsService.saveData(orderLogistics.getUserId(), "包裹取消退款", orderLogistics.getPayMoney(), 1, 1, 1, 4, orderLogistics.getId());
        }
        if(null != orderLogistics.getDriverId()){
            new Thread(new Runnable() {
                @Override
@@ -1178,7 +1252,21 @@
        Map<String, Object> map = new HashMap<>();
        UserInfo userInfo = userInfoService.selectById(uid);
        map.put("balance", userInfo.getBalance());
        map.put("coupon", 0);
        OrderLogistics orderLogistics = this.selectById(orderId);
        UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderLogistics.getCompanyId());
        double v = orderLogistics.getOrderMoney();
        if(null != query2){
            Integer orderNum=this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId",orderLogistics.getUserId()).eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())"));
            if(query2.getDistance()*1000>orderLogistics.getMileage() && query2.getOrderNum()>orderNum){
                Double special = query2.getSpecial();
                orderLogistics.setDiscount(special);
                Double orderMoney = orderLogistics.getOrderMoney();
                v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
            }
        }
        int i = userCouponRecordService.queryAvailable(uid, orderLogistics.getCompanyId(), 1, 4, v);
        i = i + userCouponRecordService.queryAvailable(uid, orderLogistics.getCompanyId(), 1, 0, v);
        map.put("coupon", i);
        return map;
    }