Authored by LUOXC

refacotr

@@ -48,8 +48,7 @@ public class BuyerCancelCompensateComputeHandler { @@ -48,8 +48,7 @@ public class BuyerCancelCompensateComputeHandler {
48 BigDecimal orderActualAmount = buyerOrder.getAmount(); 48 BigDecimal orderActualAmount = buyerOrder.getAmount();
49 BigDecimal goodsActualAmount = buyerOrderGoods.getGoodsAmount(); 49 BigDecimal goodsActualAmount = buyerOrderGoods.getGoodsAmount();
50 OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes()); 50 OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes());
51 - BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, targetStatus, orderActualAmount, goodsActualAmount, orderAttributes);  
52 - return bpcr; 51 + return calBuyerPenalty(buyerUid, orderCode, targetStatus, orderActualAmount, goodsActualAmount, orderAttributes);
53 } 52 }
54 53
55 /** 54 /**
@@ -78,14 +77,10 @@ public class BuyerCancelCompensateComputeHandler { @@ -78,14 +77,10 @@ public class BuyerCancelCompensateComputeHandler {
78 .diffTime(diffTime) 77 .diffTime(diffTime)
79 .select() 78 .select()
80 .orElseThrow(() -> new UfoServiceException(501, "not match calFee")); 79 .orElseThrow(() -> new UfoServiceException(501, "not match calFee"));
81 - BuyerPenaltyCalResult bpcr = calBuyerPenalty(penaltyRule, buyerUid, orderCode, orderActualAmount, goodsActualAmount);  
82 - if (bpcr.getLeftAmount().compareTo(BigDecimal.ZERO) <= 0) {  
83 - throw new UfoServiceException(501, "left amount not enough");  
84 - }  
85 - return bpcr; 80 + return calBuyerPenalty(penaltyRule, buyerUid, orderCode, orderActualAmount, goodsActualAmount);
86 } 81 }
87 82
88 - public BuyerPenaltyCalResult calBuyerPenalty(PenaltyRule penaltyRule, Integer buyerUid, Long orderCode, 83 + private BuyerPenaltyCalResult calBuyerPenalty(PenaltyRule penaltyRule, Integer buyerUid, Long orderCode,
89 BigDecimal orderActualAmount, BigDecimal goodsActualAmount) { 84 BigDecimal orderActualAmount, BigDecimal goodsActualAmount) {
90 BigDecimal penaltyRate = penaltyRule.getPenaltyRate(); 85 BigDecimal penaltyRate = penaltyRule.getPenaltyRate();
91 BigDecimal penaltyAmount = BigDecimalHelper.halfUp(goodsActualAmount.multiply(penaltyRate)); 86 BigDecimal penaltyAmount = BigDecimalHelper.halfUp(goodsActualAmount.multiply(penaltyRate));
@@ -95,6 +90,10 @@ public class BuyerCancelCompensateComputeHandler { @@ -95,6 +90,10 @@ public class BuyerCancelCompensateComputeHandler {
95 if (Objects.nonNull(penaltyRule.getPenaltyMaxAmount()) && penaltyAmount.compareTo(penaltyRule.getPenaltyMaxAmount()) > 0) { 90 if (Objects.nonNull(penaltyRule.getPenaltyMaxAmount()) && penaltyAmount.compareTo(penaltyRule.getPenaltyMaxAmount()) > 0) {
96 penaltyAmount = penaltyRule.getPenaltyMaxAmount(); 91 penaltyAmount = penaltyRule.getPenaltyMaxAmount();
97 } 92 }
  93 + // 如果赔偿金额大于支付金额
  94 + if (penaltyAmount.compareTo(orderActualAmount) > 0){
  95 + penaltyAmount = orderActualAmount;
  96 + }
98 BigDecimal leftAmount = orderActualAmount.subtract(penaltyAmount); 97 BigDecimal leftAmount = orderActualAmount.subtract(penaltyAmount);
99 BuyerPenaltyCalResult bpcr = BuyerPenaltyCalResult.builder() 98 BuyerPenaltyCalResult bpcr = BuyerPenaltyCalResult.builder()
100 .uid(buyerUid).orderCode(orderCode) 99 .uid(buyerUid).orderCode(orderCode)