|
@@ -80,45 +80,62 @@ public class ChargeService { |
|
@@ -80,45 +80,62 @@ public class ChargeService { |
80
|
tariffAmount = BigDecimalHelper.halfUp(goodsRealPrice.multiply(tariffRate)).doubleValue();
|
80
|
tariffAmount = BigDecimalHelper.halfUp(goodsRealPrice.multiply(tariffRate)).doubleValue();
|
81
|
}
|
81
|
}
|
82
|
|
82
|
|
83
|
- AmountCutType amountCutType = null;
|
83
|
+ SingleFeeDetail tariffDetail = calculateWithCutPolicy(tariffAmount, tariffCutPolicy, "calculateTariffAmount");
|
|
|
84
|
+ tariffDetail.setRate(tariffRate==null ? 0D : tariffRate.doubleValue());
|
|
|
85
|
+ return tariffDetail;
|
|
|
86
|
+ }
|
84
|
|
87
|
|
85
|
- if (tariffCutPolicy !=null){
|
|
|
86
|
- int cutTypeCode = tariffCutPolicy.getType();
|
|
|
87
|
- amountCutType = AmountCutType.getByCode(cutTypeCode);
|
|
|
88
|
- }
|
|
|
89
|
- double tariffCutAmout = 0D;
|
|
|
90
|
- double finalAmout = tariffAmount;
|
|
|
91
|
- if (tariffAmount > 0D && amountCutType != null){
|
|
|
92
|
|
88
|
|
93
|
- switch (amountCutType){
|
|
|
94
|
- case NO_PROMOTION:
|
|
|
95
|
- break;
|
|
|
96
|
- case PERCENT:
|
|
|
97
|
- double percentDouble = 0D;
|
|
|
98
|
- try {
|
|
|
99
|
- percentDouble = YHMath.div(tariffCutPolicy.getPercent(), 100D, 2);
|
|
|
100
|
- } catch (IllegalAccessException e) {
|
|
|
101
|
- logger.warn("calculateTariffAmount goodsRealPrice {} tariffCutPolicy {}",
|
|
|
102
|
- goodsRealPrice, tariffCutPolicy, e);
|
|
|
103
|
- }
|
|
|
104
|
- tariffCutAmout = YHMath.mul(tariffAmount, percentDouble);
|
|
|
105
|
|
89
|
|
106
|
- break;
|
|
|
107
|
- case FIX_AMOUNT:
|
|
|
108
|
- tariffCutAmout = tariffCutPolicy.getAmount();
|
|
|
109
|
- break;
|
|
|
110
|
- default:
|
|
|
111
|
- //do nothing for now
|
|
|
112
|
- tariffCutAmout = 0D;
|
|
|
113
|
- break;
|
90
|
+ private SingleFeeDetail calculateWithCutPolicy(double initAmount, AmountCutPolicy cutPolicy, String keyCase){
|
|
|
91
|
+ double cutAmount = 0D, finalAmount = initAmount;
|
|
|
92
|
+ if (initAmount != 0D){
|
|
|
93
|
+ AmountCutType amountCutType = null;
|
|
|
94
|
+
|
|
|
95
|
+ if (cutPolicy !=null){
|
|
|
96
|
+ int cutTypeCode = cutPolicy.getType();
|
|
|
97
|
+ amountCutType = AmountCutType.getByCode(cutTypeCode);
|
|
|
98
|
+ }
|
|
|
99
|
+ if (amountCutType != null){
|
|
|
100
|
+
|
|
|
101
|
+ switch (amountCutType){
|
|
|
102
|
+ case NO_PROMOTION:
|
|
|
103
|
+ break;
|
|
|
104
|
+ case PERCENT:
|
|
|
105
|
+ double percentDouble = 0D;
|
|
|
106
|
+ try {
|
|
|
107
|
+ percentDouble = YHMath.div(cutPolicy.getPercent(), 100D, 2);
|
|
|
108
|
+ } catch (IllegalAccessException e) {
|
|
|
109
|
+ logger.warn("{} init-amount {} CutPolicy {}",
|
|
|
110
|
+ keyCase, initAmount, cutPolicy, e);
|
|
|
111
|
+ }
|
|
|
112
|
+ cutAmount = YHMath.mul(initAmount, percentDouble);
|
|
|
113
|
+
|
|
|
114
|
+ break;
|
|
|
115
|
+ case FIX_AMOUNT:
|
|
|
116
|
+ cutAmount = cutPolicy.getAmount();
|
|
|
117
|
+ break;
|
|
|
118
|
+ default:
|
|
|
119
|
+ //do nothing for now
|
|
|
120
|
+ cutAmount = 0D;
|
|
|
121
|
+ break;
|
|
|
122
|
+ }
|
|
|
123
|
+ finalAmount = YHMath.sub(finalAmount, cutAmount);
|
114
|
}
|
124
|
}
|
115
|
- finalAmout = YHMath.sub(finalAmout, tariffCutAmout);
|
|
|
116
|
}
|
125
|
}
|
117
|
- SingleFeeDetail tariffDetail = SingleFeeDetail.builder().amount(tariffAmount)
|
|
|
118
|
- .cutAmount(tariffCutAmout)
|
|
|
119
|
- .rate(tariffRate==null ? 0D : tariffRate.doubleValue())
|
|
|
120
|
- .finalAmount(finalAmout).build();
|
126
|
+
|
|
|
127
|
+
|
|
|
128
|
+ SingleFeeDetail tariffDetail = SingleFeeDetail.builder()
|
|
|
129
|
+ .amount(initAmount)
|
|
|
130
|
+ .cutAmount(cutAmount)
|
|
|
131
|
+ .finalAmount(finalAmount).build();
|
121
|
return tariffDetail;
|
132
|
return tariffDetail;
|
|
|
133
|
+
|
|
|
134
|
+ }
|
|
|
135
|
+
|
|
|
136
|
+
|
|
|
137
|
+ private SingleFeeDetail calculateOverSeasOrderShipAmount(double shipFee, AmountCutPolicy shipCutPolicy){
|
|
|
138
|
+ return calculateWithCutPolicy(shipFee, shipCutPolicy, "calculateOverSeasOrderShipAmount");
|
122
|
}
|
139
|
}
|
123
|
/**
|
140
|
/**
|
124
|
* 计算商品金额
|
141
|
* 计算商品金额
|
|
@@ -203,6 +220,10 @@ public class ChargeService { |
|
@@ -203,6 +220,10 @@ public class ChargeService { |
203
|
break;
|
220
|
break;
|
204
|
case OVERSEAS_HONGHONG:
|
221
|
case OVERSEAS_HONGHONG:
|
205
|
deliveryWayCost = deliveryWayCostSupport.getCostFromHk();
|
222
|
deliveryWayCost = deliveryWayCostSupport.getCostFromHk();
|
|
|
223
|
+ AmountCutPolicy shipFeeCutPolicy = chargeContext.getChargeParam().getShipFeeCutPolicy();
|
|
|
224
|
+ SingleFeeDetail shipFeeDetail = calculateOverSeasOrderShipAmount(deliveryWayCost, shipFeeCutPolicy);
|
|
|
225
|
+ deliveryWayCost = shipFeeDetail.getFinalAmount();
|
|
|
226
|
+ chargeContext.getChargeResult().setShipFeeDetail(shipFeeDetail);
|
206
|
break;
|
227
|
break;
|
207
|
case SF:
|
228
|
case SF:
|
208
|
default:
|
229
|
default:
|