From eaf3aa2b2fd937b3302d24c6fe7621b2eae283c4 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 20 May 2021 19:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97=E5=88=86=E6=91=8A=E9=97=AE?= =?UTF-8?q?=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); }