秒杀活动增加活动商品数量

This commit is contained in:
lifenlong
2021-05-25 08:02:31 +08:00
parent 00a0edeade
commit e7e29da455
6 changed files with 39 additions and 19 deletions

View File

@@ -54,9 +54,6 @@ public class Seckill extends BasePromotion {
@ApiModelProperty(value = "商品数量")
private Integer goodsNum;
@ApiModelProperty(value = "店铺数量")
private Integer storeNum;
public Seckill(String hours,String seckillRule){
//默认创建30天后的秒杀活动
DateTime dateTime= DateUtil.beginOfDay(DateUtil.offset(new DateTime(), DateField.DAY_OF_YEAR, 30));
@@ -64,7 +61,6 @@ public class Seckill extends BasePromotion {
this.hours=hours;
this.seckillRule=seckillRule;
this.goodsNum=0;
this.storeNum=0;
//BasePromotion
setStoreName("platform");

View File

@@ -2,6 +2,7 @@ package cn.lili.modules.promotion.mapper;
import cn.lili.modules.promotion.entity.dos.Seckill;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Update;
/**
* 秒杀活动数据处理层
@@ -11,4 +12,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface SeckillMapper extends BaseMapper<Seckill> {
@Update("UPDATE li_seckill SET goods_num =( SELECT count( id ) FROM li_seckill_apply WHERE seckill_id = #{seckillId} ) WHERE id = #{seckillId}")
void updateSeckillGoodsNum(String seckillId);
}

View File

@@ -93,4 +93,11 @@ public interface SeckillService extends IService<Seckill> {
* @return 可参与活动数量
*/
Integer getApplyNum();
/**
* 更新秒杀活动的商品数量
* @param seckillId 秒杀活动ID
* @return 更新结果
*/
void updateSeckillGoodsNum(String seckillId);
}

View File

@@ -155,14 +155,10 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
for (SeckillApplyVO seckillApply : seckillApplyList) {
//获取参与活动的商品信息
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId());
//活动库存不能大于商品库存
if (goodsSku.getQuantity() < seckillApply.getQuantity()) {
throw new ServiceException(seckillApply.getGoodsName() + ",此商品库存不足");
}
//获取秒杀活动时间段
DateTime startTime = DateUtil.offsetHour(seckill.getStartTime(), seckillApply.getTimeLine());
//检测是否可以发布促销商品
checkSeckillGoodsSKU(seckill, goodsSku, startTime);
checkSeckillGoodsSKU(seckill, seckillApply, goodsSku, startTime);
//设置秒杀申请默认内容
seckillApply.setOriginalPrice(goodsSku.getPrice());
seckillApply.setPromotionApplyStatus(PromotionApplyStatusEnum.PASS.name());
@@ -188,7 +184,8 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
PromotionTools.promotionGoodsInit(promotionGoodsList, seckill, PromotionTypeEnum.SECKILL);
promotionGoodsService.saveBatch(promotionGoodsList);
}
//设置秒杀活动的商品数量、店铺数量
seckillService.updateSeckillGoodsNum(seckill.getId());
}
@@ -370,10 +367,15 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
* 检测秒杀申请的商品
*
* @param seckill 秒杀活动
* @param seckillApply 秒杀活动申请
* @param goodsSku 商品SKU
* @param startTime 秒杀时段开启时间
*/
private void checkSeckillGoodsSKU(SeckillVO seckill, GoodsSku goodsSku, DateTime startTime) {
private void checkSeckillGoodsSKU(SeckillVO seckill, SeckillApplyVO seckillApply, GoodsSku goodsSku, DateTime startTime) {
//活动库存不能大于商品库存
if (goodsSku.getQuantity() < seckillApply.getQuantity()) {
throw new ServiceException(seckillApply.getGoodsName() + ",此商品库存不足");
}
// 查询是否在同一时间段参与了拼团活动
if (promotionGoodsService.findInnerOverlapPromotionGoods(PromotionTypeEnum.PINTUAN.name(), goodsSku.getId(), startTime, seckill.getEndTime()) > 0) {
throw new ServiceException("商品[" + goodsSku.getGoodsName() + "]已经在重叠的时间段参加了拼团活动,不能参加秒杀活动");

View File

@@ -232,6 +232,11 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
return this.count(queryWrapper);
}
@Override
public void updateSeckillGoodsNum(String seckillId) {
this.baseMapper.updateSeckillGoodsNum(seckillId);
}
/**
* 添加秒杀活动延时任务
* @param seckill 秒杀活动