src/main/java/cc/mrbird/febs/mall/mapper/MallOrderInfoMapper.java
@@ -45,6 +45,8 @@ List<MallOrderInfo> selectOrderInfoByStatus(@Param("status") Integer status); List<MallOrderInfo> selectOrderInfoUpTime(@Param("status") Integer status); Integer selectCntDirectOrTeam(@Param("type") Integer type, @Param("inviteId") String inviteId); Integer selectCntDirect(@Param("inviteId") String inviteId); src/main/java/cc/mrbird/febs/mall/quartz/OrderOvertimeJob.java
@@ -43,33 +43,13 @@ @Scheduled(cron = "0 0/5 * * * ? ") public void overtimeJob() { log.info("订单超时任务执行"); List<MallOrderInfo> orderList = orderInfoMapper.selectOrderInfoByStatus(OrderStatusEnum.WAIT_PAY.getValue()); List<MallOrderInfo> orderList = orderInfoMapper.selectOrderInfoUpTime(OrderStatusEnum.WAIT_PAY.getValue()); if (CollUtil.isNotEmpty(orderList)) { for (MallOrderInfo orderInfo : orderList) { long subTime = DateUtil.between(orderInfo.getOrderTime(), new Date(), DateUnit.MINUTE, false); if (subTime > 15) { 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){ 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 mallGoodsSku = mallGoodsSkuMapper.selectById(skuId); mallGoodsSku.setSkuVolume(mallGoodsSku.getSkuVolume() - cnt); mallGoodsSku.setStock(mallGoodsSku.getStock() + cnt); mallGoodsSkuMapper.updateById(mallGoodsSku); } } //更新订单状态 orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue()); orderInfo.setCancelType(MallOrderInfo.CANCEL_OVERTIME_NO_PAY); orderInfoMapper.updateById(orderInfo); } } 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() + "库存不足"); } } } } } src/main/resources/mapper/modules/MallOrderInfoMapper.xml
@@ -259,6 +259,10 @@ select * from mall_order_info where status=#{status} </select> <select id="selectOrderInfoUpTime" resultType="cc.mrbird.febs.mall.entity.MallOrderInfo"> select * from mall_order_info where status=#{status} and now() > date_add(order_time,interval 15 minute) </select> <select id="selectCntDirectOrTeam" resultType="java.lang.Integer"> select IFNULL(count(1), 0) from mall_order_info a inner join mall_member b on a.member_id=b.ID