xiaoyong931011
2022-09-23 7df8d05903fb7fdfc04d5a71dc6e3ce4c9d22c50
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -260,23 +260,32 @@
        orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue());
        orderInfo.setCancelType(MallOrderInfo.CANCEL_BY_SELF);
        this.baseMapper.updateById(orderInfo);
        List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(id);
        List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId());
        if(CollUtil.isNotEmpty(mallOrderItemList)){
            for(MallOrderItem mallOrderItem : mallOrderItemList){
                Long goodsId = mallOrderItem.getGoodsId();
                Long skuId = mallOrderItem.getSkuId();
                Integer cnt = mallOrderItem.getCnt();
                MallGoods mallGoods = mallGoodsMapper.selectById(goodsId);
                mallGoods.setVolume(mallGoods.getVolume() - cnt);
                mallGoods.setStock(mallGoods.getStock() + cnt);
                mallGoodsMapper.updateById(mallGoods);
                MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId());
                if (sku == null) {
                    throw new FebsException("购买商品或sku不存在");
                }
                MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(skuId);
                mallGoodsSku.setSkuVolume(mallGoodsSku.getSkuVolume() - cnt);
                mallGoodsSku.setStock(mallGoodsSku.getStock() + cnt);
                mallGoodsSkuMapper.updateById(mallGoodsSku);
                if (sku.getStock() < mallOrderItem.getCnt()) {
                    throw new FebsException(sku.getSkuName() + "库存不足");
                }
                MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
                Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt());
                if(1 != goodsResult){
                    throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                }
                Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt());
                if(1 != skuResult){
                    throw new FebsException(sku.getSkuName() + "库存不足");
                }
            }
        }
    }
    /**
@@ -688,6 +697,31 @@
            orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue());
            orderInfo.setCancelType(MallOrderInfo.CANCEL_OVERTIME_NO_PAY);
            this.baseMapper.updateById(orderInfo);
            List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId());
            if(CollUtil.isNotEmpty(mallOrderItemList)){
                for(MallOrderItem mallOrderItem : mallOrderItemList){
                    MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId());
                    if (sku == null) {
                        throw new FebsException("购买商品或sku不存在");
                    }
                    if (sku.getStock() < mallOrderItem.getCnt()) {
                        throw new FebsException(sku.getSkuName() + "库存不足");
                    }
                    MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
                    Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt());
                    if(1 != goodsResult){
                        throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                    }
                    Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt());
                    if(1 != skuResult){
                        throw new FebsException(sku.getSkuName() + "库存不足");
                    }
                }
            }
        }
    }