From e18b62da6e90cc4aa4fa50f42cd189bf9b660880 Mon Sep 17 00:00:00 2001 From: misworga831 Date: Mon, 10 Apr 2023 14:43:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E4=BF=83=E9=94=80?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=B5=81=E7=A8=8B=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BF=83=E9=94=80=E7=9B=B8=E5=85=B3bug?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/common/enums/ResultCode.java | 1 + .../service/AbstractPromotionsService.java | 7 +++ .../service/MemberCouponService.java | 5 ++ .../AbstractPromotionsServiceImpl.java | 20 +++++++ .../serviceimpl/CouponServiceImpl.java | 4 +- .../serviceimpl/FullDiscountServiceImpl.java | 31 ++-------- .../serviceimpl/MemberCouponServiceImpl.java | 8 +++ .../serviceimpl/PintuanServiceImpl.java | 44 -------------- .../serviceimpl/PointsGoodsServiceImpl.java | 3 +- .../serviceimpl/SeckillServiceImpl.java | 11 ---- .../promotion/tools/PromotionTools.java | 59 ++++++++++++++++++- .../search/entity/dto/EsGoodsSearchDTO.java | 18 ++++++ .../serviceimpl/EsGoodsIndexServiceImpl.java | 32 +++++----- .../serviceimpl/EsGoodsSearchServiceImpl.java | 14 +++++ 14 files changed, 156 insertions(+), 101 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index e2b702d2..c1040bb8 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -82,6 +82,7 @@ public enum ResultCode { HAVE_INVALID_SALES_MODEL(11023, "批发规则存在小于等于0的无效数据!"), MUST_HAVE_GOODS_SKU_VALUE(11024, "规格值不能为空!"), DO_NOT_MATCH_WHOLESALE(11025, "批发商品购买数量不能低于起拍量!"), + GOODS_NOT_ERROR(11026, "商品不存在"), GOODS_PARAMS_ERROR(11013, "商品参数错误,刷新后重试"), PHYSICAL_GOODS_NEED_TEMP(11014, "实物商品需选择配送模板"), diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/AbstractPromotionsService.java b/framework/src/main/java/cn/lili/modules/promotion/service/AbstractPromotionsService.java index 241f7781..18a65b7f 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/AbstractPromotionsService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/AbstractPromotionsService.java @@ -128,4 +128,11 @@ public interface AbstractPromotionsService extends ISe */ PromotionTypeEnum getPromotionType(); + /** + * 是否允许同一时间内存在相同的促销 + * + * @return 是否允许同一时间内存在相同的促销 + */ + boolean allowExistSame(); + } diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/MemberCouponService.java b/framework/src/main/java/cn/lili/modules/promotion/service/MemberCouponService.java index 4bd4fa87..b807a080 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/MemberCouponService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/MemberCouponService.java @@ -165,4 +165,9 @@ public interface MemberCouponService extends IService { */ Page getMemberCouponsPage(Page page, MemberCouponSearchParams param); + /** + * 获取会员领取过的优惠券数量 + */ + long getMemberCouponNum(String memberId, String couponId); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java index fa75898c..8d13a2e2 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java @@ -192,6 +192,9 @@ public abstract class AbstractPromotionsServiceImpl, T e @Override public void checkPromotions(T promotions) { PromotionTools.checkPromotionTime(promotions.getStartTime(), promotions.getEndTime()); + if (!this.allowExistSame()) { + this.checkSamePromotions(promotions); + } } /** @@ -264,4 +267,21 @@ public abstract class AbstractPromotionsServiceImpl, T e } } + @Override + public boolean allowExistSame() { + return false; + } + + public void checkSamePromotions(T promotions) { + if (promotions.getStartTime() == null || promotions.getEndTime() == null) { + return; + } + QueryWrapper queryWrapper = PromotionTools.checkActiveTime(promotions.getStartTime(), promotions.getEndTime(), this.getPromotionType(), promotions.getStoreId(), promotions.getId()); + long sameNum = this.count(queryWrapper); + //当前时间段是否存在同类活动 + if (sameNum > 0) { + throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); + } + } + } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java index 7592db71..88259b66 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java @@ -310,11 +310,11 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl promotionGoodsList = PromotionTools.promotionGoodsInit(fullDiscountVO.getPromotionGoodsList(), fullDiscountVO, PromotionTypeEnum.FULL_DISCOUNT); + List promotionGoodsList = + PromotionTools.promotionGoodsInit(fullDiscountVO.getPromotionGoodsList(), fullDiscountVO, + PromotionTypeEnum.FULL_DISCOUNT); this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId())); //促销活动商品更新 result = this.promotionGoodsService.saveBatch(promotionGoodsList); @@ -166,8 +163,7 @@ public class FullDiscountServiceImpl extends AbstractPromotionsServiceImpl queryWrapper = PromotionTools.checkActiveTime(statTime, endTime, PromotionTypeEnum.FULL_DISCOUNT, storeId, id); - long sameNum = this.count(queryWrapper); - if (sameNum > 0) { - throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); - } - } - /** * 检查优惠券信息 * diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/MemberCouponServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/MemberCouponServiceImpl.java index 467d4862..b4d643ae 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/MemberCouponServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/MemberCouponServiceImpl.java @@ -327,6 +327,14 @@ public class MemberCouponServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(MemberCoupon::getMemberId, memberId); + queryWrapper.eq(MemberCoupon::getCouponId, couponId); + return this.count(queryWrapper); + } + /** * 清除无效的会员优惠券 * diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java index 51e60018..108931e9 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java @@ -31,12 +31,10 @@ import cn.lili.trigger.interfaces.TimeTrigger; import cn.lili.trigger.model.TimeExecuteConstant; import cn.lili.trigger.model.TimeTriggerMsg; import cn.lili.trigger.util.DelayQueueTools; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; -import java.util.Date; import java.util.List; /** @@ -156,48 +154,6 @@ public class PintuanServiceImpl extends AbstractPromotionsServiceImpl ids, Long startTime, Long endTime) { - if (startTime != null && endTime != null) { - for (String id : ids) { - Pintuan pintuan = this.getById(id); - QueryWrapper queryWrapper = PromotionTools.checkActiveTime(new Date(startTime), new Date(endTime), PromotionTypeEnum.PINTUAN, pintuan.getStoreId(), id); - long sameNum = this.count(queryWrapper); - //当前时间段是否存在同类活动 - if (sameNum > 0) { - throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); - } - } - } - - return super.updateStatus(ids, startTime, endTime); - } - - /** - * 检查促销参数 - * - * @param promotions 促销实体 - */ - @Override - public void checkPromotions(Pintuan promotions) { - QueryWrapper queryWrapper = PromotionTools.checkActiveTime(promotions.getStartTime(), promotions.getEndTime(), PromotionTypeEnum.PINTUAN, promotions.getStoreId(), promotions.getId()); - long sameNum = this.count(queryWrapper); - //当前时间段是否存在同类活动 - if (sameNum > 0) { - throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); - } - super.checkPromotions(promotions); - } - /** * 更新促销商品信息 * diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java index 2be950f4..f61c3e38 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java @@ -74,7 +74,8 @@ public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl queryWrapper = PromotionTools.checkActiveTime(promotions.getStartTime(), promotions.getEndTime(), PromotionTypeEnum.SECKILL, null, promotions.getId()); - long sameNum = this.count(queryWrapper); - //当前时间段是否存在同类活动 - if (sameNum > 0) { - throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); - } - } - - } /** diff --git a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java index 19b52cc0..6dc91f2f 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java +++ b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java @@ -34,6 +34,10 @@ public class PromotionTools { public static final String PLATFORM_ID = "0"; public static final String PLATFORM_NAME = "platform"; + private PromotionTools() { + throw new IllegalStateException("Utility class"); + } + /** * 参数验证 * 1、活动起始时间必须大于当前时间 @@ -87,13 +91,43 @@ public class PromotionTools { } else { queryWrapper.ge(START_TIME_COLUMN, DateUtil.beginOfDay(startTime)).le(END_TIME_COLUMN, DateUtil.endOfDay(endTime)); } - queryWrapper.eq(CharSequenceUtil.isNotEmpty(storeId), "store_id", storeId); - queryWrapper.ne(CharSequenceUtil.isNotEmpty(activityId), "id", activityId); + if (storeId != null) { + queryWrapper.eq("store_id", storeId); + } + if (activityId != null) { + queryWrapper.ne("id", activityId); + } queryWrapper.and(i -> i.or(queryPromotionStatus(PromotionsStatusEnum.NEW)).or(queryPromotionStatus(PromotionsStatusEnum.START))); queryWrapper.eq("delete_flag", false); return queryWrapper; } + /** + * 检查商品是否重复参加同类型活动 + * + * @param exceptType 排除的促销活动类型(可同时参加的活动类型) + * @param skuIds 商品skuId + * @param activityId 当前活动id + * @return mybatis plus query wrapper对象 + */ + public static QueryWrapper checkSkuDuplicate(List exceptType, List skuIds, String activityId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (skuIds != null && !skuIds.isEmpty()) { + queryWrapper.in("sku_id", skuIds); + } + if (CharSequenceUtil.isNotEmpty(activityId)) { + queryWrapper.ne("id", activityId); + } + queryWrapper.and(i -> i.or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)).or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW))); + + if (exceptType != null) { + queryWrapper.notIn(!exceptType.isEmpty(), "promotion_type", exceptType.stream().map(PromotionTypeEnum::name).collect(Collectors.toList())); + } + queryWrapper.eq("delete_flag", false); + + return queryWrapper; + } + public static Consumer> queryPromotionStatus(PromotionsStatusEnum promotionsStatusEnum) { switch (promotionsStatusEnum) { @@ -158,6 +192,12 @@ public class PromotionTools { return nextHour; } + /** + * 过滤无效促销活动 + * + * @param map 促销活动map + * @return 过滤后的促销活动map + */ public static Map filterInvalidPromotionsMap(Map map) { if (CollUtil.isEmpty(map)) { return new HashMap<>(); @@ -173,9 +213,22 @@ public class PromotionTools { return i.getValue() != null; }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> newValue)); } catch (Exception e) { - log.error("过滤无效促销活动出现异常。异常促销信息:{},异常信息:{} ", map, e); + log.error("过滤无效促销活动出现异常。异常促销信息:{},异常信息 ", map, e); return new HashMap<>(); } } + /** + * 是否为需要检查的促销活动类型(用于判定部分类型的商品不能参与活动的条件) + * 内容为不需要检查的促销活动类型 + * + * @param key 促销key + * @return 当前促销key是否存在 + */ + public static boolean isPromotionsTypeNeedsToChecked(String key) { + return !CharSequenceUtil.containsAny(key, + PromotionTypeEnum.COUPON.name(), + PromotionTypeEnum.FULL_DISCOUNT.name()); + } + } diff --git a/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java b/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java index b0cf8c4b..1eeb7710 100644 --- a/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java +++ b/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java @@ -58,6 +58,24 @@ public class EsGoodsSearchDTO { @ApiModelProperty(value = "促销活动id") private String promotionsId; + /** + * @see cn.lili.modules.goods.entity.enums.GoodsTypeEnum + */ + @ApiModelProperty(value = "商品类型") + private String goodsType; + + @ApiModelProperty("销售模式") + private String salesModel; + + /** + * @see cn.lili.modules.goods.entity.enums.GoodsTypeEnum + */ + @ApiModelProperty(value = "除了当前商品类型之外") + private String neGoodsType; + + @ApiModelProperty("除了销售模式当前销售模式之外") + private String neSalesModel; + //过滤搜索关键字 public String getKeyword() { if (CharSequenceUtil.isNotEmpty(keyword)) { diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index a8848ff8..6a77c8e5 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -22,6 +22,7 @@ import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsParamsDTO; import cn.lili.modules.goods.entity.dto.GoodsSkuDTO; 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.service.BrandService; import cn.lili.modules.goods.service.CategoryService; @@ -542,6 +543,10 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements public UpdateRequest updateEsGoodsIndexPromotions(String id, BasePromotions promotion, String key) { EsGoodsIndex goodsIndex = findById(id); if (goodsIndex != null) { + // 批发商品不参与促销(除优惠券和满减) + if (PromotionTools.isPromotionsTypeNeedsToChecked(key) && GoodsSalesModeEnum.WHOLESALE.name().equals(goodsIndex.getSalesModel())) { + return null; + } //更新索引 return this.updateGoodsIndexPromotion(goodsIndex, key, promotion); } else { @@ -610,24 +615,23 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements private void executeUpdateEsGoodsIndexAll(BasePromotions promotion, String key) { for (int i = 0; ; i++) { List skuIds; + PageVO pageVO = new PageVO(); + pageVO.setPageNumber(i); + pageVO.setPageSize(1000); + EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO(); + if (PromotionTools.isPromotionsTypeNeedsToChecked(key)) { + searchDTO.setSalesModel(GoodsSalesModeEnum.RETAIL.name()); + } //如果storeId不为空,则表示是店铺活动 if (promotion.getStoreId() != null && !promotion.getStoreId().equals(PromotionTools.PLATFORM_ID)) { - PageVO pageVO = new PageVO(); - pageVO.setPageNumber(i); - pageVO.setPageSize(1000); - EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO(); searchDTO.setStoreId(promotion.getStoreId()); - //查询出店铺商品 - SearchPage esGoodsIndices = goodsSearchService.searchGoods(searchDTO, pageVO); - - skuIds = esGoodsIndices.isEmpty() ? new ArrayList<>() : esGoodsIndices.getContent().stream().map(SearchHit::getId).collect(Collectors.toList()); - } else { - //否则是平台活动 - org.springframework.data.domain.Page all = goodsIndexRepository.findAll(PageRequest.of(i, 1000)); - - //查询出全部商品 - skuIds = all.isEmpty() ? new ArrayList<>() : all.toList().stream().map(EsGoodsIndex::getId).collect(Collectors.toList()); } + + //查询出店铺商品 + SearchPage esGoodsIndices = goodsSearchService.searchGoods(searchDTO, pageVO); + + skuIds = esGoodsIndices.isEmpty() ? new ArrayList<>() : + esGoodsIndices.getContent().stream().map(SearchHit::getId).collect(Collectors.toList()); if (skuIds.isEmpty()) { break; } diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java index 114109f8..6078d77e 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java @@ -466,6 +466,20 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { if (searchDTO.getRecommend() != null) { filterBuilder.filter(QueryBuilders.termQuery("recommend", searchDTO.getRecommend())); } + // 商品类型判定 + if (CharSequenceUtil.isNotEmpty(searchDTO.getGoodsType())) { + filterBuilder.filter(QueryBuilders.termQuery("goodsType", searchDTO.getGoodsType())); + } + if (CharSequenceUtil.isNotEmpty(searchDTO.getNeGoodsType())) { + filterBuilder.mustNot(QueryBuilders.termQuery("goodsType", searchDTO.getNeGoodsType())); + } + // 销售类型判定 + if (CharSequenceUtil.isNotEmpty(searchDTO.getSalesModel())) { + filterBuilder.filter(QueryBuilders.termQuery("salesModel", searchDTO.getSalesModel())); + } + if (CharSequenceUtil.isNotEmpty(searchDTO.getNeSalesModel())) { + filterBuilder.mustNot(QueryBuilders.termQuery("salesModel", searchDTO.getNeSalesModel())); + } //规格项判定 if (searchDTO.getNameIds() != null && !searchDTO.getNameIds().isEmpty()) { filterBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termsQuery("attrList.nameId", searchDTO.getNameIds()), ScoreMode.None));