Commit b69ba9466080f5d98b966c1989375dc0a79210be
1 parent
085b94f0
【BUG】如果没有限时优惠就不展示会员价的问题
Showing
1 changed file
with
53 additions
and
25 deletions
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 |
| 47 | 47 | if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { |
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | + | |
| 51 | + boolean discount; | |
| 52 | + boolean vip; | |
| 53 | + | |
| 50 | 54 | //----------------------------------限时折扣计算----------------------------------------- |
| 51 | 55 | // 获得 SKU 对应的限时折扣活动 |
| 52 | 56 | List<DiscountProductRespDTO> discountProducts = discountActivityApi.getMatchDiscountProductList( |
| 53 | 57 | convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSkuId)); |
| 54 | 58 | if (CollUtil.isEmpty(discountProducts)) { |
| 55 | - return; | |
| 59 | + discount = false; | |
| 60 | + }else { | |
| 61 | + discount = true; | |
| 56 | 62 | } |
| 57 | 63 | Map<Long, DiscountProductRespDTO> discountProductMap = convertMap(discountProducts, DiscountProductRespDTO::getSkuId); |
| 58 | 64 | |
| 59 | 65 | |
| 60 | 66 | |
| 61 | 67 | //----------------------------------会员计算----------------------------------------- |
| 62 | - | |
| 68 | + MemberLevelRespDTO level; | |
| 63 | 69 | // 获得用户的会员等级 |
| 64 | 70 | MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); |
| 65 | - if (user.getLevelId() == null || user.getLevelId() <= 0) { | |
| 66 | - return; | |
| 67 | - } | |
| 68 | - MemberLevelRespDTO level = memberLevelApi.getMemberLevel(user.getLevelId()); | |
| 69 | - if (level == null || level.getDiscountPercent() == null) { | |
| 70 | - return; | |
| 71 | + if (user.getLevelId() != null && user.getLevelId() > 0) { | |
| 72 | + level = memberLevelApi.getMemberLevel(user.getLevelId()); | |
| 73 | + if (level != null && level.getDiscountPercent() != null) { | |
| 74 | + vip = true; | |
| 75 | + }else { | |
| 76 | + vip = false; | |
| 77 | + } | |
| 78 | + }else { | |
| 79 | + level = null; | |
| 80 | + vip = false; | |
| 71 | 81 | } |
| 72 | 82 | |
| 83 | + | |
| 73 | 84 | // 2. 计算每个 SKU 的优惠金额 |
| 74 | 85 | result.getItems().forEach(orderItem -> { |
| 75 | 86 | |
| 76 | 87 | //----------------------------------限时折扣计算----------------------------------------- |
| 77 | - | |
| 78 | - // 2.1 计算限时折扣优惠信息 | |
| 79 | - DiscountProductRespDTO discountProduct = discountProductMap.get(orderItem.getSkuId()); | |
| 80 | - if (discountProduct == null) { | |
| 81 | - return; | |
| 88 | + DiscountProductRespDTO discountProduct = null; | |
| 89 | + Integer newDiscountPrice = 0; | |
| 90 | + if (discount){ | |
| 91 | + // 2.1 计算限时折扣优惠信息 | |
| 92 | + discountProduct = discountProductMap.get(orderItem.getSkuId()); | |
| 93 | + if (discountProduct != null) { | |
| 94 | + // 2.2 计算优惠金额 | |
| 95 | + Integer newPayPrice = calculatePayPrice(discountProduct, orderItem); | |
| 96 | + newDiscountPrice = orderItem.getPayPrice() - newPayPrice; | |
| 97 | + } | |
| 82 | 98 | } |
| 83 | - // 2.2 计算优惠金额 | |
| 84 | - Integer newPayPrice = calculatePayPrice(discountProduct, orderItem); | |
| 85 | - Integer newDiscountPrice = orderItem.getPayPrice() - newPayPrice; | |
| 86 | 99 | |
| 87 | 100 | |
| 88 | 101 | //----------------------------------会员计算----------------------------------------- |
| 89 | - | |
| 90 | - // 2.3 计算会员优惠金额 | |
| 91 | - Integer vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent()); | |
| 92 | - if (vipPrice <= 0) { | |
| 93 | - return; | |
| 102 | + Integer vipPrice = 0; | |
| 103 | + if (vip){ | |
| 104 | + // 2.3 计算会员优惠金额 | |
| 105 | + vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent()); | |
| 94 | 106 | } |
| 95 | 107 | |
| 108 | + | |
| 96 | 109 | // 2.4 记录优惠明细 |
| 110 | + // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示 | |
| 97 | 111 | if (orderItem.getSelected()) { |
| 98 | - if(newDiscountPrice > vipPrice){ | |
| 99 | - // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示 | |
| 112 | + if (discount && vip){ | |
| 113 | + if(newDiscountPrice > vipPrice){ | |
| 114 | + TradePriceCalculatorHelper.addPromotion(result, orderItem, | |
| 115 | + discountProduct.getActivityId(), discountProduct.getActivityName(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType(), | |
| 116 | + StrUtil.format("限时折扣:省 {} 元", formatPrice(newDiscountPrice)), | |
| 117 | + newDiscountPrice); | |
| 118 | + // 2.5 更新 SKU 优惠金额 | |
| 119 | + orderItem.setDiscountPrice(orderItem.getDiscountPrice() + newDiscountPrice); | |
| 120 | + }else{ | |
| 121 | + TradePriceCalculatorHelper.addPromotion(result, orderItem, | |
| 122 | + level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(), | |
| 123 | + String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)), | |
| 124 | + vipPrice); | |
| 125 | + // 2.5 更新 SKU 的优惠金额 | |
| 126 | + orderItem.setVipPrice(vipPrice); | |
| 127 | + } | |
| 128 | + }else if (discount){ | |
| 100 | 129 | TradePriceCalculatorHelper.addPromotion(result, orderItem, |
| 101 | 130 | discountProduct.getActivityId(), discountProduct.getActivityName(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType(), |
| 102 | 131 | StrUtil.format("限时折扣:省 {} 元", formatPrice(newDiscountPrice)), |
| 103 | 132 | newDiscountPrice); |
| 104 | 133 | // 2.5 更新 SKU 优惠金额 |
| 105 | 134 | orderItem.setDiscountPrice(orderItem.getDiscountPrice() + newDiscountPrice); |
| 106 | - }else{ | |
| 107 | - // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示 | |
| 135 | + }else if (vip){ | |
| 108 | 136 | TradePriceCalculatorHelper.addPromotion(result, orderItem, |
| 109 | 137 | level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(), |
| 110 | 138 | String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)), | ... | ... |