...
|
...
|
@@ -15,9 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.yohoufo.order.charge.model.ChargeParam.*;
|
|
|
import static com.yohoufo.order.constants.ApiVersionConfig.*;
|
...
|
...
|
@@ -205,7 +204,36 @@ public class ChargeService { |
|
|
chargeContext.getChargeResult().getCouponPayResultList().setUsableCouponCount(usableCouponMatchResults.size());
|
|
|
|
|
|
if (useCoupon) {
|
|
|
doCalculateCoupons(usableCouponMatchResults, chargeContext);
|
|
|
|
|
|
//默认
|
|
|
List<CouponMatchResult> betterCouponMatchResults = usableCouponMatchResults;
|
|
|
|
|
|
//活动券
|
|
|
List<CouponMatchResult> activityCouponMatchResults = usableCouponMatchResults.stream().filter(result -> result.isUsable())
|
|
|
.filter(result -> result.getUserCouponsBo().getCouponType() == CouponTypeEnum.ACTIVITY_COUPON.getCode())
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
//运费券
|
|
|
List<CouponMatchResult> shippingCouponMatchResults = usableCouponMatchResults.stream().filter(result -> result.isUsable())
|
|
|
.filter(result -> result.getUserCouponsBo().getCouponType() == CouponTypeEnum.SHIPPING_COUPON.getCode())
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
//运费金额
|
|
|
double finalShippingAmount = chargeContext.getChargeResult().getFinalShippingAmount();
|
|
|
//先匹配一下 运费券金额 >= 运费,优先使用金额等于运费的券
|
|
|
List<CouponMatchResult> betterShippingCouponMatchResults = shippingCouponMatchResults.stream()
|
|
|
.filter(result -> result.getUserCouponsBo().getCouponAmount().doubleValue() >= finalShippingAmount)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(betterShippingCouponMatchResults)) {
|
|
|
//存在金额 >= 运费的券,按照金额从小到大的顺序
|
|
|
betterShippingCouponMatchResults.sort(Comparator.comparing(result -> result.getUserCouponsBo().getCouponAmount()));
|
|
|
|
|
|
betterCouponMatchResults = new LinkedList<>(activityCouponMatchResults);
|
|
|
betterCouponMatchResults.addAll(betterShippingCouponMatchResults);
|
|
|
}
|
|
|
|
|
|
doCalculateCoupons(betterCouponMatchResults, chargeContext);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|