From b69ba9466080f5d98b966c1989375dc0a79210be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=97=B4=E8=B4=A7?= <252048765@qq.com> Date: Sat, 14 Sep 2024 19:43:45 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90BUG=E3=80=91=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E9=99=90=E6=97=B6=E4=BC=98=E6=83=A0=E5=B0=B1?= =?UTF-8?q?=E4=B8=8D=E5=B1=95=E7=A4=BA=E4=BC=9A=E5=91=98=E4=BB=B7=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TradeDiscountActivityPriceCalculator.java | 78 +++++++++++++------ 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java index b3297a985..eaf07b6a4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java @@ -47,64 +47,92 @@ public class TradeDiscountActivityPriceCalculator implements TradePriceCalculato if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { return; } + + boolean discount; + boolean vip; + //----------------------------------限时折扣计算----------------------------------------- // 获得 SKU 对应的限时折扣活动 List discountProducts = discountActivityApi.getMatchDiscountProductList( convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSkuId)); if (CollUtil.isEmpty(discountProducts)) { - return; + discount = false; + }else { + discount = true; } Map discountProductMap = convertMap(discountProducts, DiscountProductRespDTO::getSkuId); //----------------------------------会员计算----------------------------------------- - + MemberLevelRespDTO level; // 获得用户的会员等级 MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); - if (user.getLevelId() == null || user.getLevelId() <= 0) { - return; - } - MemberLevelRespDTO level = memberLevelApi.getMemberLevel(user.getLevelId()); - if (level == null || level.getDiscountPercent() == null) { - return; + if (user.getLevelId() != null && user.getLevelId() > 0) { + level = memberLevelApi.getMemberLevel(user.getLevelId()); + if (level != null && level.getDiscountPercent() != null) { + vip = true; + }else { + vip = false; + } + }else { + level = null; + vip = false; } + // 2. 计算每个 SKU 的优惠金额 result.getItems().forEach(orderItem -> { //----------------------------------限时折扣计算----------------------------------------- - - // 2.1 计算限时折扣优惠信息 - DiscountProductRespDTO discountProduct = discountProductMap.get(orderItem.getSkuId()); - if (discountProduct == null) { - return; + DiscountProductRespDTO discountProduct = null; + Integer newDiscountPrice = 0; + if (discount){ + // 2.1 计算限时折扣优惠信息 + discountProduct = discountProductMap.get(orderItem.getSkuId()); + if (discountProduct != null) { + // 2.2 计算优惠金额 + Integer newPayPrice = calculatePayPrice(discountProduct, orderItem); + newDiscountPrice = orderItem.getPayPrice() - newPayPrice; + } } - // 2.2 计算优惠金额 - Integer newPayPrice = calculatePayPrice(discountProduct, orderItem); - Integer newDiscountPrice = orderItem.getPayPrice() - newPayPrice; //----------------------------------会员计算----------------------------------------- - - // 2.3 计算会员优惠金额 - Integer vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent()); - if (vipPrice <= 0) { - return; + Integer vipPrice = 0; + if (vip){ + // 2.3 计算会员优惠金额 + vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent()); } + // 2.4 记录优惠明细 + // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示 if (orderItem.getSelected()) { - if(newDiscountPrice > vipPrice){ - // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示 + if (discount && vip){ + if(newDiscountPrice > vipPrice){ + TradePriceCalculatorHelper.addPromotion(result, orderItem, + discountProduct.getActivityId(), discountProduct.getActivityName(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType(), + StrUtil.format("限时折扣:省 {} 元", formatPrice(newDiscountPrice)), + newDiscountPrice); + // 2.5 更新 SKU 优惠金额 + orderItem.setDiscountPrice(orderItem.getDiscountPrice() + newDiscountPrice); + }else{ + TradePriceCalculatorHelper.addPromotion(result, orderItem, + level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(), + String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)), + vipPrice); + // 2.5 更新 SKU 的优惠金额 + orderItem.setVipPrice(vipPrice); + } + }else if (discount){ TradePriceCalculatorHelper.addPromotion(result, orderItem, discountProduct.getActivityId(), discountProduct.getActivityName(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType(), StrUtil.format("限时折扣:省 {} 元", formatPrice(newDiscountPrice)), newDiscountPrice); // 2.5 更新 SKU 优惠金额 orderItem.setDiscountPrice(orderItem.getDiscountPrice() + newDiscountPrice); - }else{ - // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示 + }else if (vip){ TradePriceCalculatorHelper.addPromotion(result, orderItem, level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(), String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)),