Showing
3 changed files
with
15 additions
and
19 deletions
@@ -257,26 +257,26 @@ public class ChargeService { | @@ -257,26 +257,26 @@ public class ChargeService { | ||
257 | } | 257 | } |
258 | 258 | ||
259 | //特殊场景:运费券满足条件(商品条件及金额),但运费为0,不能使用运费券 | 259 | //特殊场景:运费券满足条件(商品条件及金额),但运费为0,不能使用运费券 |
260 | - Optional<CouponPayResult> couponPayResult = null; | 260 | + Optional<CouponPayResult> couponPayResultOptional = null; |
261 | 261 | ||
262 | CouponTypeEnum couponTypeEnum = CouponTypeEnum.of(userCouponsBo.getCouponType()).orElse(null); | 262 | CouponTypeEnum couponTypeEnum = CouponTypeEnum.of(userCouponsBo.getCouponType()).orElse(null); |
263 | switch (couponTypeEnum) { | 263 | switch (couponTypeEnum) { |
264 | case ACTIVITY_COUPON: { | 264 | case ACTIVITY_COUPON: { |
265 | //活动券 | 265 | //活动券 |
266 | - couponPayResult = activityCouponUse(userCouponsBo, chargeContext); | 266 | + couponPayResultOptional = activityCouponUse(userCouponsBo, chargeContext); |
267 | break; | 267 | break; |
268 | } | 268 | } |
269 | case SHIPPING_COUPON: { | 269 | case SHIPPING_COUPON: { |
270 | //运费券 | 270 | //运费券 |
271 | - couponPayResult = shippingCouponUse(userCouponsBo, chargeContext); | 271 | + couponPayResultOptional = shippingCouponUse(userCouponsBo, chargeContext); |
272 | break; | 272 | break; |
273 | } | 273 | } |
274 | default: | 274 | default: |
275 | throw new UfoServiceException(500, "unknown couponType:" + userCouponsBo.getCouponType()); | 275 | throw new UfoServiceException(500, "unknown couponType:" + userCouponsBo.getCouponType()); |
276 | } | 276 | } |
277 | 277 | ||
278 | - if (couponPayResult.isPresent()) { | ||
279 | - couponPayResultList.addCouponPayResult(couponPayResult.get()); | 278 | + if (couponPayResultOptional.isPresent()) { |
279 | + couponPayResultList.addCouponPayResult(couponPayResultOptional.get()); | ||
280 | } | 280 | } |
281 | } | 281 | } |
282 | 282 |
@@ -50,9 +50,9 @@ public class CouponService { | @@ -50,9 +50,9 @@ public class CouponService { | ||
50 | */ | 50 | */ |
51 | public List<CouponMatchResult> getRecommendedCoupons(ChargeContext chargeContext) { | 51 | public List<CouponMatchResult> getRecommendedCoupons(ChargeContext chargeContext) { |
52 | ChargeParam chargeParam = chargeContext.getChargeParam(); | 52 | ChargeParam chargeParam = chargeContext.getChargeParam(); |
53 | - Optional<List<UserCouponsBo>> userCouponsBos = couponProxyService.getUserAvailableCouponsWhenExceptionHappenedReturnNull(chargeParam.getUid()); | ||
54 | - if (userCouponsBos.isPresent()) { | ||
55 | - List<UserCouponsBo> userCouponsBoToSort = userCouponsBos.get(); | 53 | + Optional<List<UserCouponsBo>> userCouponsBosOptional = couponProxyService.getUserAvailableCouponsWhenExceptionHappenedReturnNull(chargeParam.getUid()); |
54 | + if (userCouponsBosOptional.isPresent()) { | ||
55 | + List<UserCouponsBo> userCouponsBoToSort = userCouponsBosOptional.get(); | ||
56 | userCouponsBoToSort.sort(COUPON_COMPARATOR); | 56 | userCouponsBoToSort.sort(COUPON_COMPARATOR); |
57 | return matchAndGetUsableCoupons(userCouponsBoToSort, chargeContext); | 57 | return matchAndGetUsableCoupons(userCouponsBoToSort, chargeContext); |
58 | } | 58 | } |
@@ -61,7 +61,6 @@ import java.math.BigDecimal; | @@ -61,7 +61,6 @@ import java.math.BigDecimal; | ||
61 | import java.util.Arrays; | 61 | import java.util.Arrays; |
62 | import java.util.List; | 62 | import java.util.List; |
63 | import java.util.Objects; | 63 | import java.util.Objects; |
64 | -import java.util.Optional; | ||
65 | import java.util.stream.Collectors; | 64 | import java.util.stream.Collectors; |
66 | 65 | ||
67 | import org.springframework.context.annotation.Primary; | 66 | import org.springframework.context.annotation.Primary; |
@@ -504,7 +503,7 @@ public class ShoppingServiceImpl implements IShoppingService { | @@ -504,7 +503,7 @@ public class ShoppingServiceImpl implements IShoppingService { | ||
504 | */ | 503 | */ |
505 | protected AmountDetailBo buildOrderAmountDetailBo(ChargeResult chargeResult) { | 504 | protected AmountDetailBo buildOrderAmountDetailBo(ChargeResult chargeResult) { |
506 | //订单金额明细 | 505 | //订单金额明细 |
507 | - AmountDetailBo amountDetailBo = new AmountDetailBo(); | 506 | + final AmountDetailBo amountDetailBo = new AmountDetailBo(); |
508 | //商品金额 | 507 | //商品金额 |
509 | amountDetailBo.setGoodsAmount(chargeResult.getGoodsAmount()); | 508 | amountDetailBo.setGoodsAmount(chargeResult.getGoodsAmount()); |
510 | //运费原价 | 509 | //运费原价 |
@@ -512,16 +511,13 @@ public class ShoppingServiceImpl implements IShoppingService { | @@ -512,16 +511,13 @@ public class ShoppingServiceImpl implements IShoppingService { | ||
512 | //活动金额 | 511 | //活动金额 |
513 | amountDetailBo.setActivityCutAmount(chargeResult.getActivityCutResult().getActivityCutAmount()); | 512 | amountDetailBo.setActivityCutAmount(chargeResult.getActivityCutResult().getActivityCutAmount()); |
514 | 513 | ||
515 | - Optional<CouponPayResult> tempPayResult; | ||
516 | - if ((tempPayResult = chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.ACTIVITY_COUPON.getCode())).isPresent()) { | ||
517 | - //活动券减免金额 | ||
518 | - amountDetailBo.setCouponCutAmount(tempPayResult.get().getCouponAmount()); | ||
519 | - } | 514 | + //活动券减免金额 |
515 | + chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.ACTIVITY_COUPON.getCode()). | ||
516 | + ifPresent(tempPayResult -> amountDetailBo.setCouponCutAmount(tempPayResult.getCouponAmount())); | ||
520 | 517 | ||
521 | - if ((tempPayResult = chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.SHIPPING_COUPON.getCode())).isPresent()) { | ||
522 | - //运费券减免金额 | ||
523 | - amountDetailBo.setShippingCouponCutAmount(tempPayResult.get().getCouponAmount()); | ||
524 | - } | 518 | + //运费券减免金额 |
519 | + chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.SHIPPING_COUPON.getCode()). | ||
520 | + ifPresent(tempPayResult -> amountDetailBo.setShippingCouponCutAmount(tempPayResult.getCouponAmount())); | ||
525 | 521 | ||
526 | return amountDetailBo; | 522 | return amountDetailBo; |
527 | } | 523 | } |
-
Please register or login to post a comment