From d3fdeef0c3677f71b33f61cefcde666c8485a511 Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 19 May 2021 22:16:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=A4=9A=E9=80=89=E9=97=AE=E9=A2=98=E5=92=8C?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=8F=96=E6=B6=88=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E4=BF=83=E9=94=80=E6=B4=BB=E5=8A=A8=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=88=A0=E9=99=A4es=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E8=BF=87=E6=9C=9F=E4=BF=A1=E6=81=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/PromotionEverydayExecute.java | 7 ++++ .../serviceimpl/GoodsSkuServiceImpl.java | 2 - .../search/service/EsGoodsIndexService.java | 6 +++ .../serviceimpl/EsGoodsIndexServiceImpl.java | 37 ++++++++++++++++++- .../serviceimpl/EsGoodsSearchServiceImpl.java | 29 ++++++++++++--- 5 files changed, 72 insertions(+), 9 deletions(-) diff --git a/consumer/src/main/java/cn/lili/timetask/handler/impl/promotion/PromotionEverydayExecute.java b/consumer/src/main/java/cn/lili/timetask/handler/impl/promotion/PromotionEverydayExecute.java index f0e67719..946931a3 100644 --- a/consumer/src/main/java/cn/lili/timetask/handler/impl/promotion/PromotionEverydayExecute.java +++ b/consumer/src/main/java/cn/lili/timetask/handler/impl/promotion/PromotionEverydayExecute.java @@ -8,6 +8,7 @@ import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import cn.lili.modules.promotion.entity.vos.CouponVO; import cn.lili.modules.promotion.entity.vos.PintuanVO; import cn.lili.modules.promotion.service.*; +import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.timetask.handler.EveryDayExecute; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; @@ -34,6 +35,9 @@ public class PromotionEverydayExecute implements EveryDayExecute { //Mongo @Autowired private MongoTemplate mongoTemplate; + //es + @Autowired + private EsGoodsIndexService esGoodsIndexService; //满额活动 @Autowired private FullDiscountService fullDiscountService; @@ -74,6 +78,7 @@ public class PromotionEverydayExecute implements EveryDayExecute { if (vo.getPromotionGoodsList() != null && !vo.getPromotionGoodsList().isEmpty()) { for (PromotionGoods promotionGoods : vo.getPromotionGoodsList()) { promotionGoods.setPromotionStatus(PromotionStatusEnum.END.name()); + esGoodsIndexService.deleteEsGoodsPromotionByPromotionId(promotionGoods.getSkuId(), vo.getId()); } } mongoTemplate.save(vo); @@ -92,6 +97,7 @@ public class PromotionEverydayExecute implements EveryDayExecute { if (vo.getPromotionGoodsList() != null && !vo.getPromotionGoodsList().isEmpty()) { for (PromotionGoods promotionGoods : vo.getPromotionGoodsList()) { promotionGoods.setPromotionStatus(PromotionStatusEnum.END.name()); + esGoodsIndexService.deleteEsGoodsPromotionByPromotionId(promotionGoods.getSkuId(), vo.getId()); } } mongoTemplate.save(vo); @@ -110,6 +116,7 @@ public class PromotionEverydayExecute implements EveryDayExecute { if (vo.getPromotionGoodsList() != null && !vo.getPromotionGoodsList().isEmpty()) { for (PromotionGoods promotionGoods : vo.getPromotionGoodsList()) { promotionGoods.setPromotionStatus(PromotionStatusEnum.END.name()); + esGoodsIndexService.deleteEsGoodsPromotionByPromotionId(promotionGoods.getSkuId(), vo.getId()); } } mongoTemplate.save(vo); 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 6d63599b..311c14ea 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 @@ -438,8 +438,6 @@ public class GoodsSkuServiceImpl extends ServiceImpl i goodsIndexService.addIndex(goodsIndex); } else if (goodsSku.getQuantity() > 0 && esGoodsOld != null) { goodsIndexService.updateIndex(goodsIndex); - } else if (goodsSku.getQuantity() <= 0 && esGoodsOld != null) { - goodsIndexService.deleteIndexById(goodsSku.getId()); } //删除sku缓存 cache.remove(GoodsSkuService.getCacheKeys(goodsSku.getId())); 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 9ac0ab64..6f737c1d 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 @@ -105,6 +105,12 @@ public interface EsGoodsIndexService { */ void deleteEsGoodsPromotionIndexByList(List skuIds, PromotionTypeEnum promotionType); + /** + * 删除索引中指定的促销活动id的促销活动 + * @param skuId 商品skuId + * @param promotionId 促销活动Id + */ + void deleteEsGoodsPromotionByPromotionId(String skuId, String promotionId); /** * 清除所以商品索引的无效促销活动 */ 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 719e5a75..26c3b1ba 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 @@ -203,7 +203,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements @Override public void updateEsGoodsIndexAllByList(BasePromotion promotion, String key) { List goodsIndices; - //如果storeid不为空,则表示是店铺活动 + //如果storeId不为空,则表示是店铺活动 if (promotion.getStoreId() != null) { EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO(); searchDTO.setStoreId(promotion.getStoreId()); @@ -243,6 +243,41 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements } } + @Override + public void deleteEsGoodsPromotionByPromotionId(String skuId, String promotionId) { + if (skuId != null) { + EsGoodsIndex goodsIndex = findById(skuId); + //商品索引不为空 + if (goodsIndex != null) { + this.removePromotionByPromotionId(goodsIndex, promotionId); + } else { + log.error("更新索引商品促销信息失败!skuId 为 【{}】的索引不存在!", skuId); + } + } else { + for (EsGoodsIndex goodsIndex : this.goodsIndexRepository.findAll()) { + this.removePromotionByPromotionId(goodsIndex, promotionId); + } + } + + } + + /** + * 从索引中删除指定促销活动id的促销活动 + * + * @param goodsIndex 索引 + * @param promotionId 促销活动id + */ + private void removePromotionByPromotionId(EsGoodsIndex goodsIndex, String promotionId) { + Map promotionMap = goodsIndex.getPromotionMap(); + if (promotionMap != null && !promotionMap.isEmpty()) { + // 如果存在同类型促销活动删除 + List collect = promotionMap.keySet().stream().filter(i -> i.split("-")[1].equals(promotionId)).collect(Collectors.toList()); + collect.forEach(promotionMap::remove); + goodsIndex.setPromotionMap(promotionMap); + updateIndex(goodsIndex); + } + } + /** * 清除所有商品索引的无效促销活动 */ 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 1542152a..593073e2 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 @@ -22,6 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.NestedQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; @@ -336,6 +337,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { String[] props = searchDTO.getProp().split("@"); List nameList = new ArrayList<>(); List valueList = new ArrayList<>(); + Map> valueMap = new HashMap<>(); for (String prop : props) { String[] propValues = prop.split("_"); String name = propValues[0]; @@ -346,14 +348,29 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { if (!valueList.contains(value)) { valueList.add(value); } - if (isAggregation) { - filterBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termQuery(ATTR_NAME, name), ScoreMode.None)); - filterBuilder.should(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termsQuery(ATTR_VALUE, value), ScoreMode.None)); + // 将同一规格名下的规格值分组 + if (!valueMap.containsKey(name)) { + List values = new ArrayList<>(); + values.add(value); + valueMap.put(name, values); } else { - queryBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termQuery(ATTR_NAME, name), ScoreMode.None)); - queryBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.wildcardQuery(ATTR_VALUE, "*" + value + "*"), ScoreMode.None)); + valueMap.get(name).add(value); } - + } + BoolQueryBuilder usedQueryBuilder; + if (isAggregation) { + usedQueryBuilder = filterBuilder; + } else { + usedQueryBuilder = queryBuilder; + } + // 遍历所有的规格 + for (Map.Entry> entry : valueMap.entrySet()) { + usedQueryBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.wildcardQuery(ATTR_NAME, "*" + entry.getKey() + "*"), ScoreMode.None)); + BoolQueryBuilder shouldBuilder = QueryBuilders.boolQuery(); + for (String s : entry.getValue()) { + shouldBuilder.should(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.wildcardQuery(ATTR_VALUE, "*" + s + "*"), ScoreMode.None)); + } + usedQueryBuilder.must(shouldBuilder); } searchDTO.getNotShowCol().put(ATTR_NAME_KEY, nameList); searchDTO.getNotShowCol().put(ATTR_VALUE_KEY, valueList); From aa024c87b2159e9c3cb205983309c3066d4fa25d Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 20 May 2021 17:03:08 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BB=B6=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/delayqueue/AbstractDelayQueueMachineFactory.java | 4 +++- .../java/cn/lili/common/trigger/RocketmqTimerTrigger.java | 2 +- .../cn/lili/common/trigger/delay/PromotionDelayQueue.java | 2 ++ .../lili/modules/promotion/serviceimpl/CouponServiceImpl.java | 2 +- .../modules/promotion/serviceimpl/PintuanServiceImpl.java | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/delayqueue/AbstractDelayQueueMachineFactory.java b/framework/src/main/java/cn/lili/common/delayqueue/AbstractDelayQueueMachineFactory.java index 5189cff0..30298790 100644 --- a/framework/src/main/java/cn/lili/common/delayqueue/AbstractDelayQueueMachineFactory.java +++ b/framework/src/main/java/cn/lili/common/delayqueue/AbstractDelayQueueMachineFactory.java @@ -36,7 +36,9 @@ public abstract class AbstractDelayQueueMachineFactory { Calendar instance = Calendar.getInstance(); instance.add(Calendar.SECOND, time); long delaySeconds = instance.getTimeInMillis() / 1000; - return redisUtil.zadd(setDelayQueueName(), delaySeconds, jobId); + boolean result = redisUtil.zadd(setDelayQueueName(), delaySeconds, jobId); + log.info("redis add delay, key {}, delay time {}", setDelayQueueName(), delaySeconds); + return result; } diff --git a/framework/src/main/java/cn/lili/common/trigger/RocketmqTimerTrigger.java b/framework/src/main/java/cn/lili/common/trigger/RocketmqTimerTrigger.java index 5a78666e..f039ccbd 100644 --- a/framework/src/main/java/cn/lili/common/trigger/RocketmqTimerTrigger.java +++ b/framework/src/main/java/cn/lili/common/trigger/RocketmqTimerTrigger.java @@ -37,7 +37,7 @@ public class RocketmqTimerTrigger implements TimeTrigger { TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(executorName, triggerTime, param, uniqueKey, topic); Message message = MessageBuilder.withPayload(timeTriggerMsg).build(); - + log.info("延时任务发送信息:{}", message); this.rocketMQTemplate.asyncSend(topic, message, RocketmqSendCallbackBuilder.commonCallback()); } diff --git a/framework/src/main/java/cn/lili/common/trigger/delay/PromotionDelayQueue.java b/framework/src/main/java/cn/lili/common/trigger/delay/PromotionDelayQueue.java index 2f7735f7..4e30f9fc 100644 --- a/framework/src/main/java/cn/lili/common/trigger/delay/PromotionDelayQueue.java +++ b/framework/src/main/java/cn/lili/common/trigger/delay/PromotionDelayQueue.java @@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil; import cn.lili.common.delayqueue.AbstractDelayQueueMachineFactory; import cn.lili.common.trigger.interfaces.TimeTrigger; import cn.lili.common.trigger.model.TimeTriggerMsg; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -18,6 +19,7 @@ import org.springframework.stereotype.Component; @Component public class PromotionDelayQueue extends AbstractDelayQueueMachineFactory { + @Autowired private TimeTrigger timeTrigger; @Override 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 09b7672d..a4c0542f 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 @@ -118,7 +118,7 @@ public class CouponServiceImpl extends ServiceImpl impleme promotionMessage, coupon.getStartTime().getTime(), couponVO.getStartTime().getTime(), DelayQueueTools.wrapperUniqueKey(DelayQueueType.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - DateUtil.getDelayTime(coupon.getStartTime().getTime()), + DateUtil.getDelayTime(couponVO.getStartTime().getTime()), rocketmqCustomProperties.getPromotionTopic()); return couponVO; } 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 47dfc0c3..3567e332 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 @@ -223,7 +223,7 @@ public class PintuanServiceImpl extends ServiceImpl impl pintuanVO.getStartTime().getTime(), pintuan.getStartTime().getTime(), DelayQueueTools.wrapperUniqueKey(DelayQueueType.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - DateUtil.getDelayTime(pintuan.getStartTime().getTime()), + DateUtil.getDelayTime(pintuanVO.getStartTime().getTime()), rocketmqCustomProperties.getPromotionTopic()); } From eaf3aa2b2fd937b3302d24c6fe7621b2eae283c4 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 20 May 2021 19:59:10 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97=E5=88=86=E6=91=8A?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/trigger/RocketmqTimerTrigger.java | 2 +- .../cart/render/impl/SkuPromotionRender.java | 37 +++++++++---------- .../order/cart/service/CartServiceImpl.java | 3 ++ .../PromotionPriceServiceImpl.java | 16 ++++---- .../serviceimpl/EsGoodsSearchServiceImpl.java | 6 ++- 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/trigger/RocketmqTimerTrigger.java b/framework/src/main/java/cn/lili/common/trigger/RocketmqTimerTrigger.java index f039ccbd..8dcd7f02 100644 --- a/framework/src/main/java/cn/lili/common/trigger/RocketmqTimerTrigger.java +++ b/framework/src/main/java/cn/lili/common/trigger/RocketmqTimerTrigger.java @@ -58,7 +58,7 @@ public class RocketmqTimerTrigger implements TimeTrigger { log.info("add Redis key {} --------------------------", generateKey); log.info("定时执行在【" + DateUtil.toString(timeTriggerMsg.getTriggerTime(), "yyyy-MM-dd HH:mm:ss") + "】,消费【" + timeTriggerMsg.getParam().toString() + "】"); } else { - log.info("延时任务添加失败!"); + log.error("延时任务添加失败!"); } } 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 f3150def..c2683cc8 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 @@ -19,7 +19,6 @@ import cn.lili.modules.promotion.entity.dto.PromotionPriceParamDTO; import cn.lili.modules.promotion.entity.dto.StorePromotionPriceDTO; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.service.PromotionPriceService; -import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Service; @@ -27,6 +26,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -151,29 +151,26 @@ public class SkuPromotionRender implements CartRenderStep { for (CartVO cartVO : tradeDTO.getCartList()) { // 根据店铺分配店铺价格计算结果 - List collect = promotionPrice.getStorePromotionPriceList().parallelStream().map(i -> i.getStoreId().equals(cartVO.getStoreId()) ? i : null).collect(Collectors.toList()); - if (!collect.isEmpty() && collect.get(0) != null) { - StorePromotionPriceDTO storePromotionPriceDTO = collect.get(0); + Optional storePromotionPriceDTOOptional = promotionPrice.getStorePromotionPriceList().parallelStream().filter(i -> i.getStoreId().equals(cartVO.getStoreId())).findAny(); + if (storePromotionPriceDTOOptional.isPresent()) { + StorePromotionPriceDTO storePromotionPriceDTO = storePromotionPriceDTOOptional.get(); // 根据商品分配商品结果计算结果 this.distributionSkuPromotionPrice(cartVO.getSkuList(), storePromotionPriceDTO); - if (storePromotionPriceDTO != null) { - PriceDetailDTO sSpd = new PriceDetailDTO(); - PriceDetailVO sPd = new PriceDetailVO(); - sSpd.setGoodsPrice(storePromotionPriceDTO.getTotalOriginPrice()); - sSpd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice()); - sSpd.setCouponPrice(storePromotionPriceDTO.getTotalCouponPrice()); - sSpd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue()); - - sPd.setOriginalPrice(storePromotionPriceDTO.getTotalOriginPrice()); - sPd.setFinalePrice(storePromotionPriceDTO.getTotalFinalePrice()); - sPd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice()); - sPd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue()); - cartVO.setPriceDetailDTO(sSpd); - cartVO.setPriceDetailVO(sPd); - cartVO.setWeight(storePromotionPriceDTO.getTotalWeight()); - } + PriceDetailDTO sSpd = new PriceDetailDTO(); + PriceDetailVO sPd = new PriceDetailVO(); + sSpd.setGoodsPrice(storePromotionPriceDTO.getTotalOriginPrice()); + sSpd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice()); + sSpd.setCouponPrice(storePromotionPriceDTO.getTotalCouponPrice()); + sSpd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue()); + sPd.setOriginalPrice(storePromotionPriceDTO.getTotalOriginPrice()); + sPd.setFinalePrice(storePromotionPriceDTO.getTotalFinalePrice()); + sPd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice()); + sPd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue()); + cartVO.setPriceDetailDTO(sSpd); + cartVO.setPriceDetailVO(sPd); + cartVO.setWeight(storePromotionPriceDTO.getTotalWeight()); } } 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 8e1434b8..5ff5d4f3 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 @@ -269,6 +269,9 @@ public class CartServiceImpl implements CartService { } } cartSkuVOS.removeAll(deleteVos); + // 清除选择的优惠券 + tradeDTO.setPlatformCoupon(null); + tradeDTO.setStoreCoupons(null); // 清除添加过的备注 tradeDTO.setStoreRemark(null); cache.put(this.getOriginKey(tradeDTO.getCartTypeEnum()), tradeDTO); diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionPriceServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionPriceServiceImpl.java index 5bedc4bb..cc4ab245 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionPriceServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionPriceServiceImpl.java @@ -126,6 +126,10 @@ public class PromotionPriceServiceImpl implements PromotionPriceService { if (platformCoupons != null && !platformCoupons.isEmpty()) { // 计算平台优惠券活动 couponTotalPrice = CurrencyUtil.add(couponTotalPrice, this.calculationCoupon(platformCoupons, priceDTOList)); + for (StorePromotionPriceDTO storePromotionPriceDTO : storePromotionPriceList) { + Double couponPrice = storePromotionPriceDTO.getGoodsSkuPromotionPriceList().parallelStream().mapToDouble(GoodsSkuPromotionPriceDTO::getCouponPrice).sum(); + storePromotionPriceDTO.setTotalCouponPrice(couponPrice); + } } promotionPrice.setStorePromotionPriceList(storePromotionPriceList); promotionPrice.setTotalCouponPrice(couponTotalPrice); @@ -290,17 +294,14 @@ public class PromotionPriceServiceImpl implements PromotionPriceService { // 合计优惠券范围内的所有商品的原价 double totalPrice = conformCollect.parallelStream().mapToDouble(GoodsSkuPromotionPriceDTO::getOriginalPrice).sum(); - double discountPrice = 0; // 根据优惠券优惠类型,判断是否满足条件 if (CouponTypeEnum.PRICE.name().equals(coupon.getCouponType()) && coupon.getConsumeThreshold() <= totalPrice) { couponTotalPrice = CurrencyUtil.add(couponTotalPrice, coupon.getPrice()); - discountPrice = coupon.getPrice(); } else if (CouponTypeEnum.DISCOUNT.name().equals(coupon.getCouponType())) { double fullRate = coupon.getDiscount() >= 10 ? coupon.getDiscount() / 100 : coupon.getDiscount() / 10; double discountRatePrice = CurrencyUtil.sub(totalPrice, CurrencyUtil.mul(totalPrice, fullRate)); couponTotalPrice = CurrencyUtil.add(couponTotalPrice, discountRatePrice); - discountPrice = discountRatePrice; // 消费限额判断 // if (coupon.getConsumeThreshold() >= discountRatePrice) { // couponTotalPrice = CurrencyUtil.add(couponTotalPrice, discountRatePrice); @@ -312,14 +313,15 @@ public class PromotionPriceServiceImpl implements PromotionPriceService { } // 分配到每个商品的优惠券金额 - double distributePrice = CurrencyUtil.div(discountPrice, conformCollect.size()); for (GoodsSkuPromotionPriceDTO goodsSkuPromotionPriceDTO : conformCollect) { + double rate = CurrencyUtil.div(goodsSkuPromotionPriceDTO.getFinalePrice(), totalPrice, 5); + double distributeCouponPrice = CurrencyUtil.mul(couponTotalPrice, rate); if (goodsSkuPromotionPriceDTO.getFinalePrice() != null) { - goodsSkuPromotionPriceDTO.setFinalePrice(CurrencyUtil.sub(goodsSkuPromotionPriceDTO.getFinalePrice(), distributePrice)); + goodsSkuPromotionPriceDTO.setFinalePrice(CurrencyUtil.sub(goodsSkuPromotionPriceDTO.getFinalePrice(), distributeCouponPrice)); } else { - goodsSkuPromotionPriceDTO.setFinalePrice(CurrencyUtil.sub(goodsSkuPromotionPriceDTO.getOriginalPrice(), distributePrice)); + goodsSkuPromotionPriceDTO.setFinalePrice(CurrencyUtil.sub(goodsSkuPromotionPriceDTO.getOriginalPrice(), distributeCouponPrice)); } - goodsSkuPromotionPriceDTO.setCouponPrice(distributePrice); + goodsSkuPromotionPriceDTO.setCouponPrice(distributeCouponPrice); goodsSkuPromotionPriceDTO.setTotalFinalePrice(CurrencyUtil.mul(goodsSkuPromotionPriceDTO.getFinalePrice(), goodsSkuPromotionPriceDTO.getNumber())); BasePromotion basePromotion = new BasePromotion(); basePromotion.setId(coupon.getId()); 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 593073e2..b1f65327 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 @@ -257,7 +257,11 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { private NativeSearchQueryBuilder createSearchQueryBuilder(EsGoodsSearchDTO searchDTO, PageVO pageVo, boolean isAggregation) { NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder(); if (pageVo != null) { - Pageable pageable = PageRequest.of(pageVo.getPageNumber(), pageVo.getPageSize()); + Integer pageNumber = pageVo.getPageNumber() - 1; + if (pageNumber < 0) { + pageNumber = 0; + } + Pageable pageable = PageRequest.of(pageNumber, pageVo.getPageSize()); //分页 nativeSearchQueryBuilder.withPageable(pageable); }