修复秒杀商品下单时,不会更新秒杀商品的出售数量问题

This commit is contained in:
paulGao 2022-03-02 11:49:41 +08:00
parent e27185d424
commit c4307aa821
8 changed files with 36 additions and 36 deletions

View File

@ -332,7 +332,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
Integer num = promotionGoods.get(i).getNum(); Integer num = promotionGoods.get(i).getNum();
promotionGoods.get(i).setNum((num != null ? num : 0) + order.getOrder().getGoodsNum()); promotionGoods.get(i).setNum((num != null ? num : 0) + order.getOrder().getGoodsNum());
} }
promotionGoodsService.updateBatchById(promotionGoods); promotionGoodsService.updatePromotionGoodsStock(promotionGoods);
} }
//商品库存包含sku库存集合批量更新商品库存相关 //商品库存包含sku库存集合批量更新商品库存相关
goodsSkuService.updateGoodsStuck(goodsSkus); goodsSkuService.updateGoodsStuck(goodsSkus);

View File

@ -139,7 +139,6 @@ public class TradeDTO implements Serializable {
this.cartList = new ArrayList<>(); this.cartList = new ArrayList<>();
this.skuPromotionDetail = new HashMap<>(); this.skuPromotionDetail = new HashMap<>();
this.storeCoupons = new HashMap<>(); this.storeCoupons = new HashMap<>();
this.storeCoupons = new HashMap<>();
this.priceDetailDTO = new PriceDetailDTO(); this.priceDetailDTO = new PriceDetailDTO();
this.cantUseCoupons = new ArrayList<>(); this.cantUseCoupons = new ArrayList<>();
this.canUseCoupons = new ArrayList<>(); this.canUseCoupons = new ArrayList<>();

View File

@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
/** /**
* 发票 * 发票
* *
@ -12,7 +14,9 @@ import lombok.Data;
*/ */
@Data @Data
@ApiModel(value = "发票") @ApiModel(value = "发票")
public class ReceiptVO { public class ReceiptVO implements Serializable {
private static final long serialVersionUID = -8402457457074092957L;
@ApiModelProperty(value = "发票抬头") @ApiModelProperty(value = "发票抬头")
private String receiptTitle; private String receiptTitle;

View File

@ -121,12 +121,9 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
/** /**
* 更新促销活动商品库存 * 更新促销活动商品库存
* *
* @param typeEnum 促销商品类型 * @param promotionGoodsList 更新促销活动商品信息
* @param promotionId 促销活动id
* @param skuId 商品skuId
* @param quantity 更新后的库存数量
*/ */
void updatePromotionGoodsStock(PromotionTypeEnum typeEnum, String promotionId, String skuId, Integer quantity); void updatePromotionGoodsStock(List<PromotionGoods> promotionGoodsList);
/** /**
* 更新促销活动商品索引 * 更新促销活动商品索引

View File

@ -90,13 +90,13 @@ public interface SeckillApplyService extends IService<SeckillApply> {
void removeSeckillApply(String seckillId, String id); void removeSeckillApply(String seckillId, String id);
/** /**
* 更新秒杀商品库存 * 更新秒杀商品出售数量
* *
* @param seckillId 秒杀活动id * @param seckillId 秒杀活动id
* @param skuId 商品skuId * @param skuId 商品skuId
* @param quantity 库存 * @param saleNum 出售数量
*/ */
void updateSeckillApplyQuantity(String seckillId, String skuId, Integer quantity); void updateSeckillApplySaleNum(String seckillId, String skuId, Integer saleNum);
/** /**
* 更新秒杀活动时间 * 更新秒杀活动时间

View File

@ -3,8 +3,6 @@ package cn.lili.modules.promotion.serviceimpl;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.vo.PageVO; import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.goods.service.GoodsSkuService;
@ -27,6 +25,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -209,31 +208,32 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
/** /**
* 更新促销活动商品库存 * 更新促销活动商品库存
* *
* @param typeEnum 促销商品类型 * @param promotionGoodsList 更新促销活动商品信息
* @param promotionId 促销活动id
* @param skuId 商品skuId
* @param quantity 更新后的库存数量
*/ */
@Override @Override
public void updatePromotionGoodsStock(PromotionTypeEnum typeEnum, String promotionId, String skuId, Integer quantity) { @Transactional(rollbackFor = Exception.class)
String promotionStockKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(typeEnum, promotionId, skuId); public void updatePromotionGoodsStock(List<PromotionGoods> promotionGoodsList) {
if (typeEnum.equals(PromotionTypeEnum.SECKILL)) { for (PromotionGoods promotionGoods : promotionGoodsList) {
String promotionStockKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(PromotionTypeEnum.valueOf(promotionGoods.getPromotionType()), promotionGoods.getPromotionId(), promotionGoods.getSkuId());
if (promotionGoods.getPromotionType().equals(PromotionTypeEnum.SECKILL.name())) {
SeckillSearchParams searchParams = new SeckillSearchParams(); SeckillSearchParams searchParams = new SeckillSearchParams();
searchParams.setSeckillId(promotionId); searchParams.setSeckillId(promotionGoods.getPromotionId());
searchParams.setSkuId(skuId); searchParams.setSkuId(promotionGoods.getSkuId());
SeckillApply seckillApply = this.seckillApplyService.getSeckillApply(searchParams); SeckillApply seckillApply = this.seckillApplyService.getSeckillApply(searchParams);
if (seckillApply == null) { if (seckillApply != null) {
throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR); seckillApplyService.updateSeckillApplySaleNum(promotionGoods.getPromotionId(), promotionGoods.getSkuId(), promotionGoods.getNum());
} }
seckillApplyService.updateSeckillApplyQuantity(promotionId, skuId, quantity);
} else {
LambdaUpdateWrapper<PromotionGoods> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(PromotionGoods::getPromotionType, typeEnum.name()).eq(PromotionGoods::getPromotionId, promotionId).eq(PromotionGoods::getSkuId, skuId);
updateWrapper.set(PromotionGoods::getQuantity, quantity);
this.update(updateWrapper);
} }
stringRedisTemplate.opsForValue().set(promotionStockKey, quantity.toString()); LambdaUpdateWrapper<PromotionGoods> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(PromotionGoods::getPromotionType, promotionGoods.getPromotionType()).eq(PromotionGoods::getPromotionId, promotionGoods.getPromotionId()).eq(PromotionGoods::getSkuId, promotionGoods.getSkuId());
updateWrapper.set(PromotionGoods::getQuantity, promotionGoods.getQuantity()).set(PromotionGoods::getNum, promotionGoods.getNum());
this.update(updateWrapper);
stringRedisTemplate.opsForValue().set(promotionStockKey, promotionGoods.getQuantity().toString());
}
} }
/** /**

View File

@ -231,17 +231,17 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
} }
/** /**
* 更新秒杀商品库存 * 更新秒杀商品出售数量
* *
* @param seckillId 秒杀活动id * @param seckillId 秒杀活动id
* @param skuId 商品skuId * @param skuId 商品skuId
* @param quantity 库存 * @param saleNum 库存
*/ */
@Override @Override
public void updateSeckillApplyQuantity(String seckillId, String skuId, Integer quantity) { public void updateSeckillApplySaleNum(String seckillId, String skuId, Integer saleNum) {
LambdaUpdateWrapper<SeckillApply> updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<SeckillApply> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(SeckillApply::getSeckillId, seckillId).eq(SeckillApply::getSkuId, skuId); updateWrapper.eq(SeckillApply::getSeckillId, seckillId).eq(SeckillApply::getSkuId, skuId);
updateWrapper.set(SeckillApply::getQuantity, quantity); updateWrapper.set(SeckillApply::getSalesNum, saleNum);
this.update(updateWrapper); this.update(updateWrapper);
} }