秒杀活动增加活动商品数量
This commit is contained in:
parent
00a0edeade
commit
e7e29da455
@ -54,9 +54,6 @@ public class Seckill extends BasePromotion {
|
|||||||
@ApiModelProperty(value = "商品数量")
|
@ApiModelProperty(value = "商品数量")
|
||||||
private Integer goodsNum;
|
private Integer goodsNum;
|
||||||
|
|
||||||
@ApiModelProperty(value = "店铺数量")
|
|
||||||
private Integer storeNum;
|
|
||||||
|
|
||||||
public Seckill(String hours,String seckillRule){
|
public Seckill(String hours,String seckillRule){
|
||||||
//默认创建30天后的秒杀活动
|
//默认创建30天后的秒杀活动
|
||||||
DateTime dateTime= DateUtil.beginOfDay(DateUtil.offset(new DateTime(), DateField.DAY_OF_YEAR, 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.hours=hours;
|
||||||
this.seckillRule=seckillRule;
|
this.seckillRule=seckillRule;
|
||||||
this.goodsNum=0;
|
this.goodsNum=0;
|
||||||
this.storeNum=0;
|
|
||||||
|
|
||||||
//BasePromotion
|
//BasePromotion
|
||||||
setStoreName("platform");
|
setStoreName("platform");
|
||||||
|
@ -2,6 +2,7 @@ package cn.lili.modules.promotion.mapper;
|
|||||||
|
|
||||||
import cn.lili.modules.promotion.entity.dos.Seckill;
|
import cn.lili.modules.promotion.entity.dos.Seckill;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
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> {
|
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);
|
||||||
}
|
}
|
@ -93,4 +93,11 @@ public interface SeckillService extends IService<Seckill> {
|
|||||||
* @return 可参与活动数量
|
* @return 可参与活动数量
|
||||||
*/
|
*/
|
||||||
Integer getApplyNum();
|
Integer getApplyNum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新秒杀活动的商品数量
|
||||||
|
* @param seckillId 秒杀活动ID
|
||||||
|
* @return 更新结果
|
||||||
|
*/
|
||||||
|
void updateSeckillGoodsNum(String seckillId);
|
||||||
}
|
}
|
@ -155,14 +155,10 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
|
|||||||
for (SeckillApplyVO seckillApply : seckillApplyList) {
|
for (SeckillApplyVO seckillApply : seckillApplyList) {
|
||||||
//获取参与活动的商品信息
|
//获取参与活动的商品信息
|
||||||
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId());
|
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId());
|
||||||
//活动库存不能大于商品库存
|
|
||||||
if (goodsSku.getQuantity() < seckillApply.getQuantity()) {
|
|
||||||
throw new ServiceException(seckillApply.getGoodsName() + ",此商品库存不足");
|
|
||||||
}
|
|
||||||
//获取秒杀活动时间段
|
//获取秒杀活动时间段
|
||||||
DateTime startTime = DateUtil.offsetHour(seckill.getStartTime(), seckillApply.getTimeLine());
|
DateTime startTime = DateUtil.offsetHour(seckill.getStartTime(), seckillApply.getTimeLine());
|
||||||
//检测是否可以发布促销商品
|
//检测是否可以发布促销商品
|
||||||
checkSeckillGoodsSKU(seckill, goodsSku, startTime);
|
checkSeckillGoodsSKU(seckill, seckillApply, goodsSku, startTime);
|
||||||
//设置秒杀申请默认内容
|
//设置秒杀申请默认内容
|
||||||
seckillApply.setOriginalPrice(goodsSku.getPrice());
|
seckillApply.setOriginalPrice(goodsSku.getPrice());
|
||||||
seckillApply.setPromotionApplyStatus(PromotionApplyStatusEnum.PASS.name());
|
seckillApply.setPromotionApplyStatus(PromotionApplyStatusEnum.PASS.name());
|
||||||
@ -188,7 +184,8 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
|
|||||||
PromotionTools.promotionGoodsInit(promotionGoodsList, seckill, PromotionTypeEnum.SECKILL);
|
PromotionTools.promotionGoodsInit(promotionGoodsList, seckill, PromotionTypeEnum.SECKILL);
|
||||||
promotionGoodsService.saveBatch(promotionGoodsList);
|
promotionGoodsService.saveBatch(promotionGoodsList);
|
||||||
}
|
}
|
||||||
|
//设置秒杀活动的商品数量、店铺数量
|
||||||
|
seckillService.updateSeckillGoodsNum(seckill.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -370,10 +367,15 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
|
|||||||
* 检测秒杀申请的商品
|
* 检测秒杀申请的商品
|
||||||
*
|
*
|
||||||
* @param seckill 秒杀活动
|
* @param seckill 秒杀活动
|
||||||
|
* @param seckillApply 秒杀活动申请
|
||||||
* @param goodsSku 商品SKU
|
* @param goodsSku 商品SKU
|
||||||
* @param startTime 秒杀时段开启时间
|
* @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) {
|
if (promotionGoodsService.findInnerOverlapPromotionGoods(PromotionTypeEnum.PINTUAN.name(), goodsSku.getId(), startTime, seckill.getEndTime()) > 0) {
|
||||||
throw new ServiceException("商品[" + goodsSku.getGoodsName() + "]已经在重叠的时间段参加了拼团活动,不能参加秒杀活动");
|
throw new ServiceException("商品[" + goodsSku.getGoodsName() + "]已经在重叠的时间段参加了拼团活动,不能参加秒杀活动");
|
||||||
|
@ -232,6 +232,11 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
|
|||||||
return this.count(queryWrapper);
|
return this.count(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSeckillGoodsNum(String seckillId) {
|
||||||
|
this.baseMapper.updateSeckillGoodsNum(seckillId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加秒杀活动延时任务
|
* 添加秒杀活动延时任务
|
||||||
* @param seckill 秒杀活动
|
* @param seckill 秒杀活动
|
||||||
|
@ -14,6 +14,7 @@ import cn.lili.modules.promotion.service.SeckillApplyService;
|
|||||||
import cn.lili.modules.promotion.service.SeckillService;
|
import cn.lili.modules.promotion.service.SeckillService;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -33,8 +34,9 @@ public class SeckillManagerController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SeckillApplyService seckillApplyService;
|
private SeckillApplyService seckillApplyService;
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
@ApiOperation(value = "添加秒杀活动")
|
@ApiOperation(value = "添加秒杀活动")
|
||||||
|
@PostMapping
|
||||||
public ResultMessage<Seckill> addSeckill(SeckillVO seckillVO) {
|
public ResultMessage<Seckill> addSeckill(SeckillVO seckillVO) {
|
||||||
AuthUser currentUser = UserContext.getCurrentUser();
|
AuthUser currentUser = UserContext.getCurrentUser();
|
||||||
seckillVO.setStoreId(currentUser.getId());
|
seckillVO.setStoreId(currentUser.getId());
|
||||||
@ -44,8 +46,9 @@ public class SeckillManagerController {
|
|||||||
return ResultUtil.data(seckillVO);
|
return ResultUtil.data(seckillVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
|
||||||
@ApiOperation(value = "修改秒杀活动")
|
@ApiOperation(value = "修改秒杀活动")
|
||||||
|
@PutMapping
|
||||||
public ResultMessage<Seckill> updateSeckill(SeckillVO seckillVO) {
|
public ResultMessage<Seckill> updateSeckill(SeckillVO seckillVO) {
|
||||||
AuthUser currentUser = UserContext.getCurrentUser();
|
AuthUser currentUser = UserContext.getCurrentUser();
|
||||||
seckillVO.setStoreId(currentUser.getId());
|
seckillVO.setStoreId(currentUser.getId());
|
||||||
@ -54,44 +57,48 @@ public class SeckillManagerController {
|
|||||||
return ResultUtil.data(seckillVO);
|
return ResultUtil.data(seckillVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/{id}")
|
|
||||||
@ApiOperation(value = "通过id获取")
|
@ApiOperation(value = "通过id获取")
|
||||||
|
@ApiImplicitParam(name = "id", value = "秒杀活动ID", required = true, dataType = "String", paramType = "path")
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
public ResultMessage<Seckill> get(@PathVariable String id) {
|
public ResultMessage<Seckill> get(@PathVariable String id) {
|
||||||
Seckill seckill = seckillService.getById(id);
|
Seckill seckill = seckillService.getById(id);
|
||||||
return ResultUtil.data(seckill);
|
return ResultUtil.data(seckill);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
@ApiOperation(value = "分页查询秒杀活动列表")
|
@ApiOperation(value = "分页查询秒杀活动列表")
|
||||||
|
@GetMapping
|
||||||
public ResultMessage<IPage<SeckillVO>> getAll(SeckillSearchParams param, PageVO pageVo) {
|
public ResultMessage<IPage<SeckillVO>> getAll(SeckillSearchParams param, PageVO pageVo) {
|
||||||
pageVo.setNotConvert(true);
|
pageVo.setNotConvert(true);
|
||||||
IPage<SeckillVO> page = seckillService.getSeckillByPageFromMongo(param, pageVo);
|
IPage<SeckillVO> page = seckillService.getSeckillByPageFromMongo(param, pageVo);
|
||||||
return ResultUtil.data(page);
|
return ResultUtil.data(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
@ApiOperation(value = "删除一个秒杀活动")
|
@ApiOperation(value = "删除一个秒杀活动")
|
||||||
|
@ApiImplicitParam(name = "id", value = "秒杀活动ID", required = true, dataType = "String", paramType = "path")
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
public ResultMessage<Object> deleteSeckill(@PathVariable String id) {
|
public ResultMessage<Object> deleteSeckill(@PathVariable String id) {
|
||||||
seckillService.deleteSeckill(id);
|
seckillService.deleteSeckill(id);
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/close/{id}")
|
|
||||||
@ApiOperation(value = "关闭一个秒杀活动")
|
@ApiOperation(value = "关闭一个秒杀活动")
|
||||||
|
@ApiImplicitParam(name = "id", value = "秒杀活动ID", required = true, dataType = "String", paramType = "path")
|
||||||
|
@PutMapping("/close/{id}")
|
||||||
public ResultMessage<Object> closeSeckill(@PathVariable String id) {
|
public ResultMessage<Object> closeSeckill(@PathVariable String id) {
|
||||||
seckillService.closeSeckill(id);
|
seckillService.closeSeckill(id);
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "开启一个秒杀活动")
|
||||||
|
@ApiImplicitParam(name = "id", value = "秒杀活动ID", required = true, dataType = "String", paramType = "path")
|
||||||
@PutMapping("/open/{id}")
|
@PutMapping("/open/{id}")
|
||||||
@ApiOperation(value = "一个秒杀活动")
|
|
||||||
public ResultMessage<Object> openSeckill(@PathVariable String id) {
|
public ResultMessage<Object> openSeckill(@PathVariable String id) {
|
||||||
seckillService.openSeckill(id);
|
seckillService.openSeckill(id);
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/apply")
|
|
||||||
@ApiOperation(value = "获取秒杀活动申请列表")
|
@ApiOperation(value = "获取秒杀活动申请列表")
|
||||||
|
@GetMapping("/apply")
|
||||||
public ResultMessage<IPage<SeckillApply>> getSeckillApply(SeckillSearchParams param, PageVO pageVo) {
|
public ResultMessage<IPage<SeckillApply>> getSeckillApply(SeckillSearchParams param, PageVO pageVo) {
|
||||||
IPage<SeckillApply> seckillApply = seckillApplyService.getSeckillApplyFromMongo(param, pageVo);
|
IPage<SeckillApply> seckillApply = seckillApplyService.getSeckillApplyFromMongo(param, pageVo);
|
||||||
return ResultUtil.data(seckillApply);
|
return ResultUtil.data(seckillApply);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user