Merge branch 'dev-coupon-recommend' into test6.9.6
Showing
1 changed file
with
32 additions
and
4 deletions
@@ -15,9 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -15,9 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
15 | import org.springframework.stereotype.Component; | 15 | import org.springframework.stereotype.Component; |
16 | 16 | ||
17 | import java.math.BigDecimal; | 17 | import java.math.BigDecimal; |
18 | -import java.util.List; | ||
19 | -import java.util.Objects; | ||
20 | -import java.util.Optional; | 18 | +import java.util.*; |
19 | +import java.util.stream.Collectors; | ||
21 | 20 | ||
22 | import static com.yohoufo.order.charge.model.ChargeParam.*; | 21 | import static com.yohoufo.order.charge.model.ChargeParam.*; |
23 | import static com.yohoufo.order.constants.ApiVersionConfig.*; | 22 | import static com.yohoufo.order.constants.ApiVersionConfig.*; |
@@ -205,7 +204,36 @@ public class ChargeService { | @@ -205,7 +204,36 @@ public class ChargeService { | ||
205 | chargeContext.getChargeResult().getCouponPayResultList().setUsableCouponCount(usableCouponMatchResults.size()); | 204 | chargeContext.getChargeResult().getCouponPayResultList().setUsableCouponCount(usableCouponMatchResults.size()); |
206 | 205 | ||
207 | if (useCoupon) { | 206 | if (useCoupon) { |
208 | - doCalculateCoupons(usableCouponMatchResults, chargeContext); | 207 | + |
208 | + //默认 | ||
209 | + List<CouponMatchResult> betterCouponMatchResults = usableCouponMatchResults; | ||
210 | + | ||
211 | + //活动券 | ||
212 | + List<CouponMatchResult> activityCouponMatchResults = usableCouponMatchResults.stream().filter(result -> result.isUsable()) | ||
213 | + .filter(result -> result.getUserCouponsBo().getCouponType() == CouponTypeEnum.ACTIVITY_COUPON.getCode()) | ||
214 | + .collect(Collectors.toList()); | ||
215 | + | ||
216 | + //运费券 | ||
217 | + List<CouponMatchResult> shippingCouponMatchResults = usableCouponMatchResults.stream().filter(result -> result.isUsable()) | ||
218 | + .filter(result -> result.getUserCouponsBo().getCouponType() == CouponTypeEnum.SHIPPING_COUPON.getCode()) | ||
219 | + .collect(Collectors.toList()); | ||
220 | + | ||
221 | + //运费金额 | ||
222 | + double finalShippingAmount = chargeContext.getChargeResult().getFinalShippingAmount(); | ||
223 | + //先匹配一下 运费券金额 >= 运费,优先使用金额等于运费的券 | ||
224 | + List<CouponMatchResult> betterShippingCouponMatchResults = shippingCouponMatchResults.stream() | ||
225 | + .filter(result -> result.getUserCouponsBo().getCouponAmount().doubleValue() >= finalShippingAmount) | ||
226 | + .collect(Collectors.toList()); | ||
227 | + | ||
228 | + if (CollectionUtils.isNotEmpty(betterShippingCouponMatchResults)) { | ||
229 | + //存在金额 >= 运费的券,按照金额从小到大的顺序 | ||
230 | + betterShippingCouponMatchResults.sort(Comparator.comparing(result -> result.getUserCouponsBo().getCouponAmount())); | ||
231 | + | ||
232 | + betterCouponMatchResults = new LinkedList<>(activityCouponMatchResults); | ||
233 | + betterCouponMatchResults.addAll(betterShippingCouponMatchResults); | ||
234 | + } | ||
235 | + | ||
236 | + doCalculateCoupons(betterCouponMatchResults, chargeContext); | ||
209 | } | 237 | } |
210 | } | 238 | } |
211 | 239 |
-
Please register or login to post a comment