...
|
...
|
@@ -80,15 +80,23 @@ public class ChargeService { |
|
|
tariffAmount = BigDecimalHelper.halfUp(goodsRealPrice.multiply(tariffRate)).doubleValue();
|
|
|
}
|
|
|
|
|
|
SingleFeeDetail tariffDetail = calculateWithCutPolicy(tariffAmount, tariffCutPolicy, "calculateTariffAmount");
|
|
|
tariffDetail.setRate(tariffRate==null ? 0D : tariffRate.doubleValue());
|
|
|
return tariffDetail;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SingleFeeDetail calculateWithCutPolicy(double initAmount, AmountCutPolicy cutPolicy, String keyCase){
|
|
|
double cutAmount = 0D, finalAmount = initAmount;
|
|
|
if (initAmount != 0D){
|
|
|
AmountCutType amountCutType = null;
|
|
|
|
|
|
if (tariffCutPolicy !=null){
|
|
|
int cutTypeCode = tariffCutPolicy.getType();
|
|
|
if (cutPolicy !=null){
|
|
|
int cutTypeCode = cutPolicy.getType();
|
|
|
amountCutType = AmountCutType.getByCode(cutTypeCode);
|
|
|
}
|
|
|
double tariffCutAmout = 0D;
|
|
|
double finalAmout = tariffAmount;
|
|
|
if (tariffAmount > 0D && amountCutType != null){
|
|
|
if (amountCutType != null){
|
|
|
|
|
|
switch (amountCutType){
|
|
|
case NO_PROMOTION:
|
...
|
...
|
@@ -96,29 +104,38 @@ public class ChargeService { |
|
|
case PERCENT:
|
|
|
double percentDouble = 0D;
|
|
|
try {
|
|
|
percentDouble = YHMath.div(tariffCutPolicy.getPercent(), 100D, 2);
|
|
|
percentDouble = YHMath.div(cutPolicy.getPercent(), 100D, 2);
|
|
|
} catch (IllegalAccessException e) {
|
|
|
logger.warn("calculateTariffAmount goodsRealPrice {} tariffCutPolicy {}",
|
|
|
goodsRealPrice, tariffCutPolicy, e);
|
|
|
logger.warn("{} init-amount {} CutPolicy {}",
|
|
|
keyCase, initAmount, cutPolicy, e);
|
|
|
}
|
|
|
tariffCutAmout = YHMath.mul(tariffAmount, percentDouble);
|
|
|
cutAmount = YHMath.mul(initAmount, percentDouble);
|
|
|
|
|
|
break;
|
|
|
case FIX_AMOUNT:
|
|
|
tariffCutAmout = tariffCutPolicy.getAmount();
|
|
|
cutAmount = cutPolicy.getAmount();
|
|
|
break;
|
|
|
default:
|
|
|
//do nothing for now
|
|
|
tariffCutAmout = 0D;
|
|
|
cutAmount = 0D;
|
|
|
break;
|
|
|
}
|
|
|
finalAmout = YHMath.sub(finalAmout, tariffCutAmout);
|
|
|
finalAmount = YHMath.sub(finalAmount, cutAmount);
|
|
|
}
|
|
|
}
|
|
|
SingleFeeDetail tariffDetail = SingleFeeDetail.builder().amount(tariffAmount)
|
|
|
.cutAmount(tariffCutAmout)
|
|
|
.rate(tariffRate==null ? 0D : tariffRate.doubleValue())
|
|
|
.finalAmount(finalAmout).build();
|
|
|
|
|
|
|
|
|
SingleFeeDetail tariffDetail = SingleFeeDetail.builder()
|
|
|
.amount(initAmount)
|
|
|
.cutAmount(cutAmount)
|
|
|
.finalAmount(finalAmount).build();
|
|
|
return tariffDetail;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private SingleFeeDetail calculateOverSeasOrderShipAmount(double shipFee, AmountCutPolicy shipCutPolicy){
|
|
|
return calculateWithCutPolicy(shipFee, shipCutPolicy, "calculateOverSeasOrderShipAmount");
|
|
|
}
|
|
|
/**
|
|
|
* 计算商品金额
|
...
|
...
|
@@ -203,6 +220,10 @@ public class ChargeService { |
|
|
break;
|
|
|
case OVERSEAS_HONGHONG:
|
|
|
deliveryWayCost = deliveryWayCostSupport.getCostFromHk();
|
|
|
AmountCutPolicy shipFeeCutPolicy = chargeContext.getChargeParam().getShipFeeCutPolicy();
|
|
|
SingleFeeDetail shipFeeDetail = calculateOverSeasOrderShipAmount(deliveryWayCost, shipFeeCutPolicy);
|
|
|
deliveryWayCost = shipFeeDetail.getFinalAmount();
|
|
|
chargeContext.getChargeResult().setShipFeeDetail(shipFeeDetail);
|
|
|
break;
|
|
|
case SF:
|
|
|
default:
|
...
|
...
|
|