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

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();
promotionGoods.get(i).setNum((num != null ? num : 0) + order.getOrder().getGoodsNum());
}
promotionGoodsService.updateBatchById(promotionGoods);
promotionGoodsService.updatePromotionGoodsStock(promotionGoods);
}
//商品库存包含sku库存集合批量更新商品库存相关
goodsSkuService.updateGoodsStuck(goodsSkus);

View File

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

View File

@ -193,7 +193,7 @@ public class CheckDataRender implements CartRenderStep {
}
}
//积分商品判断用户积分是否满足
} else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS) && tradeDTO.getSkuList().get(0).getPromotionMap() != null && !tradeDTO.getSkuList().get(0).getPromotionMap().isEmpty()) {
} else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS) && tradeDTO.getSkuList().get(0).getPromotionMap() != null && !tradeDTO.getSkuList().get(0).getPromotionMap().isEmpty()) {
//获取积分商品VO
Optional<Map.Entry<String, Object>> pointsPromotions = tradeDTO.getSkuList().get(0).getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.POINTS_GOODS.name())).findFirst();
if (pointsPromotions.isPresent()) {

View File

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

View File

@ -121,12 +121,9 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
/**
* 更新促销活动商品库存
*
* @param typeEnum 促销商品类型
* @param promotionId 促销活动id
* @param skuId 商品skuId
* @param quantity 更新后的库存数量
* @param promotionGoodsList 更新促销活动商品信息
*/
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);
/**
* 更新秒杀商品库存
* 更新秒杀商品出售数量
*
* @param seckillId 秒杀活动id
* @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.text.CharSequenceUtil;
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.modules.goods.entity.dos.GoodsSku;
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.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
@ -209,31 +208,32 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
/**
* 更新促销活动商品库存
*
* @param typeEnum 促销商品类型
* @param promotionId 促销活动id
* @param skuId 商品skuId
* @param quantity 更新后的库存数量
* @param promotionGoodsList 更新促销活动商品信息
*/
@Override
public void updatePromotionGoodsStock(PromotionTypeEnum typeEnum, String promotionId, String skuId, Integer quantity) {
String promotionStockKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(typeEnum, promotionId, skuId);
if (typeEnum.equals(PromotionTypeEnum.SECKILL)) {
SeckillSearchParams searchParams = new SeckillSearchParams();
searchParams.setSeckillId(promotionId);
searchParams.setSkuId(skuId);
SeckillApply seckillApply = this.seckillApplyService.getSeckillApply(searchParams);
if (seckillApply == null) {
throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR);
@Transactional(rollbackFor = Exception.class)
public void updatePromotionGoodsStock(List<PromotionGoods> promotionGoodsList) {
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();
searchParams.setSeckillId(promotionGoods.getPromotionId());
searchParams.setSkuId(promotionGoods.getSkuId());
SeckillApply seckillApply = this.seckillApplyService.getSeckillApply(searchParams);
if (seckillApply != null) {
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);
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());
}
stringRedisTemplate.opsForValue().set(promotionStockKey, quantity.toString());
}
/**

View File

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