优化促销验证商品,检查商品是否可以参与促销
This commit is contained in:
parent
6f4994b5da
commit
ed976e90dc
@ -82,6 +82,14 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
||||
*/
|
||||
GoodsSku getGoodsSkuByIdFromCache(String id);
|
||||
|
||||
/**
|
||||
* 从缓存中获取可参与促销商品
|
||||
*
|
||||
* @param skuId skuid
|
||||
* @return 商品详情
|
||||
*/
|
||||
GoodsSku getCanPromotionGoodsSkuByIdFromCache(String skuId);
|
||||
|
||||
/**
|
||||
* 获取商品sku详情
|
||||
*
|
||||
@ -143,7 +151,7 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
||||
/**
|
||||
* 分页查询商品sku信息
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param page 分页参数
|
||||
* @param queryWrapper 查询参数
|
||||
* @return 商品sku信息
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@ import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSkuDTO;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsSkuSpecVO;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsSkuVO;
|
||||
@ -237,6 +238,15 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
return goodsSku;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GoodsSku getCanPromotionGoodsSkuByIdFromCache(String skuId) {
|
||||
GoodsSku goodsSku = this.getGoodsSkuByIdFromCache(skuId);
|
||||
if (goodsSku != null && GoodsSalesModeEnum.WHOLESALE.name().equals(goodsSku.getSalesModel())) {
|
||||
throw new ServiceException(ResultCode.PROMOTION_GOODS_DO_NOT_JOIN_WHOLESALE, goodsSku.getGoodsName());
|
||||
}
|
||||
return goodsSku;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getGoodsSkuDetail(String goodsId, String skuId) {
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
|
@ -462,7 +462,6 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
|
||||
memberPointMessage.setPoint(point);
|
||||
memberPointMessage.setType(type);
|
||||
memberPointMessage.setMemberId(memberId);
|
||||
// 发送会员注册信息
|
||||
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("update member point", rocketmqCustomProperties.getMemberTopic(), MemberTagsEnum.MEMBER_POINT_CHANGE.name(), memberPointMessage));
|
||||
return true;
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl<CouponMappe
|
||||
throw new ServiceException(ResultCode.COUPON_SCOPE_ERROR);
|
||||
}
|
||||
for (String id : split) {
|
||||
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(id);
|
||||
GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(id);
|
||||
if (goodsSku == null) {
|
||||
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class KanjiaActivityGoodsServiceImpl extends AbstractPromotionsServiceImp
|
||||
* @return 商品sku
|
||||
*/
|
||||
private GoodsSku checkSkuExist(String skuId) {
|
||||
GoodsSku goodsSku = this.goodsSkuService.getGoodsSkuByIdFromCache(skuId);
|
||||
GoodsSku goodsSku = this.goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(skuId);
|
||||
if (goodsSku == null) {
|
||||
log.error("商品ID为" + skuId + "的商品不存在!");
|
||||
throw new ServiceException();
|
||||
@ -206,7 +206,7 @@ public class KanjiaActivityGoodsServiceImpl extends AbstractPromotionsServiceImp
|
||||
}
|
||||
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = new KanjiaActivityGoodsDTO();
|
||||
BeanUtils.copyProperties(kanjiaActivityGoods, kanjiaActivityGoodsDTO);
|
||||
GoodsSku goodsSku = this.goodsSkuService.getGoodsSkuByIdFromCache(kanjiaActivityGoods.getSkuId());
|
||||
GoodsSku goodsSku = this.goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(kanjiaActivityGoods.getSkuId());
|
||||
if (goodsSku != null) {
|
||||
kanjiaActivityGoodsDTO.setGoodsSku(goodsSku);
|
||||
}
|
||||
@ -233,7 +233,7 @@ public class KanjiaActivityGoodsServiceImpl extends AbstractPromotionsServiceImp
|
||||
//获取砍价商品
|
||||
KanjiaActivityGoods kanJiaActivityGoods = this.getById(id);
|
||||
//获取商品SKU
|
||||
GoodsSku goodsSku = this.goodsSkuService.getGoodsSkuByIdFromCache(kanJiaActivityGoods.getSkuId());
|
||||
GoodsSku goodsSku = this.goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(kanJiaActivityGoods.getSkuId());
|
||||
//填写活动商品价格、剩余数量
|
||||
kanJiaActivityGoodsVO.setGoodsSku(goodsSku);
|
||||
kanJiaActivityGoodsVO.setStock(kanJiaActivityGoods.getStock());
|
||||
|
@ -115,7 +115,7 @@ public class KanjiaActivityServiceImpl extends ServiceImpl<KanJiaActivityMapper,
|
||||
}
|
||||
KanjiaActivity kanJiaActivity = new KanjiaActivity();
|
||||
//获取商品信息
|
||||
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(kanJiaActivityGoods.getSkuId());
|
||||
GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(kanJiaActivityGoods.getSkuId());
|
||||
if (goodsSku != null) {
|
||||
kanJiaActivity.setSkuId(kanJiaActivityGoods.getSkuId());
|
||||
kanJiaActivity.setGoodsName(goodsSku.getGoodsName());
|
||||
|
@ -297,7 +297,7 @@ public class PintuanServiceImpl extends AbstractPromotionsServiceImpl<PintuanMap
|
||||
if (pintuan.getPromotionGoodsList() != null && !pintuan.getPromotionGoodsList().isEmpty()) {
|
||||
List<PromotionGoods> promotionGoods = PromotionTools.promotionGoodsInit(pintuan.getPromotionGoodsList(), pintuan, PromotionTypeEnum.PINTUAN);
|
||||
for (PromotionGoods promotionGood : promotionGoods) {
|
||||
if (goodsSkuService.getGoodsSkuByIdFromCache(promotionGood.getSkuId()) == null) {
|
||||
if (goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(promotionGood.getSkuId()) == null) {
|
||||
log.error("商品[" + promotionGood.getGoodsName() + "]不存在或处于不可售卖状态!");
|
||||
throw new ServiceException("商品[" + promotionGood.getGoodsName() + "]不存在或处于不可售卖状态!");
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl<Points
|
||||
* @return 商品sku
|
||||
*/
|
||||
private GoodsSku checkSkuExist(String skuId) {
|
||||
GoodsSku goodsSku = this.goodsSkuService.getGoodsSkuByIdFromCache(skuId);
|
||||
GoodsSku goodsSku = this.goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(skuId);
|
||||
if (goodsSku == null) {
|
||||
log.error("商品ID为" + skuId + "的商品不存在!");
|
||||
throw new ServiceException();
|
||||
|
@ -5,11 +5,8 @@ import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
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.entity.enums.GoodsSalesModeEnum;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsVO;
|
||||
import cn.lili.modules.goods.service.GoodsService;
|
||||
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||
@ -75,7 +72,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
@Override
|
||||
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
|
||||
|
||||
GoodsSku sku = goodsSkuService.getGoodsSkuByIdFromCache(skuId);
|
||||
GoodsSku sku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(skuId);
|
||||
if (sku == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@ -316,40 +313,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
return promotionMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(PromotionGoods entity) {
|
||||
this.checkGoodsSku(entity.getSkuId());
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveBatch(Collection<PromotionGoods> entityList) {
|
||||
for (PromotionGoods promotionGoods : entityList) {
|
||||
this.checkGoodsSku(promotionGoods.getSkuId());
|
||||
}
|
||||
return super.saveBatch(entityList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveOrUpdateBatch(Collection<PromotionGoods> entityList) {
|
||||
for (PromotionGoods promotionGoods : entityList) {
|
||||
this.checkGoodsSku(promotionGoods.getSkuId());
|
||||
}
|
||||
return super.saveOrUpdateBatch(entityList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为不能参加促销活动的商品
|
||||
*
|
||||
* @param skuId 商品skuId
|
||||
*/
|
||||
private void checkGoodsSku(String skuId) {
|
||||
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(skuId);
|
||||
if (goodsSku != null && GoodsSalesModeEnum.WHOLESALE.name().equals(goodsSku.getSalesModel())) {
|
||||
throw new ServiceException(ResultCode.PROMOTION_GOODS_DO_NOT_JOIN_WHOLESALE, goodsSku.getGoodsName());
|
||||
}
|
||||
}
|
||||
|
||||
private void setGoodsPromotionInfo(GoodsSku dataSku, Map.Entry<String, Object> promotionInfo) {
|
||||
JSONObject promotionsObj = JSONUtil.parseObj(promotionInfo.getValue());
|
||||
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
|
||||
|
@ -161,7 +161,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
|
||||
List<PromotionGoods> promotionGoodsList = new ArrayList<>();
|
||||
for (SeckillApplyVO seckillApply : seckillApplyList) {
|
||||
//获取参与活动的商品信息
|
||||
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId());
|
||||
GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(seckillApply.getSkuId());
|
||||
if (!goodsSku.getStoreId().equals(storeId)) {
|
||||
continue;
|
||||
}
|
||||
@ -262,7 +262,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
|
||||
List<SeckillApply> list = this.list(queryWrapper).stream().filter(i -> i.getTimeLine() != null && seckill.getHours().contains(i.getTimeLine().toString())).collect(Collectors.toList());
|
||||
for (SeckillApply seckillApply : list) {
|
||||
//获取参与活动的商品信息
|
||||
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId());
|
||||
GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(seckillApply.getSkuId());
|
||||
//获取促销商品
|
||||
PromotionGoods promotionGoods = this.setSeckillGoods(goodsSku, seckillApply, seckill);
|
||||
promotionGoodsList.add(promotionGoods);
|
||||
@ -373,7 +373,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
|
||||
if (!seckillApplyList.isEmpty()) {
|
||||
List<SeckillApply> collect = seckillApplyList.stream().filter(i -> i.getTimeLine().equals(startTimeline) && i.getPromotionApplyStatus().equals(PromotionsApplyStatusEnum.PASS.name())).collect(Collectors.toList());
|
||||
for (SeckillApply seckillApply : collect) {
|
||||
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId());
|
||||
GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(seckillApply.getSkuId());
|
||||
if (goodsSku != null) {
|
||||
SeckillGoodsVO goodsVO = new SeckillGoodsVO();
|
||||
BeanUtil.copyProperties(seckillApply, goodsVO);
|
||||
|
Loading…
x
Reference in New Issue
Block a user