mitao
2024-07-19 7106d8205f0af944a34b880405c1b33effcc5393
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -19,6 +19,7 @@
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.page.BeanUtils;
import com.ruoyi.common.core.utils.page.CollUtils;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.order.controller.management.dto.MgtOrderConfirmShipmentDTO;
@@ -348,9 +349,12 @@
            GoodsSku goodsSku = goodsSkuClient.getGoodsSkuOne(data.getGoodsSkuId(), SecurityConstants.INNER).getData();
            if (data.getLimitNumber()<num1) {
                throw new ServiceException("该商品已售罄,暂无库存");
            if (data.getLimitNumber()!=0){
                if (data.getLimitNumber()<num1) {
                    throw new ServiceException("对不起,大于商品购买数");
                }
            }
            order.setOrderFrom(OrderFromEnum.SNAP_ORDERS);
            memberOrderVO.setGoodsSkuId(memberOrderDTO.getGoodsSkuId());
@@ -514,17 +518,22 @@
                memberOrderDTO1.setGoodsSkuId(order.getGoodsSkuId());
                Integer num=baseMapper.getSeckillMembers1(memberOrderDTO1);
                Integer num1=0;
                if (num!=null){
                    num1 =num+order.getGoodsQuantity();
                if(num!=order.getGoodsQuantity()){
                    if (num!=null){
                        num1 =num+order.getGoodsQuantity();
                    }else{
                        num1=order.getGoodsQuantity();
                    }
                }else{
                    num1=order.getGoodsQuantity();
                      num1=num;
                }
                GoodsSeckill data = goodsSkuClient.getGoodsSeckillOne(order.getGoodsSkuId(), SecurityConstants.INNER).getData();
                GoodsSku goodsSku = goodsSkuClient.getGoodsSkuOne(data.getGoodsSkuId(), SecurityConstants.INNER).getData();
                if (num1!=order.getGoodsQuantity()){
                    if (data.getLimitNumber()<num1){
                    if (data.getLimitNumber()!=0||data.getLimitNumber()<num1){
                        throw new ServiceException("对不起,大于商品购买数");
                    }else{
@@ -613,6 +622,7 @@
                        pice=pice.subtract(data.getReductionAmount());
                        order.setDiscountMoney(data.getReductionAmount());
                    }else{
                        order.setDiscountMoney(pice);
                        pice=new BigDecimal(0);
                    }
@@ -620,10 +630,13 @@
                if (data.getCouponType().getCode()==2){
                    pice= order.getTotalAmount();
                    if(pice.compareTo(data.getVoucherAmount())<0){
                        throw new ServiceException("优惠卷抵扣金额不能大于实际支付金额");
                        order.setDiscountMoney(pice);
                        pice=new BigDecimal(0);
                    }else{
                        pice=pice.subtract(data.getVoucherAmount());
                        order.setDiscountMoney(data.getVoucherAmount());
                    }
                    pice=pice.subtract(data.getVoucherAmount());
                    order.setDiscountMoney(data.getVoucherAmount());
                }
                if (data.getCouponType().getCode()==3){
                    pice= order.getTotalAmount();
@@ -634,17 +647,20 @@
                        pice3=new BigDecimal(data.getMaxDiscount().doubleValue());
                    }
                    if(pice.compareTo(pice3)<0){
                        throw new ServiceException("优惠卷抵扣金额不能大于实际支付金额");
                        BigDecimal pice4= pice.subtract(pice3);
                        if (pice4.doubleValue()>data.getMaxDiscount().doubleValue()){
                            pice=pice.subtract(data.getMaxDiscount());
                            order.setDiscountMoney(data.getMaxDiscount());
                        }else{
                            order.setDiscountMoney(pice4);
                            pice=pice3;
                        }
                    }else{
                        order.setDiscountMoney(pice);
                        pice=new BigDecimal(0);
                    }
                    BigDecimal pice4= pice.subtract(pice3);
                    if (pice4.doubleValue()>data.getMaxDiscount().doubleValue()){
                        pice=pice.subtract(data.getMaxDiscount());
                        order.setDiscountMoney(data.getMaxDiscount());
                    }else{
                        order.setDiscountMoney(pice4);
                        pice=pice3;
                    }
                }
                order.setCouponId(memberOrderDTO.getCouponId());
@@ -736,6 +752,17 @@
                        MemberOrderList.setOrderStatus(OrderStatusEnum.CANCELED);
                        Order order = this.getOrder(MemberOrderList.getId());
                        order.setOrderStatus(OrderStatusEnum.CANCELED);
                        if (order.getCouponId()!=0){
                            CouponMemberDTO couponMemberDTO1=new CouponMemberDTO();
                            couponMemberDTO1.setId(order.getCouponId());
                            couponMemberDTO1.setCouponStatus(0);
                            promotionClient.updCouponMember(couponMemberDTO1, SecurityConstants.INNER);
                            order.setCouponId(0L);
                        }
                        this.updateById(order);
                    }
@@ -765,6 +792,11 @@
            }else {
                MemberOrderList.setIsAuctionBond(1);
            }
            CustomConfig memberPointsPoints = sysUserClient.getconfig("MALL_ORDER_DESCRIPTION").getData();
            MemberOrderList.setOrderShuoMin(memberPointsPoints.getConfigValue());
            CustomConfig ReturnCycle = sysUserClient.getconfig("RETURN_CYCLE").getData();
            MemberOrderList.setOrderZq(Integer.valueOf(ReturnCycle.getConfigValue()));
        }
@@ -807,10 +839,14 @@
                }
            }else {
                orderVO.setIsAuctionBond(1);
                orderVO.setBound(new BigDecimal(0));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if (order.getTotalAmount()==null){
            order.setTotalAmount(new BigDecimal(0));
        }
        CustomConfig memberPointsPoints = sysUserClient.getconfig("MALL_ORDER_DESCRIPTION").getData();
        orderVO.setOrderShuoMin(memberPointsPoints.getConfigValue());
@@ -1469,38 +1505,33 @@
    @Override
    public void refundBond(Long id) {
        Order order = getOrder(id);
        OrderAuctionBond orderAuctionBond;
        List<OrderAuctionBond> orderAuctionBond;
        if (order.getAuctionOrderType() == AuctionOrderTypeEnum.AUCTION_ITEMS) {
            orderAuctionBond = orderAuctionBondMapper.selectOne(
            orderAuctionBond = orderAuctionBondMapper.selectList(
                    Wrappers.lambdaQuery(OrderAuctionBond.class)
                            .eq(OrderAuctionBond::getAuctionSalesroomId,
                                    order.getAuctionSalesroomId())
                            .eq(OrderAuctionBond::getBoundStatus, BondStatusEnum.PAID));
            if (StringUtils.isNotNull(orderAuctionBond)
                    && orderAuctionBond.getBoundStatus() == BondStatusEnum.REFUNDED) {
                throw new ServiceException("改拍卖会已退保证金");
            }
        } else {
            orderAuctionBond = orderAuctionBondMapper.selectOne(
            orderAuctionBond = orderAuctionBondMapper.selectList(
                    Wrappers.lambdaQuery(OrderAuctionBond.class)
                            .eq(OrderAuctionBond::getAuctionGoodsId,
                                    order.getGoodsSkuId())
                            .eq(OrderAuctionBond::getBoundStatus, BondStatusEnum.PAID));
        }
        Paylog paylog = iPaylogService.lambdaQuery()
                .eq(Paylog::getOutTradeNo, orderAuctionBond.getOrderNo())
                .last("limit 1").one();
        if (StringUtils.isNull(paylog)) {
            throw new ServiceException("支付记录不存在");
        }
        PaymentMethodEnum paymentMethod = orderAuctionBond.getPaymentMethod();
        if (orderAuctionBond.getBoundStatus() == BondStatusEnum.PAID) {
            boolean result = handleRefund(paymentMethod, paylog, orderAuctionBond.getOrderNo());
            if (result) {
                paylog.setState(3);// 已退款
                orderAuctionBond.setBoundStatus(BondStatusEnum.REFUNDED);
                iPaylogService.updateById(paylog);
                this.updateById(order);
        if (CollUtils.isNotEmpty(orderAuctionBond)) {
            for (OrderAuctionBond auctionBond : orderAuctionBond) {
                Paylog paylog = iPaylogService.lambdaQuery()
                        .in(Paylog::getOutTradeNo, auctionBond.getOrderNo())
                        .one();
                boolean result = handleRefund(auctionBond.getPaymentMethod(), paylog,
                        auctionBond.getOrderNo());
                if (result) {
                    paylog.setState(3);// 已退款
                    auctionBond.setBoundStatus(BondStatusEnum.REFUNDED);
                    iPaylogService.updateById(paylog);
                    this.updateById(order);
                }
            }
        }
    }