Administrator
2026-06-12 e28f4db774879138d947b32f7e9f1ec8e5e56077
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -42,6 +42,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@@ -86,24 +87,22 @@
    private final CouponGoodsMapper couponGoodsMapper;
    private final IMallVipConfigService mallVipConfigService;
    private final MallActivityMapper mallActivityMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long createOrder(AddOrderDto addOrderDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember member = mallMemberMapper.selectById(memberId);
        //订单范围内才允许下单
        MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId());
        if(ObjectUtil.isEmpty(address)){
            throw new FebsException("请重新选择收货地址信息");
        }
        MallAddressInfo address = ValidateEntityUtils
                .ensureColumnReturnEntity(addOrderDto.getAddressId(), MallAddressInfo::getId, mallAddressInfoMapper::selectOne, "Please fill in the address first");
        String orderNo = MallUtils.getOrderNum();
        MallOrderInfo orderInfo = new MallOrderInfo();
        orderInfo.setOrderNo(orderNo);
        orderInfo.setOrderTime(new Date());
        orderInfo.setMemberId(member.getId());
        orderInfo.setMemberId(memberId);
        orderInfo.setStatus(OrderStatusEnum.WAIT_PAY.getValue());
        orderInfo.setRemark(addOrderDto.getRemark());
        orderInfo.setOrderType(addOrderDto.getOrderType());
@@ -114,145 +113,54 @@
        this.baseMapper.insert(orderInfo);
        BigDecimal total = BigDecimal.ZERO;
        /**
         * 根据传入的优惠卷ID和商品明细集合计算出每个商品获取的实际支付金额
         */
        Map<Long, BigDecimal> couponAmountMap = new HashMap<>();
        MallMemberCoupon mallMemberCoupon = new MallMemberCoupon();
        if(ObjectUtil.isNotEmpty(addOrderDto.getMemberCouponId())){
            Long memberCouponId = addOrderDto.getMemberCouponId();
            mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
            if(ObjectUtil.isEmpty(mallMemberCoupon)){
                throw new FebsException(mallMemberCoupon.getCouponName()+"无法使用");
            }
            Integer state = mallMemberCoupon.getState();
            if(1 != state){
                throw new FebsException(mallMemberCoupon.getCouponName()+"无法使用");
            }
            List<AddOrderItemDto> items = addOrderDto.getItems();
            couponAmountMap = getCouponAmountMap(memberCouponId, items);
        }
        for (AddOrderItemDto item : addOrderDto.getItems()) {
                MallOrderItem orderItem = new MallOrderItem();
            MallOrderItem orderItem = new MallOrderItem();
                // 积分商品提交订单
                if (addOrderDto.getOrderType() == 2) {
                    MallGoods mallGoods = mallGoodsMapper.selectById(item.getSkuId());
                    if (mallGoods.getStock() < item.getCnt()) {
                        throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                    }
            MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
            if (sku == null) {
                throw new FebsException("The product does not exist.");
            }
                    if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                        throw new FebsException(mallGoods.getGoodsName() + "已下架");
                    }
            if (sku.getStock() < item.getCnt()) {
                throw new FebsException("Insufficient stock");
            }
                    BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt()));
                    orderItem.setAmount(amount);
                    orderItem.setCnt(item.getCnt());
                    orderItem.setOrderId(orderInfo.getId());
                    orderItem.setPrice(mallGoods.getScore());
                    orderItem.setGoodsId(mallGoods.getId());
                    orderItem.setGoodsName(mallGoods.getGoodsName());
                    orderItem.setStyleName(mallGoods.getGoodsName());
                    orderItem.setSkuName(mallGoods.getGoodsName());
                    orderItem.setSkuImage(mallGoods.getThumb());
                    orderItem.setState(1);
            MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
                    if (addOrderDto.getType() == 1) {
                        LambdaQueryWrapper<MallShoppingCart> delQuery = new LambdaQueryWrapper<>();
                        delQuery.eq(MallShoppingCart::getGoodsId, item.getSkuId())
                                .eq(MallShoppingCart::getMemberId, member.getId());
                        mallShoppingCartMapper.delete(delQuery);
                    }
                    total = total.add(amount);
                } else {
                    MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
                    if (sku == null) {
                        throw new FebsException("购买商品或sku不存在");
                    }
            if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                throw new FebsException("Discontinued");
            }
            //商品库存销量计算
            Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), item.getCnt());
            if(1 != goodsResult){
                throw new FebsException("Discontinued");
            }
//                    if("样品".equals(sku.getSample())){
//                        List<MallOrderItem> items = mallOrderItemMapper.selectItemBySkuIdUnCancel(sku.getId(), member.getId());
//                        if (CollUtil.isNotEmpty(items)) {
//                            throw new FebsException("样品一个用户只能购买一次");
//                        }
//                        Integer cnt = item.getCnt();
//                        if(1 < cnt){
//                            throw new FebsException("样品只能购买一件");
//                        }
//
//                    }
            BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
            orderItem.setAmount(amount);
            orderItem.setCnt(item.getCnt());
            orderItem.setOrderId(orderInfo.getId());
            orderItem.setPrice(sku.getPresentPrice());
            orderItem.setGoodsId(sku.getGoodsId());
            orderItem.setGoodsName(sku.getGoodsName());
            orderItem.setSkuId(sku.getId());
            orderItem.setState(1);
            orderItem.setStyleName(sku.getStyleName());
            orderItem.setSkuName(sku.getSkuName());
            orderItem.setSkuImage(sku.getSkuImage());
            orderItem.setIsNormal(mallGoods.getIsNormal());
            orderItem.setCostPrice(sku.getCostPrice());
                    if (sku.getStock() < item.getCnt()) {
                        throw new FebsException(sku.getSkuName() + "库存不足");
                    }
                    MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
                    // 零撸专区购买
                    if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) {
                        List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId());
                        if (CollUtil.isNotEmpty(items)) {
                            throw new FebsException("无法重复领取同一个商品");
                        }
                    }
                    if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                        throw new FebsException(mallGoods.getGoodsName() + "已下架");
                    }
                    //商品库存销量计算
                    Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), item.getCnt());
                    if(1 != goodsResult){
                        throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                    }
                    BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
                    //是否使用优惠卷
                    if(ObjectUtil.isNotEmpty(addOrderDto.getMemberCouponId())){
                        Long memberCouponId = addOrderDto.getMemberCouponId();
                        if(ObjectUtil.isNotEmpty(couponAmountMap.get(item.getSkuId()))){
                            BigDecimal skuCouponAmount = couponAmountMap.get(item.getSkuId());//使用折扣卷后的应该支付的钱
                            if(skuCouponAmount.compareTo(BigDecimal.ZERO) > 0){
                                amount = skuCouponAmount;
                            }
                            orderItem.setMemberCouponId(memberCouponId);
                        }
                    }
                    orderItem.setAmount(amount);
                    orderItem.setCnt(item.getCnt());
                    orderItem.setOrderId(orderInfo.getId());
                    orderItem.setPrice(sku.getPresentPrice());
                    orderItem.setGoodsId(sku.getGoodsId());
                    orderItem.setGoodsName(sku.getGoodsName());
                    orderItem.setSkuId(sku.getId());
                    orderItem.setState(1);
                    if(ObjectUtil.isNotEmpty(member.getReferrerId())){
                        orderItem.setMemberInviteId(member.getReferrerId());
                    }
                    if(ObjectUtil.isNotEmpty(addOrderDto.getMemberInviteId())){
                        orderItem.setMemberInviteId(addOrderDto.getMemberInviteId());
                    }
                    orderItem.setStyleName(sku.getStyleName());
                    orderItem.setSkuName(sku.getSkuName());
                    orderItem.setSkuImage(sku.getSkuImage());
                    orderItem.setIsNormal(mallGoods.getIsNormal());
                    orderItem.setCostPrice(sku.getCostPrice());
                    total = total.add(amount);
                    //规格的库存销量
                    Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),item.getCnt());
                    if(1 != skuResult){
                        throw new FebsException(sku.getSkuName() + "库存不足");
                    }
                    if (addOrderDto.getType() == 1) {
                        mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId());
                    }
                }
                mallOrderItemMapper.insert(orderItem);
            total = total.add(amount);
            //规格的库存销量
            Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),item.getCnt());
            ValidateEntityUtils.ensureEqual(1,skuResult,sku.getSkuName() + "Discontinued");
            if (addOrderDto.getType() == 1) {
                mallShoppingCartMapper.delBySkuId(sku.getId(), memberId);
            }
            mallOrderItemMapper.insert(orderItem);
        }
        mallMemberCoupon.setState(2);
        mallMemberCouponMapper.updateById(mallMemberCoupon);
        //运费
        BigDecimal delivaryAmount = addOrderDto.getDeliveryAmount() == null ? BigDecimal.ZERO : addOrderDto.getDeliveryAmount();
        orderInfo.setCarriage(delivaryAmount);
@@ -260,14 +168,10 @@
        total = total.add(delivaryAmount);
        orderInfo.setAmount(total);
        orderInfo.setAddressId(address.getId());
        orderInfo.setName(address.getName());
        orderInfo.setName(address.getFristName() + address.getName());
        orderInfo.setPhone(address.getPhone());
        orderInfo.setIsHome(addOrderDto.getIsHome());
        if (StrUtil.isBlank(address.getLatitude())||StrUtil.isBlank(address.getLongitude())) {
            throw new FebsException("请添加地址");
        }
        orderInfo.setAddress(address.getProvince()+address.getCity()+address.getArea() + address.getAddress());
        orderInfo.setAddress(address.getArea()+ address.getAddress()+address.getCity()+address.getProvince() + address.getCountry() );
        orderInfo.setLatitude(address.getLatitude());
        orderInfo.setLongitude(address.getLongitude());
        this.baseMapper.updateById(orderInfo);
@@ -283,81 +187,101 @@
     * @return Map<Long,BigDecimal> skuId,实际支付金额
     */
    @Override
    public Map<Long,BigDecimal> getCouponAmountMap(Long memberCouponId,List<AddOrderItemDto> items){
        HashMap<Long,BigDecimal> couponAmountMap = new HashMap<>();
        MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
        if(ObjectUtil.isEmpty(mallMemberCoupon)){
            return couponAmountMap;
        }
        Integer state = mallMemberCoupon.getState();
        if(1 != state){
            return couponAmountMap;
        }
        Long couponId = mallMemberCoupon.getCouponId();//优惠卷ID
        List<Long> goodsIdsAll = couponGoodsMapper.selectByCouponId(couponId);
        List<MallGoodsSku> skusAll = mallGoodsSkuMapper.selectSkuIdsByGoodsId(goodsIdsAll);//获取该优惠卷绑定的全部商品sku
        List<Long> skuIdsAll = skusAll.stream().map(MallGoodsSku::getId).collect(Collectors.toList());//获取该优惠卷绑定的全部商品skuIDS
        List<Long> skuIds = items.stream().map(AddOrderItemDto::getSkuId).collect(Collectors.toList());//订单中的全部skuIds
    public Map<Long, BigDecimal> getCouponAmountMap(Long memberCouponId, List<AddOrderItemDto> items) {
        HashMap<Long, BigDecimal> couponAmountMap = new HashMap<>();
        // 获取优惠券信息
        Optional<MallMemberCoupon> optionalMallMemberCoupon = Optional.ofNullable(mallMemberCouponMapper.selectById(memberCouponId));
        MallMemberCoupon mallMemberCoupon = optionalMallMemberCoupon.orElse(null);
        /**
         * 获取这张优惠卷生效的skuIds
         */
        Set<Long> intersection = skuIdsAll.stream()
                .filter(item -> skuIds.contains(item))
                .collect(Collectors.toSet());//获取两个集合的交集
        if(CollUtil.isEmpty(intersection)){
        if (mallMemberCoupon == null || mallMemberCoupon.getState() != 1) {
            return couponAmountMap;
        }
        HashMap<Long,BigDecimal> skuMap = new HashMap<>();//每个订单详情的ID和amount的map
        List<MallGoodsSku> skus = mallGoodsSkuMapper.selectByIds(new ArrayList<>(intersection));
        BigDecimal totalAmount = BigDecimal.ZERO;//订单中的总金额
        Map<Long, AddOrderItemDto> itemMap = new HashMap<>();// 预先将items转换为Map,以skuId作为键
        for (AddOrderItemDto addOrderItemDto : items) {
            itemMap.put(addOrderItemDto.getSkuId(), addOrderItemDto);
        Set<Long> intersection = items.stream().map(AddOrderItemDto::getSkuId).collect(Collectors.toSet()); // 订单中的全部skuIds
        if (intersection.isEmpty()) {
            return couponAmountMap;
        }
        for(MallGoodsSku mallGoodsSku : skus){
        // 获取订单详情的ID和amount的map
        Map<Long, AddOrderItemDto> itemMap = items.stream()
                .collect(Collectors.toMap(AddOrderItemDto::getSkuId, item -> item));
        List<MallGoodsSku> skus = mallGoodsSkuMapper.selectList(
                new LambdaQueryWrapper<MallGoodsSku>()
                        .select(MallGoodsSku::getId, MallGoodsSku::getPresentPrice)
                        .in(MallGoodsSku::getId, intersection)
        );
        BigDecimal totalAmount = BigDecimal.ZERO;
        Map<Long, BigDecimal> skuMap = new HashMap<>();
        for (MallGoodsSku mallGoodsSku : skus) {
            Long id = mallGoodsSku.getId();
            BigDecimal presentPrice = mallGoodsSku.getPresentPrice();
            // 检查itemMap中是否存在该商品
            AddOrderItemDto addOrderItemDto = itemMap.get(id);
            if (addOrderItemDto != null) {
                BigDecimal skuAmount = presentPrice.multiply(BigDecimal.valueOf(addOrderItemDto.getCnt()));
                totalAmount = totalAmount.add(skuAmount);
                skuMap.put(id,skuAmount);
                skuMap.put(id, skuAmount);
            }
        }
        /**
         * 计算每个商品利用优惠卷打折的具体金额
         */
        MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(mallMemberCoupon.getCouponId());
        BigDecimal costAmount = mallGoodsCoupon.getCostAmount();
        BigDecimal realAmount = mallGoodsCoupon.getRealAmount();
        if(totalAmount.compareTo(costAmount) < 0){
        // 计算每个商品利用优惠卷打折的具体金额
        Optional<MallGoodsCoupon> optionalMallGoodsCoupon = Optional.ofNullable(mallGoodsCouponMapper.selectById(mallMemberCoupon.getCouponId()));
        MallGoodsCoupon mallGoodsCoupon = optionalMallGoodsCoupon.orElse(null);
        if (mallGoodsCoupon == null) {
            return couponAmountMap;
        }
        HashMap<Long,BigDecimal> skuMapPercent = new HashMap<>();//每个订单详情的ID和amount的map
        for (Map.Entry<Long,BigDecimal> entry : skuMap.entrySet()) {
        BigDecimal costAmount = mallGoodsCoupon.getCostAmount();
        BigDecimal realAmount = mallGoodsCoupon.getRealAmount();
        Integer type = mallGoodsCoupon.getType();
        if (MallGoodsCoupon.TYPE_ONE == type) {
            realAmount = mallGoodsCoupon.getRealAmount();
        } else if (MallGoodsCoupon.TYPE_TWO == type) {
            BigDecimal divideTime = totalAmount.divide(costAmount, 0, RoundingMode.DOWN); // 累计减免次数
            realAmount = divideTime.multiply(realAmount); // 实际减免金额
        }
        if (totalAmount.compareTo(costAmount) < 0) {
            return couponAmountMap;
        }
        BigDecimal totalDiscount = BigDecimal.ZERO;
        for (Map.Entry<Long, BigDecimal> entry : skuMap.entrySet()) {
            Long keySkuId = entry.getKey();
            BigDecimal valueSkuAmount = entry.getValue();
            BigDecimal divide = valueSkuAmount.divide(totalAmount, 4, BigDecimal.ROUND_DOWN);//每个商品占符合满减的总额的比例
            skuMapPercent.put(keySkuId,divide);
            Integer type = mallGoodsCoupon.getType();
            if(MallGoodsCoupon.TYPE_ONE == type){
                BigDecimal bigDecimal = realAmount.multiply(divide).setScale(0, BigDecimal.ROUND_DOWN);//每个SKU的减免金额(比例*减免金额)
                BigDecimal skuRealAmount = valueSkuAmount.subtract(bigDecimal.compareTo(BigDecimal.ZERO) > 0 ? bigDecimal : BigDecimal.ZERO);//实际支付金额
                couponAmountMap.put(keySkuId,skuRealAmount);
            BigDecimal divide = valueSkuAmount.divide(totalAmount, 4, RoundingMode.DOWN); // 每个商品占符合满减的总额的比例
            BigDecimal skuRealAmount = BigDecimal.ZERO;
            if (MallGoodsCoupon.TYPE_ONE == type) {
                BigDecimal bigDecimalOne = realAmount.multiply(divide).setScale(2, RoundingMode.DOWN); // 每个SKU的减免金额(比例*减免金额)
                skuRealAmount = valueSkuAmount.subtract(bigDecimalOne.max(BigDecimal.ZERO)).setScale(2, RoundingMode.DOWN);
                totalDiscount = totalDiscount.add(bigDecimalOne);
            } else if (MallGoodsCoupon.TYPE_TWO == type) {
                BigDecimal divideTime = totalAmount.divide(costAmount, 0, RoundingMode.DOWN); // 累计减免次数
                BigDecimal multiply = divideTime.multiply(realAmount); // 实际减免金额
                BigDecimal bigDecimalTwo = multiply.multiply(divide).setScale(2, RoundingMode.DOWN); // 每个SKU的减免金额(比例*实际减免金额)
                skuRealAmount = valueSkuAmount.subtract(bigDecimalTwo.max(BigDecimal.ZERO)).setScale(2, RoundingMode.DOWN);
                totalDiscount = totalDiscount.add(bigDecimalTwo);
            }
            if(MallGoodsCoupon.TYPE_TWO == type){
                BigDecimal divideTime = totalAmount.divide(costAmount, 0, BigDecimal.ROUND_DOWN);//累计减免次数
                BigDecimal multiply = divideTime.multiply(realAmount);//实际减免金额
                BigDecimal bigDecimal = multiply.multiply(divide).setScale(0, BigDecimal.ROUND_DOWN);//每个SKU的减免金额(比例*实际减免金额)
                BigDecimal skuRealAmount = valueSkuAmount.subtract(bigDecimal.compareTo(BigDecimal.ZERO) > 0 ? bigDecimal : BigDecimal.ZERO);//实际支付金额
                couponAmountMap.put(keySkuId,skuRealAmount);
            couponAmountMap.put(keySkuId, skuRealAmount);
        }
        // 调整最后一个商品的减免金额以确保总减免金额达到预期
        if (totalDiscount.compareTo(realAmount) < 0) {
            BigDecimal difference = realAmount.subtract(totalDiscount);
            for (Map.Entry<Long, BigDecimal> entry : couponAmountMap.entrySet()) {
                Long keySkuId = entry.getKey();
                BigDecimal skuRealAmount = entry.getValue();
                BigDecimal newSkuRealAmount = skuRealAmount.subtract(difference).setScale(2, RoundingMode.DOWN);
                couponAmountMap.put(keySkuId, newSkuRealAmount);
                break; // 调整最后一个商品的减免金额
            }
        }
        return couponAmountMap;
    }
    public static void main(String[] args) {
        List<Integer> a = new ArrayList<>();
@@ -387,11 +311,11 @@
        MallMember member = LoginUserUtil.getLoginUser();
        MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), id);
        if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
            throw new FebsException("Order does not exist");
        }
        if (OrderStatusEnum.WAIT_PAY.getValue() != orderInfo.getStatus()) {
            throw new FebsException("订单不是待付款, 无法取消");
            throw new FebsException("The order is not pending payment, so it cannot be canceled");
        }
        orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue());
@@ -399,8 +323,6 @@
        this.baseMapper.updateById(orderInfo);
        if (orderInfo.getOrderType() == 2) {
//            mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount(), MoneyFlowTypeEnum.REFUND.getValue(), orderInfo.getOrderNo(),  FlowTypeEnum.PRIZE_SCORE.getValue());
//            memberWalletService.add(orderInfo.getAmount(), member.getId(), "prizeScore");
            return;
        }
@@ -409,22 +331,22 @@
            for(MallOrderItem mallOrderItem : mallOrderItemList){
                MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId());
                if (sku == null) {
                    throw new FebsException("购买商品或sku不存在");
                    throw new FebsException("The product does not exist.");
                }
                if (sku.getStock() < mallOrderItem.getCnt()) {
                    throw new FebsException(sku.getSkuName() + "库存不足");
                    throw new FebsException("Insufficient stock");
                }
                MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
                Integer goodsResult = mallGoodsMapper.updateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt());
                if(1 != goodsResult){
                    throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                    throw new FebsException("Insufficient stock");
                }
                Integer skuResult = mallGoodsSkuMapper.updateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt());
                if(1 != skuResult){
                    throw new FebsException(sku.getSkuName() + "库存不足");
                    throw new FebsException("Insufficient stock");
                }
                Long memberCouponId = mallOrderItem.getMemberCouponId();
                MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
@@ -479,14 +401,10 @@
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> payOrder(PayOrderDto payOrderDto) {
        MallMember member = LoginUserUtil.getLoginUser();
        MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), payOrderDto.getId());
        if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
        }
        if (OrderStatusEnum.WAIT_PAY.getValue() != orderInfo.getStatus()) {
            throw new FebsException("订单状态不能支付");
        }
        MallOrderInfo orderInfo = ValidateEntityUtils
                .ensureColumnReturnEntity(payOrderDto.getId(), MallOrderInfo::getId, this.baseMapper::selectOne, "订单不存在");
        ValidateEntityUtils.ensureEqual(member.getId(),orderInfo.getMemberId(),"订单不存在");
        ValidateEntityUtils.ensureEqual(OrderStatusEnum.WAIT_PAY.getValue(),orderInfo.getStatus(),"订单状态不能支付");
        String payResultStr = "";
        String wxResultStr = "";
@@ -878,23 +796,16 @@
    @Transactional
    public FebsResponse refundOrder(Long id) {
        MallMember member = LoginUserUtil.getLoginUser();
        MallOrderInfo mallOrderInfo = this.baseMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallOrderInfo)){
            return new FebsResponse().fail().message("订单不存在");
        }
        MallOrderInfo mallOrderInfo = ValidateEntityUtils
                .ensureColumnReturnEntity(id, MallOrderInfo::getId, this.baseMapper::selectOne, "订单不存在");
        Integer status = mallOrderInfo.getStatus();
        if(OrderStatusEnum.WAIT_SHIPPING.getValue() != status){
            return new FebsResponse().fail().message("订单不是待发货状态");
        }
        Integer deliveryState = mallOrderInfo.getDeliveryState();
        if(1 != deliveryState){
            return new FebsResponse().fail().message("订单不是待配送状态");
        }
        ValidateEntityUtils.ensureEqual(OrderStatusEnum.WAIT_SHIPPING.getValue(),status,"订单不是待发货状态");
        ValidateEntityUtils.ensureEqual(1,deliveryState,"订单不是待配送状态");
        //根据子订单生成退款记录
        List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(id);
        if(CollUtil.isEmpty(mallOrderItemList)){
            return new FebsResponse().fail().message("订单不存在");
        }
        List<MallOrderItem> mallOrderItemList = ValidateEntityUtils
                .ensureColumnReturnEntityList(id, MallOrderItem::getOrderId, mallOrderItemMapper::selectList, "订单不存在");
        for(MallOrderItem mallOrderItem : mallOrderItemList){
            QueryWrapper<MallRefundEntity> objectQueryWrapper = new QueryWrapper<>();
            objectQueryWrapper.eq("member_id",member.getId());
@@ -909,7 +820,7 @@
                mallRefundEntity.setItemId(mallOrderItem.getId());
                if("余额支付".equals(mallOrderInfo.getPayMethod())){
                    mallRefundEntity.setType(3);
                }else if("微信支付".equals(mallOrderInfo.getPayMethod())){
                }else if("FIUU支付".equals(mallOrderInfo.getPayMethod())){
                    mallRefundEntity.setType(1);
                }else{
                    mallRefundEntity.setType(3);
@@ -918,9 +829,7 @@
                mallRefundEntity.setAmount(mallOrderItem.getAmount());
                mallRefundMapper.insert(mallRefundEntity);
            }else{
                if(mallRefund.getState() == 1){
                    return new FebsResponse().fail().message("订单已退款");
                }
                ValidateEntityUtils.ensureNotEqual(1,mallRefund.getState(),"订单已退款");
                if(mallRefund.getState() == 2 || mallRefund.getState() == 3){
                    mallRefundEntity.setId(mallRefund.getId());
                    mallRefundEntity.setRefundNo(mallRefund.getRefundNo());
@@ -997,39 +906,22 @@
    @Override
    public FebsResponse createOrderVerify(ApiCreateOrderVerifyDto apiCreateOrderVerifyDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember member = memberMapper.selectById(memberId);
        List<AddOrderItemDto> items = apiCreateOrderVerifyDto.getItems();
        if(CollUtil.isEmpty(items)){
            return new FebsResponse().fail().message("请先挑选商品");
            return new FebsResponse().fail().message("Please select the product first");
        }
        for (AddOrderItemDto item : apiCreateOrderVerifyDto.getItems()) {
            MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
            if (sku == null) {
                return new FebsResponse().fail().message("购买商品或sku不存在");
                return new FebsResponse().fail().message("The product does not exist.");
            }
//            if("样品".equals(sku.getSample())){
//                List<MallOrderItem> mallOrderItems = mallOrderItemMapper.selectItemBySkuIdUnCancel(sku.getId(), member.getId());
//                if (CollUtil.isNotEmpty(mallOrderItems)) {
//                    return new FebsResponse().fail().message("样品只能购买一次");
//                }
//                Integer cnt = item.getCnt();
//                if(1 < cnt){
//                    return new FebsResponse().fail().message("样品只能购买一件");
//                }
//            }else{
//                //验证用户的等级
//                if(AgentLevelEnum.ZERO_LEVEL.name().equals(member.getLevel())){
//                    return new FebsResponse().fail().message("请先申请成为合伙人");
//                }
//            }
            if (sku.getStock() < item.getCnt()) {
                return new FebsResponse().fail().message(sku.getSkuName() + "库存不足");
                return new FebsResponse().fail().message("Insufficient stock");
            }
            MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
            if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                return new FebsResponse().fail().message(mallGoods.getGoodsName() + "已下架");
                return new FebsResponse().fail().message("Discontinued");
            }
        }