xiaoyong931011
2022-09-23 68819657fbc6c3c701620037135b6633b888a886
20220902
1 files modified
26 ■■■■■ changed files
src/main/java/cc/mrbird/febs/mall/quartz/OrderOvertimeJob.java 26 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/quartz/OrderOvertimeJob.java
@@ -1,6 +1,7 @@
package cc.mrbird.febs.mall.quartz;
import cc.mrbird.febs.common.enumerates.OrderStatusEnum;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.mall.entity.MallGoods;
import cc.mrbird.febs.mall.entity.MallGoodsSku;
import cc.mrbird.febs.mall.entity.MallOrderInfo;
@@ -50,6 +51,31 @@
                orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue());
                orderInfo.setCancelType(MallOrderInfo.CANCEL_OVERTIME_NO_PAY);
                orderInfoMapper.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() + "库存不足");
                        }
                    }
                }
            }
        }