mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-13 17:51:53 +08:00
mall + trade:增肌爱 TradeCouponPriceCalculator 的单元测试
This commit is contained in:
@@ -101,7 +101,8 @@ public class TradeCouponPriceCalculator implements TradePriceCalculator {
|
||||
CouponRespDTO coupon) {
|
||||
Predicate<TradePriceCalculateRespBO.OrderItem> matchPredicate = TradePriceCalculateRespBO.OrderItem::getSelected;
|
||||
if (PromotionProductScopeEnum.SPU.getScope().equals(coupon.getProductScope())) {
|
||||
matchPredicate = orderItem -> coupon.getProductSpuIds().contains(orderItem.getSpuId());
|
||||
matchPredicate = matchPredicate // 额外加如下条件
|
||||
.and(orderItem -> coupon.getProductSpuIds().contains(orderItem.getSpuId()));
|
||||
}
|
||||
return filterList(result.getItems(), matchPredicate);
|
||||
}
|
||||
|
@@ -15,8 +15,6 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
// TODO 芋艿:改成父类
|
||||
|
||||
/**
|
||||
* {@link TradePriceCalculator} 的工具类
|
||||
*
|
||||
@@ -106,6 +104,31 @@ public class TradePriceCalculatorHelper {
|
||||
- orderItem.getPointPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新计算每个订单项的支付金额
|
||||
*
|
||||
* 【目前主要是单测使用】
|
||||
*
|
||||
* @param orderItems 订单项数组
|
||||
*/
|
||||
public static void recountPayPrice(List<TradePriceCalculateRespBO.OrderItem> orderItems) {
|
||||
orderItems.forEach(orderItem -> {
|
||||
if (orderItem.getDiscountPrice() == null) {
|
||||
orderItem.setDiscountPrice(0);
|
||||
}
|
||||
if (orderItem.getDeliveryPrice() == null) {
|
||||
orderItem.setDeliveryPrice(0);
|
||||
}
|
||||
if (orderItem.getCouponPrice() == null) {
|
||||
orderItem.setCouponPrice(0);
|
||||
}
|
||||
if (orderItem.getPointPrice() == null) {
|
||||
orderItem.setPointPrice(0);
|
||||
}
|
||||
recountPayPrice(orderItem);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算已选中的订单项,总支付金额
|
||||
*
|
||||
@@ -114,7 +137,7 @@ public class TradePriceCalculatorHelper {
|
||||
*/
|
||||
public static Integer calculateTotalPayPrice(List<TradePriceCalculateRespBO.OrderItem> orderItems) {
|
||||
return getSumValue(orderItems,
|
||||
orderItem -> orderItem.getSelected() ? orderItem.getPayPrice() : 0, // 未选中的情况下,不计算支付金额
|
||||
orderItem -> orderItem.getSelected() ? orderItem.getPayPrice() : 0, // 未选中的情况下,不计算支付金额
|
||||
Integer::sum);
|
||||
}
|
||||
|
||||
|
@@ -53,6 +53,9 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
||||
// 1.2 获得最大匹配的满减送活动的规则
|
||||
RewardActivityMatchRespDTO.Rule rule = getMaxMatchRewardActivityRule(rewardActivity, orderItems);
|
||||
if (rule == null) {
|
||||
TradePriceCalculatorHelper.addNotMatchPromotion(result, orderItems,
|
||||
rewardActivity.getId(), rewardActivity.getName(), PromotionTypeEnum.REWARD_ACTIVITY.getType(),
|
||||
getRewardActivityNotMeetTip(rewardActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user