【BUG】如果没有限时优惠就不展示会员价的问题

This commit is contained in:
痴货 2024-09-14 19:43:45 +08:00
parent 085b94f0d0
commit b69ba94660
1 changed files with 53 additions and 25 deletions

View File

@ -47,56 +47,70 @@ public class TradeDiscountActivityPriceCalculator implements TradePriceCalculato
if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) {
return; return;
} }
boolean discount;
boolean vip;
//----------------------------------限时折扣计算----------------------------------------- //----------------------------------限时折扣计算-----------------------------------------
// 获得 SKU 对应的限时折扣活动 // 获得 SKU 对应的限时折扣活动
List<DiscountProductRespDTO> discountProducts = discountActivityApi.getMatchDiscountProductList( List<DiscountProductRespDTO> discountProducts = discountActivityApi.getMatchDiscountProductList(
convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSkuId)); convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSkuId));
if (CollUtil.isEmpty(discountProducts)) { if (CollUtil.isEmpty(discountProducts)) {
return; discount = false;
}else {
discount = true;
} }
Map<Long, DiscountProductRespDTO> discountProductMap = convertMap(discountProducts, DiscountProductRespDTO::getSkuId); Map<Long, DiscountProductRespDTO> discountProductMap = convertMap(discountProducts, DiscountProductRespDTO::getSkuId);
//----------------------------------会员计算----------------------------------------- //----------------------------------会员计算-----------------------------------------
MemberLevelRespDTO level;
// 获得用户的会员等级 // 获得用户的会员等级
MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); MemberUserRespDTO user = memberUserApi.getUser(param.getUserId());
if (user.getLevelId() == null || user.getLevelId() <= 0) { if (user.getLevelId() != null && user.getLevelId() > 0) {
return; level = memberLevelApi.getMemberLevel(user.getLevelId());
if (level != null && level.getDiscountPercent() != null) {
vip = true;
}else {
vip = false;
} }
MemberLevelRespDTO level = memberLevelApi.getMemberLevel(user.getLevelId()); }else {
if (level == null || level.getDiscountPercent() == null) { level = null;
return; vip = false;
} }
// 2. 计算每个 SKU 的优惠金额 // 2. 计算每个 SKU 的优惠金额
result.getItems().forEach(orderItem -> { result.getItems().forEach(orderItem -> {
//----------------------------------限时折扣计算----------------------------------------- //----------------------------------限时折扣计算-----------------------------------------
DiscountProductRespDTO discountProduct = null;
Integer newDiscountPrice = 0;
if (discount){
// 2.1 计算限时折扣优惠信息 // 2.1 计算限时折扣优惠信息
DiscountProductRespDTO discountProduct = discountProductMap.get(orderItem.getSkuId()); discountProduct = discountProductMap.get(orderItem.getSkuId());
if (discountProduct == null) { if (discountProduct != null) {
return;
}
// 2.2 计算优惠金额 // 2.2 计算优惠金额
Integer newPayPrice = calculatePayPrice(discountProduct, orderItem); Integer newPayPrice = calculatePayPrice(discountProduct, orderItem);
Integer newDiscountPrice = orderItem.getPayPrice() - newPayPrice; newDiscountPrice = orderItem.getPayPrice() - newPayPrice;
}
}
//----------------------------------会员计算----------------------------------------- //----------------------------------会员计算-----------------------------------------
Integer vipPrice = 0;
if (vip){
// 2.3 计算会员优惠金额 // 2.3 计算会员优惠金额
Integer vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent()); vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent());
if (vipPrice <= 0) {
return;
} }
// 2.4 记录优惠明细 // 2.4 记录优惠明细
if (orderItem.getSelected()) {
if(newDiscountPrice > vipPrice){
// 注意只有在选中的情况下才会记录到优惠明细否则仅仅是更新 SKU 优惠金额用于展示 // 注意只有在选中的情况下才会记录到优惠明细否则仅仅是更新 SKU 优惠金额用于展示
if (orderItem.getSelected()) {
if (discount && vip){
if(newDiscountPrice > vipPrice){
TradePriceCalculatorHelper.addPromotion(result, orderItem, TradePriceCalculatorHelper.addPromotion(result, orderItem,
discountProduct.getActivityId(), discountProduct.getActivityName(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType(), discountProduct.getActivityId(), discountProduct.getActivityName(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType(),
StrUtil.format("限时折扣:省 {} 元", formatPrice(newDiscountPrice)), StrUtil.format("限时折扣:省 {} 元", formatPrice(newDiscountPrice)),
@ -104,7 +118,21 @@ public class TradeDiscountActivityPriceCalculator implements TradePriceCalculato
// 2.5 更新 SKU 优惠金额 // 2.5 更新 SKU 优惠金额
orderItem.setDiscountPrice(orderItem.getDiscountPrice() + newDiscountPrice); orderItem.setDiscountPrice(orderItem.getDiscountPrice() + newDiscountPrice);
}else{ }else{
// 注意只有在选中的情况下才会记录到优惠明细否则仅仅是更新 SKU 优惠金额用于展示 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 if (vip){
TradePriceCalculatorHelper.addPromotion(result, orderItem, TradePriceCalculatorHelper.addPromotion(result, orderItem,
level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(), level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(),
String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)), String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)),