优化促销验证商品,检查商品是否可以参与促销

This commit is contained in:
paulGao 2022-07-27 17:21:48 +08:00
parent 6f4994b5da
commit ed976e90dc
10 changed files with 30 additions and 50 deletions

View File

@ -82,6 +82,14 @@ public interface GoodsSkuService extends IService<GoodsSku> {
*/ */
GoodsSku getGoodsSkuByIdFromCache(String id); GoodsSku getGoodsSkuByIdFromCache(String id);
/**
* 从缓存中获取可参与促销商品
*
* @param skuId skuid
* @return 商品详情
*/
GoodsSku getCanPromotionGoodsSkuByIdFromCache(String skuId);
/** /**
* 获取商品sku详情 * 获取商品sku详情
* *

View File

@ -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.GoodsSkuDTO;
import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO; import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO;
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; 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.enums.GoodsStatusEnum;
import cn.lili.modules.goods.entity.vos.GoodsSkuSpecVO; import cn.lili.modules.goods.entity.vos.GoodsSkuSpecVO;
import cn.lili.modules.goods.entity.vos.GoodsSkuVO; import cn.lili.modules.goods.entity.vos.GoodsSkuVO;
@ -237,6 +238,15 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
return goodsSku; 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 @Override
public Map<String, Object> getGoodsSkuDetail(String goodsId, String skuId) { public Map<String, Object> getGoodsSkuDetail(String goodsId, String skuId) {
Map<String, Object> map = new HashMap<>(16); Map<String, Object> map = new HashMap<>(16);

View File

@ -462,7 +462,6 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
memberPointMessage.setPoint(point); memberPointMessage.setPoint(point);
memberPointMessage.setType(type); memberPointMessage.setType(type);
memberPointMessage.setMemberId(memberId); memberPointMessage.setMemberId(memberId);
// 发送会员注册信息
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("update member point", rocketmqCustomProperties.getMemberTopic(), MemberTagsEnum.MEMBER_POINT_CHANGE.name(), memberPointMessage)); applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("update member point", rocketmqCustomProperties.getMemberTopic(), MemberTagsEnum.MEMBER_POINT_CHANGE.name(), memberPointMessage));
return true; return true;
} }

View File

@ -291,7 +291,7 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl<CouponMappe
throw new ServiceException(ResultCode.COUPON_SCOPE_ERROR); throw new ServiceException(ResultCode.COUPON_SCOPE_ERROR);
} }
for (String id : split) { for (String id : split) {
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(id); GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(id);
if (goodsSku == null) { if (goodsSku == null) {
throw new ServiceException(ResultCode.GOODS_NOT_EXIST); throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
} }

View File

@ -120,7 +120,7 @@ public class KanjiaActivityGoodsServiceImpl extends AbstractPromotionsServiceImp
* @return 商品sku * @return 商品sku
*/ */
private GoodsSku checkSkuExist(String skuId) { private GoodsSku checkSkuExist(String skuId) {
GoodsSku goodsSku = this.goodsSkuService.getGoodsSkuByIdFromCache(skuId); GoodsSku goodsSku = this.goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(skuId);
if (goodsSku == null) { if (goodsSku == null) {
log.error("商品ID为" + skuId + "的商品不存在!"); log.error("商品ID为" + skuId + "的商品不存在!");
throw new ServiceException(); throw new ServiceException();
@ -206,7 +206,7 @@ public class KanjiaActivityGoodsServiceImpl extends AbstractPromotionsServiceImp
} }
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = new KanjiaActivityGoodsDTO(); KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = new KanjiaActivityGoodsDTO();
BeanUtils.copyProperties(kanjiaActivityGoods, kanjiaActivityGoodsDTO); BeanUtils.copyProperties(kanjiaActivityGoods, kanjiaActivityGoodsDTO);
GoodsSku goodsSku = this.goodsSkuService.getGoodsSkuByIdFromCache(kanjiaActivityGoods.getSkuId()); GoodsSku goodsSku = this.goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(kanjiaActivityGoods.getSkuId());
if (goodsSku != null) { if (goodsSku != null) {
kanjiaActivityGoodsDTO.setGoodsSku(goodsSku); kanjiaActivityGoodsDTO.setGoodsSku(goodsSku);
} }
@ -233,7 +233,7 @@ public class KanjiaActivityGoodsServiceImpl extends AbstractPromotionsServiceImp
//获取砍价商品 //获取砍价商品
KanjiaActivityGoods kanJiaActivityGoods = this.getById(id); KanjiaActivityGoods kanJiaActivityGoods = this.getById(id);
//获取商品SKU //获取商品SKU
GoodsSku goodsSku = this.goodsSkuService.getGoodsSkuByIdFromCache(kanJiaActivityGoods.getSkuId()); GoodsSku goodsSku = this.goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(kanJiaActivityGoods.getSkuId());
//填写活动商品价格剩余数量 //填写活动商品价格剩余数量
kanJiaActivityGoodsVO.setGoodsSku(goodsSku); kanJiaActivityGoodsVO.setGoodsSku(goodsSku);
kanJiaActivityGoodsVO.setStock(kanJiaActivityGoods.getStock()); kanJiaActivityGoodsVO.setStock(kanJiaActivityGoods.getStock());

View File

@ -115,7 +115,7 @@ public class KanjiaActivityServiceImpl extends ServiceImpl<KanJiaActivityMapper,
} }
KanjiaActivity kanJiaActivity = new KanjiaActivity(); KanjiaActivity kanJiaActivity = new KanjiaActivity();
//获取商品信息 //获取商品信息
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(kanJiaActivityGoods.getSkuId()); GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(kanJiaActivityGoods.getSkuId());
if (goodsSku != null) { if (goodsSku != null) {
kanJiaActivity.setSkuId(kanJiaActivityGoods.getSkuId()); kanJiaActivity.setSkuId(kanJiaActivityGoods.getSkuId());
kanJiaActivity.setGoodsName(goodsSku.getGoodsName()); kanJiaActivity.setGoodsName(goodsSku.getGoodsName());

View File

@ -297,7 +297,7 @@ public class PintuanServiceImpl extends AbstractPromotionsServiceImpl<PintuanMap
if (pintuan.getPromotionGoodsList() != null && !pintuan.getPromotionGoodsList().isEmpty()) { if (pintuan.getPromotionGoodsList() != null && !pintuan.getPromotionGoodsList().isEmpty()) {
List<PromotionGoods> promotionGoods = PromotionTools.promotionGoodsInit(pintuan.getPromotionGoodsList(), pintuan, PromotionTypeEnum.PINTUAN); List<PromotionGoods> promotionGoods = PromotionTools.promotionGoodsInit(pintuan.getPromotionGoodsList(), pintuan, PromotionTypeEnum.PINTUAN);
for (PromotionGoods promotionGood : promotionGoods) { for (PromotionGoods promotionGood : promotionGoods) {
if (goodsSkuService.getGoodsSkuByIdFromCache(promotionGood.getSkuId()) == null) { if (goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(promotionGood.getSkuId()) == null) {
log.error("商品[" + promotionGood.getGoodsName() + "]不存在或处于不可售卖状态!"); log.error("商品[" + promotionGood.getGoodsName() + "]不存在或处于不可售卖状态!");
throw new ServiceException("商品[" + promotionGood.getGoodsName() + "]不存在或处于不可售卖状态!"); throw new ServiceException("商品[" + promotionGood.getGoodsName() + "]不存在或处于不可售卖状态!");
} }

View File

@ -278,7 +278,7 @@ public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl<Points
* @return 商品sku * @return 商品sku
*/ */
private GoodsSku checkSkuExist(String skuId) { private GoodsSku checkSkuExist(String skuId) {
GoodsSku goodsSku = this.goodsSkuService.getGoodsSkuByIdFromCache(skuId); GoodsSku goodsSku = this.goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(skuId);
if (goodsSku == null) { if (goodsSku == null) {
log.error("商品ID为" + skuId + "的商品不存在!"); log.error("商品ID为" + skuId + "的商品不存在!");
throw new ServiceException(); throw new ServiceException();

View File

@ -5,11 +5,8 @@ import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
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.entity.enums.GoodsSalesModeEnum;
import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.goods.service.GoodsSkuService;
@ -75,7 +72,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
@Override @Override
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) { public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
GoodsSku sku = goodsSkuService.getGoodsSkuByIdFromCache(skuId); GoodsSku sku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(skuId);
if (sku == null) { if (sku == null) {
return new ArrayList<>(); return new ArrayList<>();
} }
@ -316,40 +313,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
return promotionMap; 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) { private void setGoodsPromotionInfo(GoodsSku dataSku, Map.Entry<String, Object> promotionInfo) {
JSONObject promotionsObj = JSONUtil.parseObj(promotionInfo.getValue()); JSONObject promotionsObj = JSONUtil.parseObj(promotionInfo.getValue());
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();

View File

@ -161,7 +161,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
List<PromotionGoods> promotionGoodsList = new ArrayList<>(); List<PromotionGoods> promotionGoodsList = new ArrayList<>();
for (SeckillApplyVO seckillApply : seckillApplyList) { for (SeckillApplyVO seckillApply : seckillApplyList) {
//获取参与活动的商品信息 //获取参与活动的商品信息
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId()); GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(seckillApply.getSkuId());
if (!goodsSku.getStoreId().equals(storeId)) { if (!goodsSku.getStoreId().equals(storeId)) {
continue; 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()); 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) { for (SeckillApply seckillApply : list) {
//获取参与活动的商品信息 //获取参与活动的商品信息
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId()); GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(seckillApply.getSkuId());
//获取促销商品 //获取促销商品
PromotionGoods promotionGoods = this.setSeckillGoods(goodsSku, seckillApply, seckill); PromotionGoods promotionGoods = this.setSeckillGoods(goodsSku, seckillApply, seckill);
promotionGoodsList.add(promotionGoods); promotionGoodsList.add(promotionGoods);
@ -373,7 +373,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
if (!seckillApplyList.isEmpty()) { if (!seckillApplyList.isEmpty()) {
List<SeckillApply> collect = seckillApplyList.stream().filter(i -> i.getTimeLine().equals(startTimeline) && i.getPromotionApplyStatus().equals(PromotionsApplyStatusEnum.PASS.name())).collect(Collectors.toList()); List<SeckillApply> collect = seckillApplyList.stream().filter(i -> i.getTimeLine().equals(startTimeline) && i.getPromotionApplyStatus().equals(PromotionsApplyStatusEnum.PASS.name())).collect(Collectors.toList());
for (SeckillApply seckillApply : collect) { for (SeckillApply seckillApply : collect) {
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId()); GoodsSku goodsSku = goodsSkuService.getCanPromotionGoodsSkuByIdFromCache(seckillApply.getSkuId());
if (goodsSku != null) { if (goodsSku != null) {
SeckillGoodsVO goodsVO = new SeckillGoodsVO(); SeckillGoodsVO goodsVO = new SeckillGoodsVO();
BeanUtil.copyProperties(seckillApply, goodsVO); BeanUtil.copyProperties(seckillApply, goodsVO);