diff --git a/buyer-api/src/main/java/cn/lili/controller/promotion/PointsGoodsBuyerController.java b/buyer-api/src/main/java/cn/lili/controller/promotion/PointsGoodsBuyerController.java index e4cd94d1..4dc38065 100644 --- a/buyer-api/src/main/java/cn/lili/controller/promotion/PointsGoodsBuyerController.java +++ b/buyer-api/src/main/java/cn/lili/controller/promotion/PointsGoodsBuyerController.java @@ -5,6 +5,7 @@ import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.promotion.entity.dos.PointsGoods; import cn.lili.modules.promotion.entity.dos.PointsGoodsCategory; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.entity.vos.PointsGoodsSearchParams; import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; import cn.lili.modules.promotion.service.PointsGoodsCategoryService; @@ -37,6 +38,7 @@ public class PointsGoodsBuyerController { @GetMapping @ApiOperation(value = "分页获取积分商品") public ResultMessage> getPointsGoodsPage(PointsGoodsSearchParams searchParams, PageVO page) { + searchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); IPage pointsGoodsByPage = pointsGoodsService.pageFindAll(searchParams, page); return ResultUtil.data(pointsGoodsByPage); } diff --git a/consumer/src/main/java/cn/lili/event/impl/RegisteredCouponActivityExecute.java b/consumer/src/main/java/cn/lili/event/impl/RegisteredCouponActivityExecute.java index 75d2ad21..a103b767 100644 --- a/consumer/src/main/java/cn/lili/event/impl/RegisteredCouponActivityExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/RegisteredCouponActivityExecute.java @@ -1,18 +1,16 @@ package cn.lili.event.impl; -import cn.hutool.core.date.DateUtil; import cn.lili.event.MemberRegisterEvent; import cn.lili.modules.member.entity.dos.Member; import cn.lili.modules.promotion.entity.dos.CouponActivity; -import cn.lili.modules.promotion.entity.dto.BasePromotions; import cn.lili.modules.promotion.entity.enums.CouponActivityTypeEnum; import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.service.CouponActivityService; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import cn.lili.modules.promotion.tools.PromotionTools; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.Date; import java.util.List; /** @@ -35,10 +33,9 @@ public class RegisteredCouponActivityExecute implements MemberRegisterEvent { */ @Override public void memberRegister(Member member) { - List couponActivities = couponActivityService.list(new LambdaQueryWrapper() - .eq(CouponActivity::getCouponActivityType, CouponActivityTypeEnum.REGISTERED.name()) - .ge(BasePromotions::getEndTime, new Date()) - .le(BasePromotions::getStartTime, new Date())); + List couponActivities = couponActivityService.list(new QueryWrapper() + .eq("coupon_activity_type", CouponActivityTypeEnum.REGISTERED.name()) + .and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START))); couponActivityService.registered(couponActivities, member); } } diff --git a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java index 3c1095e1..3900de1f 100644 --- a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java +++ b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java @@ -27,6 +27,7 @@ import cn.lili.modules.promotion.entity.dto.BasePromotions; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import cn.lili.modules.promotion.service.PromotionGoodsService; +import cn.lili.modules.promotion.service.PromotionService; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.modules.store.service.StoreService; @@ -113,6 +114,9 @@ public class GoodsMessageListener implements RocketMQListener { @Autowired private StoreGoodsLabelService storeGoodsLabelService; + @Autowired + private PromotionService promotionService; + @Autowired private PromotionGoodsService promotionGoodsService; @@ -362,6 +366,11 @@ public class GoodsMessageListener implements RocketMQListener { goodsIndex.setStoreCategoryNamePath(ArrayUtil.join(storeGoodsLabels.stream().map(StoreGoodsLabel::getLabelName).toArray(), ",")); } } + + if (goodsIndex.getPromotionMap() == null || goodsIndex.getPromotionMap().isEmpty()) { + Map goodsCurrentPromotionMap = promotionService.getGoodsPromotionMap(goodsIndex); + goodsIndex.setPromotionMap(goodsCurrentPromotionMap); + } } 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 264b36fc..6b621a35 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -67,6 +67,7 @@ public enum ResultCode { GOODS_AUTH_ERROR(11005, "商品审核失败"), POINT_GOODS_ERROR(11006, "积分商品业务异常,请稍后重试"), POINT_GOODS_NOT_EXIST(11020, "积分商品不存在"), + POINT_GOODS_CATEGORY_EXIST(11021, "当前积分商品分类已存在"), GOODS_SKU_SN_ERROR(11007, "商品SKU货号不能为空"), GOODS_SKU_PRICE_ERROR(11008, "商品SKU价格不能小于等于0"), GOODS_SKU_COST_ERROR(11009, "商品SKU成本价不能小于等于0"), @@ -179,6 +180,7 @@ public enum ResultCode { ORDER_CAN_NOT_CANCEL(31012, "当前订单状态不可取消"), ORDER_BATCH_DELIVER_ERROR(31013, "批量发货,文件读取失败"), ORDER_ITEM_NOT_EXIST(31014, "当前订单项不存在!"), + POINT_NOT_ENOUGH(31015, "当前会员积分不足购买当前积分商品!"), /** diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java b/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java index bc50c52d..205672c0 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java @@ -8,6 +8,7 @@ import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.modules.goods.entity.dto.GoodsOperationDTO; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; +import cn.lili.modules.goods.entity.enums.GoodsTypeEnum; import cn.lili.mybatis.BaseEntity; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -181,7 +182,7 @@ public class Goods extends BaseEntity { throw new ServiceException(ResultCode.GOODS_SKU_COST_ERROR); } //虚拟商品没有重量字段 - if (!sku.containsKey("weight") || sku.containsKey("weight") && (StringUtil.isEmpty(sku.get("weight").toString()) || Convert.toDouble(sku.get("weight").toString()) < 0)) { + if (this.goodsType.equals(GoodsTypeEnum.PHYSICAL_GOODS.name()) && (!sku.containsKey("weight") || sku.containsKey("weight") && (StringUtil.isEmpty(sku.get("weight").toString()) || Convert.toDouble(sku.get("weight").toString()) < 0))) { throw new ServiceException(ResultCode.GOODS_SKU_WEIGHT_ERROR); } if (!sku.containsKey("quantity") || StringUtil.isEmpty(sku.get("quantity").toString()) || Convert.toInt(sku.get("quantity").toString()) < 0) { diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 30bcd611..37d3268c 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -241,7 +241,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //获取当前商品的索引信息 EsGoodsIndex goodsIndex = goodsIndexService.findById(skuId); if (goodsIndex == null) { - goodsIndex = goodsIndexService.resetEsGoodsIndex(goodsSku, goodsVO.getGoodsParamsDTOList()); + goodsIndex = goodsIndexService.getTempEsGoodsIndex(goodsSku, goodsVO.getGoodsParamsDTOList()); //发送mq消息 String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.RESET_GOODS_INDEX.name(); diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartVO.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartVO.java index 4f60aa4a..9da4da6a 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartVO.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartVO.java @@ -85,6 +85,7 @@ public class CartVO extends CartBase implements Serializable { this.setCouponList(new ArrayList<>()); this.setGiftList(new ArrayList<>()); this.setGiftCouponList(new ArrayList<>()); + this.setCanReceiveCoupon(new ArrayList<>()); this.setChecked(false); this.isFull = false; this.weight = 0d; diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/RenderStepStatement.java b/framework/src/main/java/cn/lili/modules/order/cart/render/RenderStepStatement.java index bcbfd597..f1c4c894 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/RenderStepStatement.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/RenderStepStatement.java @@ -44,6 +44,7 @@ public class RenderStepStatement { public static RenderStepEnums[] checkedSingleRender = { RenderStepEnums.CHECK_DATA, RenderStepEnums.SKU_PROMOTION, + RenderStepEnums.COUPON, RenderStepEnums.SKU_FREIGHT, RenderStepEnums.CART_PRICE }; diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java index 4f8ca2a5..4c40767e 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java @@ -20,9 +20,12 @@ import cn.lili.modules.order.cart.entity.vo.CartVO; import cn.lili.modules.order.cart.render.CartRenderStep; import cn.lili.modules.order.order.entity.dos.Order; import cn.lili.modules.order.order.service.OrderService; +import cn.lili.modules.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.Pintuan; import cn.lili.modules.promotion.entity.dos.PointsGoods; import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.vos.CouponVO; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,6 +42,7 @@ import java.util.stream.Collectors; * @since 2020-07-02 14:47 */ @Service +@Slf4j public class CheckDataRender implements CartRenderStep { @Autowired @@ -144,6 +148,16 @@ public class CheckDataRender implements CartRenderStep { cartVO.setDeliveryMethod(DeliveryMethodEnum.LOGISTICS.name()); } cartVO.setSkuList(storeCart.getValue()); + try { + //筛选属于当前店铺的优惠券 + storeCart.getValue().forEach(i -> i.getPromotionMap().forEach((key, value) -> { + if (key.contains(PromotionTypeEnum.COUPON.name()) && ((Coupon) value).getStoreId().equals(storeCart.getKey())) { + cartVO.getCanReceiveCoupon().add(new CouponVO((Coupon) value)); + } + })); + } catch (Exception e) { + log.error("筛选属于当前店铺的优惠券发生异常!", e); + } storeCart.getValue().stream().filter(i -> Boolean.TRUE.equals(i.getChecked())).findFirst().ifPresent(cartSkuVO -> cartVO.setChecked(true)); cartList.add(cartVO); } diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java index 3302449e..6ff74e3c 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java @@ -1,8 +1,12 @@ package cn.lili.modules.order.cart.render.impl; import cn.lili.common.enums.PromotionTypeEnum; +import cn.lili.common.enums.ResultCode; +import cn.lili.common.exception.ServiceException; import cn.lili.common.security.context.UserContext; import cn.lili.common.utils.CurrencyUtil; +import cn.lili.modules.member.entity.dos.Member; +import cn.lili.modules.member.service.MemberService; import cn.lili.modules.order.cart.entity.dto.TradeDTO; import cn.lili.modules.order.cart.entity.enums.RenderStepEnums; import cn.lili.modules.order.cart.entity.vo.CartSkuVO; @@ -34,6 +38,9 @@ public class SkuPromotionRender implements CartRenderStep { @Autowired private KanjiaActivityService kanjiaActivityService; + @Autowired + private MemberService memberService; + @Override public RenderStepEnums step() { return RenderStepEnums.SKU_PROMOTION; @@ -76,14 +83,20 @@ public class SkuPromotionRender implements CartRenderStep { //这里是双重循环,但是实际积分购买或者是砍价购买时,购物车只有一个商品,所以没有循环操作数据库或者其他的问题 case POINTS: + Member userInfo = memberService.getUserInfo(); + long totalPayPoints = 0; //处理积分商品购买 for (CartVO cartVO : tradeDTO.getCartList()) { for (CartSkuVO cartSkuVO : cartVO.getCheckedSkuList()) { cartSkuVO.getPriceDetailDTO().setPayPoint(cartSkuVO.getPoint()); PromotionSkuVO promotionSkuVO = new PromotionSkuVO(PromotionTypeEnum.POINTS_GOODS.name(), cartSkuVO.getPointsId()); cartSkuVO.getPriceDetailDTO().getJoinPromotion().add(promotionSkuVO); + totalPayPoints += cartSkuVO.getPoint(); } } + if (userInfo.getPoint() < totalPayPoints) { + throw new ServiceException(ResultCode.POINT_NOT_ENOUGH); + } return; case KANJIA: for (CartVO cartVO : tradeDTO.getCartList()) { diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java index cb406aa7..6c339a65 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java @@ -16,8 +16,10 @@ import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; +import cn.lili.modules.member.entity.dos.Member; import cn.lili.modules.member.entity.dos.MemberAddress; import cn.lili.modules.member.service.MemberAddressService; +import cn.lili.modules.member.service.MemberService; import cn.lili.modules.order.cart.entity.dto.MemberCouponDTO; import cn.lili.modules.order.cart.entity.dto.TradeDTO; import cn.lili.modules.order.cart.entity.enums.CartTypeEnum; @@ -127,34 +129,19 @@ public class CartServiceImpl implements CartService { @Autowired private TradeBuilder tradeBuilder; + @Autowired + private MemberService memberService; + @Override public void add(String skuId, Integer num, String cartType, Boolean cover) { + AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); if (num <= 0) { throw new ServiceException(ResultCode.CART_NUM_ERROR); } CartTypeEnum cartTypeEnum = getCartType(cartType); GoodsSku dataSku = checkGoods(skuId); - Map promotionMap; - EsGoodsIndex goodsIndex = goodsIndexService.findById(skuId); - if (goodsIndex == null) { - GoodsVO goodsVO = this.goodsService.getGoodsVO(dataSku.getGoodsId()); - goodsIndex = goodsIndexService.resetEsGoodsIndex(dataSku, goodsVO.getGoodsParamsDTOList()); + Map promotionMap = this.getCurrentGoodsPromotion(dataSku, cartType); - //发送mq消息 - String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.RESET_GOODS_INDEX.name(); - rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsIndex)), RocketmqSendCallbackBuilder.commonCallback()); - } - if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty()) { - if (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.SECKILL.name())) || - (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.PINTUAN.name())) - && CartTypeEnum.PINTUAN.name().equals(cartType))) { - dataSku.setPromotionFlag(true); - dataSku.setPromotionPrice(goodsIndex.getPromotionPrice()); - } - promotionMap = goodsIndex.getPromotionMap(); - } else { - promotionMap = null; - } try { //购物车方式购买需要保存之前的选择,其他方式购买,则直接抹除掉之前的记录 TradeDTO tradeDTO; @@ -200,7 +187,6 @@ public class CartServiceImpl implements CartService { cartSkuVO.setChecked(true); } else { tradeDTO = new TradeDTO(cartTypeEnum); - AuthUser currentUser = UserContext.getCurrentUser(); tradeDTO.setMemberId(currentUser.getId()); tradeDTO.setMemberName(currentUser.getUsername()); List cartSkuVOS = tradeDTO.getSkuList(); @@ -569,6 +555,31 @@ public class CartServiceImpl implements CartService { return trade; } + private Map getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) { + Map promotionMap; + EsGoodsIndex goodsIndex = goodsIndexService.findById(dataSku.getId()); + if (goodsIndex == null) { + GoodsVO goodsVO = this.goodsService.getGoodsVO(dataSku.getGoodsId()); + goodsIndex = goodsIndexService.getTempEsGoodsIndex(dataSku, goodsVO.getGoodsParamsDTOList()); + + //发送mq消息 + String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.RESET_GOODS_INDEX.name(); + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsIndex)), RocketmqSendCallbackBuilder.commonCallback()); + } + if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty()) { + if (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.SECKILL.name())) || + (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.PINTUAN.name())) + && CartTypeEnum.PINTUAN.name().equals(cartType))) { + dataSku.setPromotionFlag(true); + dataSku.setPromotionPrice(goodsIndex.getPromotionPrice()); + } + promotionMap = goodsIndex.getPromotionMap(); + } else { + promotionMap = null; + } + return promotionMap; + } + /** * 获取购物车类型 @@ -763,7 +774,10 @@ public class CartServiceImpl implements CartService { PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetailBySkuId(cartSkuVO.getGoodsSku().getId()); if (pointsGoodsVO != null) { - + Member userInfo = memberService.getUserInfo(); + if (userInfo.getPoint() < pointsGoodsVO.getPoints()) { + throw new ServiceException(ResultCode.POINT_NOT_ENOUGH); + } if (pointsGoodsVO.getActiveStock() < 1) { throw new ServiceException(ResultCode.POINT_GOODS_ACTIVE_STOCK_INSUFFICIENT); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PromotionGoods.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PromotionGoods.java index 2475528d..427bccb7 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PromotionGoods.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PromotionGoods.java @@ -121,15 +121,22 @@ public class PromotionGoods extends BaseEntity { this.promotionId = pointsGoods.getId(); this.quantity = pointsGoods.getActiveStock(); this.originalPrice = sku.getPrice(); + this.promotionType = PromotionTypeEnum.POINTS_GOODS.name(); + this.scopeId = sku.getId(); } } - public PromotionGoods(KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO) { if (kanjiaActivityGoodsDTO != null) { BeanUtil.copyProperties(kanjiaActivityGoodsDTO, this, "id"); BeanUtil.copyProperties(kanjiaActivityGoodsDTO.getGoodsSku(), this, "id"); + this.setQuantity(kanjiaActivityGoodsDTO.getStock()); + this.setPromotionId(kanjiaActivityGoodsDTO.getId()); + this.setPromotionType(PromotionTypeEnum.KANJIA.name()); + this.setTitle(PromotionTypeEnum.KANJIA.name() + "-" + kanjiaActivityGoodsDTO.getGoodsName()); + this.setScopeType(PromotionsScopeTypeEnum.PORTION_GOODS.name()); + this.setPromotionType(PromotionTypeEnum.KANJIA.name()); } } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java index 6ed0dfaf..54c0230d 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java @@ -5,6 +5,7 @@ import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.lili.modules.promotion.entity.dto.BasePromotions; import cn.lili.modules.promotion.entity.vos.SeckillVO; +import cn.lili.modules.promotion.tools.PromotionTools; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; @@ -61,8 +62,8 @@ public class Seckill extends BasePromotions { this.seckillRule = seckillRule; this.goodsNum = 0; //BasePromotion - this.setStoreName("platform"); - this.setStoreId("platform"); + this.setStoreName(PromotionTools.PLATFORM_NAME); + this.setStoreId(PromotionTools.PLATFORM_ID); this.setPromotionName(DateUtil.formatDate(dateTime) + " 秒杀活动"); this.setStartTime(dateTime); this.setEndTime(DateUtil.endOfDay(dateTime)); diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/BasePromotionsSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/BasePromotionsSearchParams.java index 6c73c83f..5999e332 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/BasePromotionsSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/BasePromotionsSearchParams.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.Arrays; import java.util.Date; /** @@ -29,7 +30,7 @@ public class BasePromotionsSearchParams { /** * @see PromotionsStatusEnum */ - @ApiModelProperty(value = "活动状态") + @ApiModelProperty(value = "活动状态 如需同时判断多个活动状态','分割") private String promotionStatus; /** @@ -38,6 +39,9 @@ public class BasePromotionsSearchParams { @ApiModelProperty(value = "关联范围类型") private String scopeType; + @ApiModelProperty(value = "店铺编号 如有多个','分割") + private String storeId; + public QueryWrapper queryWrapper() { QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -51,11 +55,18 @@ public class BasePromotionsSearchParams { queryWrapper.le("end_time", new Date(endTime)); } if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.valueOf(promotionStatus))); + queryWrapper.and(i -> { + for (String status : promotionStatus.split(",")) { + i.or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.valueOf(status))); + } + }); } if (CharSequenceUtil.isNotEmpty(scopeType)) { queryWrapper.eq("scope_type", scopeType); } + if (CharSequenceUtil.isNotEmpty(storeId)) { + queryWrapper.in("store_id", Arrays.asList(storeId.split(","))); + } queryWrapper.eq("delete_flag", false); return queryWrapper; } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponSearchParams.java index 17c95a1b..a57b6b85 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponSearchParams.java @@ -9,7 +9,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serializable; -import java.util.Arrays; import java.util.Date; /** @@ -27,9 +26,6 @@ public class CouponSearchParams extends BasePromotionsSearchParams implements Se private static final String PRICE_COLUMN = "price"; private static final String RANGE_DAY_TYPE_COLUMN = "range_day_type"; - @ApiModelProperty(value = "店铺编号") - private String storeId; - @ApiModelProperty(value = "会员id") private String memberId; @@ -69,10 +65,7 @@ public class CouponSearchParams extends BasePromotionsSearchParams implements Se @Override public QueryWrapper queryWrapper() { - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (storeId != null) { - queryWrapper.in("store_id", Arrays.asList(storeId.split(","))); - } + QueryWrapper queryWrapper = super.queryWrapper(); if (CharSequenceUtil.isNotEmpty(couponName)) { queryWrapper.like("coupon_name", couponName); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/FullDiscountSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/FullDiscountSearchParams.java index 7dc41e69..d1f0adb5 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/FullDiscountSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/FullDiscountSearchParams.java @@ -7,7 +7,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serializable; -import java.util.Arrays; /** * 满优惠查询通用类 @@ -25,9 +24,6 @@ public class FullDiscountSearchParams extends BasePromotionsSearchParams impleme @ApiModelProperty(value = "活动名称") private String promotionName; - @ApiModelProperty(value = "店铺编号 如有多个','分割") - private String storeId; - @ApiModelProperty(value = "是否赠优惠券") private Boolean couponFlag; @@ -40,9 +36,6 @@ public class FullDiscountSearchParams extends BasePromotionsSearchParams impleme if (CharSequenceUtil.isNotEmpty(promotionName)) { queryWrapper.like("title", promotionName); } - if (storeId != null) { - queryWrapper.in("store_id", Arrays.asList(storeId.split(","))); - } if (couponFlag != null) { queryWrapper.eq("coupon_flag", couponFlag); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java index 36069bf5..c49cf6af 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java @@ -18,9 +18,6 @@ import javax.validation.constraints.NotEmpty; @Data public class PintuanSearchParams extends BasePromotionsSearchParams { - @ApiModelProperty(value = "商家id") - private String storeId; - @ApiModelProperty(value = "商家名称,如果是平台,这个值为 platform") private String storeName; @@ -38,9 +35,6 @@ public class PintuanSearchParams extends BasePromotionsSearchParams { if (CharSequenceUtil.isNotEmpty(storeName)) { queryWrapper.like("store_name", storeName); } - if (CharSequenceUtil.isNotEmpty(storeId)) { - queryWrapper.eq("store_id", storeId); - } return queryWrapper; } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PromotionGoodsSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PromotionGoodsSearchParams.java index f1661f06..b3da07fc 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PromotionGoodsSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PromotionGoodsSearchParams.java @@ -26,9 +26,6 @@ public class PromotionGoodsSearchParams extends BasePromotionsSearchParams { @ApiModelProperty(value = "促销类型") private String promotionType; - @ApiModelProperty(value = "商品活动id") - private String storeId; - @ApiModelProperty(value = "商品名称") private String goodsName; @@ -63,9 +60,6 @@ public class PromotionGoodsSearchParams extends BasePromotionsSearchParams { if (CharSequenceUtil.isNotEmpty(categoryPath)) { queryWrapper.like("category_path", categoryPath); } - if (CharSequenceUtil.isNotEmpty(storeId)) { - queryWrapper.in("store_id", Arrays.asList(storeId.split(","))); - } if (CharSequenceUtil.isNotEmpty(skuId)) { queryWrapper.in("sku_id", Arrays.asList(skuId.split(","))); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/SeckillSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/SeckillSearchParams.java index bebeac2f..a19f4ec7 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/SeckillSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/SeckillSearchParams.java @@ -34,9 +34,6 @@ public class SeckillSearchParams extends BasePromotionsSearchParams implements S @ApiModelProperty(value = "商家id") private String[] storeIds; - @ApiModelProperty(value = "商家编号") - private String storeId; - @ApiModelProperty(value = "商品名称") private String goodsName; diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java index eb1063b7..93a186d1 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java @@ -3,7 +3,6 @@ package cn.lili.modules.promotion.service; import cn.lili.cache.CachePrefix; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.vo.PageVO; -import cn.lili.modules.order.cart.entity.vo.CartSkuVO; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -34,19 +33,13 @@ public interface PromotionGoodsService extends IService { } /** - * 更新促销活动 - * - * @param cartSkuVO 购物车中的产品 - */ - void updatePromotion(CartSkuVO cartSkuVO); - - /** - * 获取某sku当日所有活动 + * 获取某sku所有有效活动 * * @param skuId 商品skuId + * @param storeIds 店铺id * @return 促销商品集合 */ - List findNowSkuPromotion(String skuId); + List findSkuValidPromotion(String skuId, String storeIds); /** * 分页获取促销商品信息 diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionService.java b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionService.java index 99f2d01a..2349f055 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionService.java @@ -25,6 +25,6 @@ public interface PromotionService { * @param index 商品索引 * @return 当前促销活动集合 */ - Map getGoodsCurrentPromotionMap(EsGoodsIndex index); + Map getGoodsPromotionMap(EsGoodsIndex index); } \ 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 5b617f98..5264f309 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 @@ -220,8 +220,9 @@ public abstract class AbstractPromotionsServiceImpl, T e this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId())); return; } - if (PromotionsScopeTypeEnum.ALL.name().equals(promotions.getScopeType())) { + if (CharSequenceUtil.equalsAny(promotions.getScopeType(), PromotionsScopeTypeEnum.ALL.name(), PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name())) { PromotionGoods promotionGoods = new PromotionGoods(); + promotionGoods.setScopeId(promotions.getScopeId()); promotionGoods.setScopeType(promotions.getScopeType()); promotionGoods.setPromotionId(promotions.getId()); promotionGoods.setStoreId(promotions.getStoreId()); diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java index e98c9306..f9a99c45 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java @@ -19,6 +19,7 @@ import cn.lili.modules.promotion.service.CouponActivityItemService; import cn.lili.modules.promotion.service.CouponActivityService; import cn.lili.modules.promotion.service.CouponService; import cn.lili.modules.promotion.service.MemberCouponService; +import cn.lili.modules.promotion.tools.PromotionTools; import groovy.util.logging.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -203,7 +204,7 @@ public class CouponActivityServiceImpl extends AbstractPromotionsServiceImpl fullDiscounts = fullDiscountService.listFindAll(searchParams); if (fullDiscounts != null && !fullDiscounts.isEmpty()) { throw new ServiceException("当前优惠券参与了促销活动【" + fullDiscounts.get(0).getPromotionName() + "】不能进行编辑删除操作"); @@ -228,6 +229,10 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl promotionGoodsList = PromotionTools.promotionGoodsInit(couponVO.getPromotionGoodsList(), couponVO, this.getPromotionType()); + for (PromotionGoods promotionGoods : promotionGoodsList) { + promotionGoods.setStoreId(promotions.getStoreId()); + promotionGoods.setStoreName(promotions.getStoreName()); + } //促销活动商品更新 this.promotionGoodsService.saveBatch(promotionGoodsList); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/KanjiaActivityGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/KanjiaActivityGoodsServiceImpl.java index 662853d5..e36027ac 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/KanjiaActivityGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/KanjiaActivityGoodsServiceImpl.java @@ -11,7 +11,6 @@ import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.promotion.entity.dos.KanjiaActivityGoods; import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.dto.BasePromotions; import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO; import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsOperationDTO; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; @@ -268,7 +267,8 @@ public class KanjiaActivityGoodsServiceImpl extends AbstractPromotionsServiceImp throw new ServiceException("商品id为" + goodsSku.getId() + "的商品已参加砍价商品活动!"); } this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(kanJiaActivityGoodsDTO.getId())); - this.updatePromotionsGoods(kanJiaActivityGoodsDTO); + PromotionGoods promotionGoods = new PromotionGoods(kanJiaActivityGoodsDTO); + this.promotionGoodsService.save(promotionGoods); this.updateEsGoodsIndex(kanJiaActivityGoodsDTO); //修改数据库 return this.updateById(kanJiaActivityGoodsDTO); 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 e2c7f024..0b305710 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 @@ -15,6 +15,7 @@ import cn.lili.modules.promotion.entity.vos.CouponSearchParams; import cn.lili.modules.promotion.mapper.MemberCouponMapper; import cn.lili.modules.promotion.service.CouponService; import cn.lili.modules.promotion.service.MemberCouponService; +import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -118,7 +119,7 @@ public class MemberCouponServiceImpl extends ServiceImpl getMemberCouponsByCanUse(CouponSearchParams param, Double totalPrice, PageVO pageVo) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); List storeIds = new ArrayList<>(Arrays.asList(param.getStoreId().split(","))); - storeIds.add("platform"); + storeIds.add(PromotionTools.PLATFORM_ID); queryWrapper.in(MemberCoupon::getStoreId, storeIds); queryWrapper.eq(MemberCoupon::getMemberId, param.getMemberId()); queryWrapper.and( @@ -253,7 +254,7 @@ public class MemberCouponServiceImpl extends ServiceImpl().eq(PointsGoods::getSkuId, skuId), false); + QueryWrapper queryWrapper = new QueryWrapper().eq("sku_id", skuId); + queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); + PointsGoods pointsGoods = this.getOne(queryWrapper, false); if (pointsGoods == null) { log.error("skuId为" + skuId + "的积分商品不存在!"); throw new ServiceException(); @@ -208,7 +206,7 @@ public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl().eq(PromotionGoods::getPromotionId, promotions.getId())); + this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId())); this.promotionGoodsService.save(new PromotionGoods(promotions, this.checkSkuExist(promotions.getSkuId()))); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java index 2dc9ff90..a827e99c 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java @@ -5,18 +5,13 @@ import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; -import cn.lili.common.utils.DateUtil; import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.service.GoodsSkuService; -import cn.lili.modules.order.cart.entity.vo.CartSkuVO; -import cn.lili.modules.promotion.entity.dos.Coupon; -import cn.lili.modules.promotion.entity.dos.FullDiscount; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.SeckillApply; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; -import cn.lili.modules.promotion.entity.vos.BasePromotionsSearchParams; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import cn.lili.modules.promotion.entity.vos.SeckillSearchParams; import cn.lili.modules.promotion.mapper.PromotionGoodsMapper; @@ -37,6 +32,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; @@ -73,7 +69,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl findNowSkuPromotion(String skuId) { + public List findSkuValidPromotion(String skuId, String storeIds) { GoodsSku sku = goodsSkuService.getGoodsSkuByIdFromCache(skuId); if (sku == null) { @@ -81,48 +77,13 @@ public class PromotionGoodsServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("sku_id", skuId); - queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); - - List promotionGoods = this.list(queryWrapper); - - - BasePromotionsSearchParams searchParams = new BasePromotionsSearchParams(); - searchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); - searchParams.setScopeType(PromotionsScopeTypeEnum.ALL.name()); - //单独检查,添加适用于全品类的满优惠活动 - List fullDiscountVOS = this.fullDiscountService.listFindAll(searchParams); - for (FullDiscount fullDiscountVO : fullDiscountVOS) { - PromotionGoods p = new PromotionGoods(sku); - p.setPromotionId(fullDiscountVO.getId()); - p.setPromotionType(PromotionTypeEnum.FULL_DISCOUNT.name()); - p.setStartTime(fullDiscountVO.getStartTime()); - p.setEndTime(fullDiscountVO.getEndTime()); - promotionGoods.add(p); - } - //单独检查,添加适用于全品类的全平台或属于当前店铺的优惠券活动 - List couponVOS = this.couponService.listFindAll(searchParams); - for (Coupon couponVO : couponVOS) { - PromotionGoods p = new PromotionGoods(sku); - p.setPromotionId(couponVO.getId()); - p.setPromotionType(PromotionTypeEnum.COUPON.name()); - p.setStartTime(couponVO.getStartTime()); - p.setEndTime(couponVO.getEndTime()); - promotionGoods.add(p); - } - return promotionGoods; - } - - @Override - public void updatePromotion(CartSkuVO cartSkuVO) { - Date date = DateUtil.getCurrentDayEndTime(); - //如果商品的促销更新时间在当前时间之前,则更新促销 - if (cartSkuVO.getUpdatePromotionTime().before(date)) { - List promotionGoods = this.findNowSkuPromotion(cartSkuVO.getGoodsSku().getId()); - cartSkuVO.setPromotions(promotionGoods); - //下一次更新时间 - cartSkuVO.setUpdatePromotionTime(date); - } + queryWrapper.and(i -> i.or(j -> j.eq("sku_id", skuId)) + .or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name())) + .or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) + .and(l -> l.like("scope_id", sku.getCategoryPath()))))); + queryWrapper.and(i -> i.or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)).or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW))); + queryWrapper.in("store_id", Arrays.asList(storeIds.split(","))); + return this.list(queryWrapper); } @Override diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java index 68dea115..0bdc102a 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java @@ -2,11 +2,12 @@ package cn.lili.modules.promotion.serviceimpl; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.modules.promotion.entity.dos.*; -import cn.lili.modules.promotion.entity.enums.CouponGetEnum; -import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; -import cn.lili.modules.promotion.entity.vos.*; +import cn.lili.modules.promotion.entity.vos.FullDiscountSearchParams; +import cn.lili.modules.promotion.entity.vos.PintuanSearchParams; +import cn.lili.modules.promotion.entity.vos.SeckillSearchParams; import cn.lili.modules.promotion.service.*; +import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -111,33 +112,10 @@ public class PromotionServiceImpl implements PromotionService { * @return 当前促销活动集合 */ @Override - public Map getGoodsCurrentPromotionMap(EsGoodsIndex index) { + public Map getGoodsPromotionMap(EsGoodsIndex index) { + String storeIds = index.getStoreId() + "," + PromotionTools.PLATFORM_ID; Map promotionMap = new HashMap<>(); - FullDiscountSearchParams fullDiscountSearchParams = new FullDiscountSearchParams(); - fullDiscountSearchParams.setScopeType(PromotionsScopeTypeEnum.ALL.name()); - fullDiscountSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); - List fullDiscountVOS = this.fullDiscountService.listFindAll(fullDiscountSearchParams); - for (FullDiscount fullDiscount : fullDiscountVOS) { - if (index.getStoreId().equals(fullDiscount.getStoreId())) { - String fullDiscountKey = PromotionTypeEnum.FULL_DISCOUNT.name() + "-" + fullDiscount.getId(); - promotionMap.put(fullDiscountKey, fullDiscount); - } - } - CouponSearchParams couponSearchParams = new CouponSearchParams(); - couponSearchParams.setScopeType(PromotionsScopeTypeEnum.ALL.name()); - couponSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); - couponSearchParams.setGetType(CouponGetEnum.FREE.name()); - List couponVOS = this.couponService.listFindAll(couponSearchParams); - for (Coupon coupon : couponVOS) { - if (("platform").equals(coupon.getStoreId()) || index.getStoreId().equals(coupon.getStoreId())) { - String couponKey = PromotionTypeEnum.COUPON.name() + "-" + coupon.getId(); - promotionMap.put(couponKey, coupon); - } - } - PromotionGoodsSearchParams promotionGoodsSearchParams = new PromotionGoodsSearchParams(); - promotionGoodsSearchParams.setSkuId(index.getId()); - promotionGoodsSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); - List promotionGoodsList = promotionGoodsService.listFindAll(promotionGoodsSearchParams); + List promotionGoodsList = promotionGoodsService.findSkuValidPromotion(index.getId(), storeIds); for (PromotionGoods promotionGoods : promotionGoodsList) { String esPromotionKey = promotionGoods.getPromotionType() + "-" + promotionGoods.getPromotionId(); switch (PromotionTypeEnum.valueOf(promotionGoods.getPromotionType())) { diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java index fdffd2a8..2fe796ab 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java @@ -189,7 +189,6 @@ public class SeckillApplyServiceImpl extends ServiceImpl().eq(SeckillApply::getSeckillId, seckillId).in(SeckillApply::getSkuId, skuIds)); this.saveBatch(originList); - this.seckillService.updateEsGoodsSeckill(seckill, originList); //保存促销活动商品信息 if (!promotionGoodsList.isEmpty()) { PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); @@ -203,6 +202,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl seckillApplies) { if (seckillApplies != null && !seckillApplies.isEmpty()) { // 更新促销范围 - List skuIds = seckillApplies.stream().map(SeckillApply::getSkuId).collect(Collectors.toList()); - seckill.setScopeId(ArrayUtil.join(skuIds.toArray(), ",")); + seckill.setScopeId(ArrayUtil.join(seckillApplies.stream().map(SeckillApply::getSkuId).toArray(), ",")); UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.eq("id", seckill.getId()); updateWrapper.set("scope_id", seckill.getScopeId()); @@ -153,7 +151,7 @@ public class SeckillServiceImpl extends AbstractPromotionsServiceImpl map = new HashMap<>(); // es促销key map.put("esPromotionKey", promotionKey); 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 3ac5441a..b43a5839 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 @@ -2,6 +2,7 @@ package cn.lili.modules.promotion.tools; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; @@ -26,6 +27,8 @@ public class PromotionTools { public static final String START_TIME_COLUMN = "start_time"; public static final String END_TIME_COLUMN = "end_time"; + public static final String PLATFORM_ID = "platform"; + public static final String PLATFORM_NAME = "platform"; /** * 参数验证 @@ -119,7 +122,12 @@ public class PromotionTools { //本次促销商品入库 for (PromotionGoods promotionGoods : originList) { promotionGoods.setPromotionId(promotion.getId()); - promotionGoods.setStoreName(promotion.getStoreName()); + if (CharSequenceUtil.isEmpty(promotionGoods.getStoreId())) { + promotionGoods.setStoreId(promotion.getStoreId()); + } + if (CharSequenceUtil.isEmpty(promotionGoods.getStoreName())) { + promotionGoods.setStoreName(promotion.getStoreName()); + } promotionGoods.setTitle(promotion.getPromotionName()); if (promotionGoods.getStartTime() == null) { promotionGoods.setStartTime(promotion.getStartTime()); diff --git a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java index 2d70153b..9a4f4c7c 100644 --- a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java +++ b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java @@ -169,11 +169,11 @@ public interface EsGoodsIndexService { List getPromotionIdByPromotionType(String id, PromotionTypeEnum promotionTypeEnum); /** - * 重置当前商品索引 + * 获取临时拼装的商品索引 * * @param goodsSku 商品sku信息 * @param goodsParamDTOS 商品参数 * @return 商品索引 */ - EsGoodsIndex resetEsGoodsIndex(GoodsSku goodsSku, List goodsParamDTOS); + EsGoodsIndex getTempEsGoodsIndex(GoodsSku goodsSku, List goodsParamDTOS); } 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 c74b7c56..ae7f5164 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 @@ -28,6 +28,7 @@ import cn.lili.modules.promotion.entity.dos.Seckill; import cn.lili.modules.promotion.entity.dto.BasePromotions; import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.service.PromotionService; +import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import cn.lili.modules.search.entity.dto.EsGoodsSearchDTO; import cn.lili.modules.search.repository.EsGoodsIndexRepository; @@ -390,7 +391,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements public void updateEsGoodsIndexAllByList(BasePromotions promotion, String key) { List goodsIndices = new ArrayList<>(); //如果storeId不为空,则表示是店铺活动 - if (promotion.getStoreId() != null) { + if (promotion.getStoreId() != null && !promotion.getStoreId().equals(PromotionTools.PLATFORM_ID)) { EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO(); searchDTO.setStoreId(promotion.getStoreId()); //查询出店铺商品 @@ -552,17 +553,17 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements } /** - * 重置当前商品索引 + * 获取临时拼装的商品索引 * * @param goodsSku 商品sku信息 * @param goodsParamDTOS 商品参数 * @return 商品索引 */ @Override - public EsGoodsIndex resetEsGoodsIndex(GoodsSku goodsSku, List goodsParamDTOS) { + public EsGoodsIndex getTempEsGoodsIndex(GoodsSku goodsSku, List goodsParamDTOS) { EsGoodsIndex index = new EsGoodsIndex(goodsSku, goodsParamDTOS); //获取活动信息 - Map goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index); + Map goodsCurrentPromotionMap = promotionService.getGoodsPromotionMap(index); //写入促销信息 index.setPromotionMap(goodsCurrentPromotionMap); return index; @@ -588,18 +589,10 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements promotionMap = goodsIndex.getPromotionMap(); } //如果活动已结束 - if (promotion.getPromotionStatus().equals(PromotionsStatusEnum.END.name()) || promotion.getPromotionStatus().equals(PromotionsStatusEnum.CLOSE.name())) { - //如果存在活动 - if (promotionMap.containsKey(key)) { - //删除活动 - promotionMap.remove(key); - } else { - //不存在则说明是秒杀活动,尝试删除秒杀信息 - this.removePromotionKey(key, promotionMap, PromotionTypeEnum.SECKILL.name()); - } + if (promotion.getPromotionStatus().equals(PromotionsStatusEnum.END.name()) || promotion.getPromotionStatus().equals(PromotionsStatusEnum.CLOSE.name())) {//如果存在活动 + //删除活动 + promotionMap.remove(key); } else { - //添加促销活动前,如果是同一时间只可以有一个的活动,但商品索引的促销活动里存在其他(同一时间只可以有一个)的活动,则清除 - this.removePromotionKey(key, promotionMap, PromotionTypeEnum.PINTUAN.name(), PromotionTypeEnum.SECKILL.name(), PromotionTypeEnum.FULL_DISCOUNT.name()); promotionMap.put(key, promotion); } goodsIndex.setPromotionMap(promotionMap); @@ -695,7 +688,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements } } //促销索引 - Map goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index); + Map goodsCurrentPromotionMap = promotionService.getGoodsPromotionMap(index); index.setPromotionMap(goodsCurrentPromotionMap); return index; } diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/CouponManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/CouponManagerController.java index f2ed20ee..7bf896ac 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/CouponManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/CouponManagerController.java @@ -13,6 +13,7 @@ import cn.lili.modules.promotion.entity.vos.CouponSearchParams; import cn.lili.modules.promotion.entity.vos.CouponVO; import cn.lili.modules.promotion.service.CouponService; import cn.lili.modules.promotion.service.MemberCouponService; +import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -42,7 +43,7 @@ public class CouponManagerController { @ApiOperation(value = "获取优惠券列表") @GetMapping public ResultMessage> getCouponList(CouponSearchParams queryParam, PageVO page) { - queryParam.setStoreId("platform"); + queryParam.setStoreId(PromotionTools.PLATFORM_ID); return ResultUtil.data(couponService.pageVOFindAll(queryParam, page)); } @@ -111,8 +112,8 @@ public class CouponManagerController { if (currentUser == null) { throw new ServiceException(ResultCode.USER_NOT_EXIST); } - couponVO.setStoreId("platform"); - couponVO.setStoreName("platform"); + couponVO.setStoreId(PromotionTools.PLATFORM_ID); + couponVO.setStoreName(PromotionTools.PLATFORM_NAME); } } diff --git a/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java b/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java index 2efe7fcd..682b4d15 100644 --- a/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java +++ b/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java @@ -136,7 +136,7 @@ class EsTest { List esGoodsIndices = new ArrayList<>(); for (GoodsSku goodsSku : list) { EsGoodsIndex index = new EsGoodsIndex(goodsSku); - Map goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index); + Map goodsCurrentPromotionMap = promotionService.getGoodsPromotionMap(index); index.setPromotionMap(goodsCurrentPromotionMap); esGoodsIndices.add(index); cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity());