Authored by caoyan

Merge branch 'test6.9.7' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.7

... ... @@ -80,45 +80,62 @@ public class ChargeService {
tariffAmount = BigDecimalHelper.halfUp(goodsRealPrice.multiply(tariffRate)).doubleValue();
}
AmountCutType amountCutType = null;
SingleFeeDetail tariffDetail = calculateWithCutPolicy(tariffAmount, tariffCutPolicy, "calculateTariffAmount");
tariffDetail.setRate(tariffRate==null ? 0D : tariffRate.doubleValue());
return tariffDetail;
}
if (tariffCutPolicy !=null){
int cutTypeCode = tariffCutPolicy.getType();
amountCutType = AmountCutType.getByCode(cutTypeCode);
}
double tariffCutAmout = 0D;
double finalAmout = tariffAmount;
if (tariffAmount > 0D && amountCutType != null){
switch (amountCutType){
case NO_PROMOTION:
break;
case PERCENT:
double percentDouble = 0D;
try {
percentDouble = YHMath.div(tariffCutPolicy.getPercent(), 100D, 2);
} catch (IllegalAccessException e) {
logger.warn("calculateTariffAmount goodsRealPrice {} tariffCutPolicy {}",
goodsRealPrice, tariffCutPolicy, e);
}
tariffCutAmout = YHMath.mul(tariffAmount, percentDouble);
break;
case FIX_AMOUNT:
tariffCutAmout = tariffCutPolicy.getAmount();
break;
default:
//do nothing for now
tariffCutAmout = 0D;
break;
private SingleFeeDetail calculateWithCutPolicy(double initAmount, AmountCutPolicy cutPolicy, String keyCase){
double cutAmount = 0D, finalAmount = initAmount;
if (initAmount != 0D){
AmountCutType amountCutType = null;
if (cutPolicy !=null){
int cutTypeCode = cutPolicy.getType();
amountCutType = AmountCutType.getByCode(cutTypeCode);
}
if (amountCutType != null){
switch (amountCutType){
case NO_PROMOTION:
break;
case PERCENT:
double percentDouble = 0D;
try {
percentDouble = YHMath.div(cutPolicy.getPercent(), 100D, 2);
} catch (IllegalAccessException e) {
logger.warn("{} init-amount {} CutPolicy {}",
keyCase, initAmount, cutPolicy, e);
}
cutAmount = YHMath.mul(initAmount, percentDouble);
break;
case FIX_AMOUNT:
cutAmount = cutPolicy.getAmount();
break;
default:
//do nothing for now
cutAmount = 0D;
break;
}
finalAmount = YHMath.sub(finalAmount, cutAmount);
}
finalAmout = YHMath.sub(finalAmout, tariffCutAmout);
}
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:
... ...
... ... @@ -33,6 +33,8 @@ public class ChargeResult {
*/
private SingleFeeDetail tariffFee;
private SingleFeeDetail shipFeeDetail;
/**
* 发货方式
*/
... ...
... ... @@ -2,4 +2,5 @@ package com.yohoufo.order.constants;
public interface ClientSpecialSemanticCode {
int needRealName = 440;
int WaitingPayLimit = 512;
}
... ...
... ... @@ -40,7 +40,7 @@ public class ShoppingRiskWatchDog {
if (cnt >= waitingPayCnt){
logger.warn("in ShoppingRiskWatchDog.checkWaitingPayCnt try monopolizing skup another time,uid {} waiting pay cnt {}",
uid, cnt);
throw new UfoServiceException(512, "您有未支付的订单,支付或取消后可提交新的订单");
throw new UfoServiceException(ClientSpecialSemanticCode.WaitingPayLimit, "您有未支付的订单,支付或取消后可提交新的订单");
}
}
... ...
... ... @@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
... ... @@ -104,7 +105,19 @@ public class ShoppingSupport {
//运费
PromotionFormula expressFormula = new PromotionFormula();
expressFormula.setPromotion(OrderConstant.DELIVERY_DESC);
String shipFee = OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(chargeResult.getShippingAmount());
String shipFee;
SingleFeeDetail shipFeeDetail;
if (Objects.nonNull(shipFeeDetail = chargeResult.getShipFeeDetail())){
if (shipFeeDetail.getCutAmount()>0D){
expressFormula.setPromotionAside(OrderConstant.DELIVERY_DESC_ASIDE);
}
String normalShipFee = OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(shipFeeDetail.getAmount());
expressFormula.setNormalAmount(normalShipFee);
//
shipFee = OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(shipFeeDetail.getFinalAmount());
}else{
shipFee = OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(chargeResult.getShippingAmount());
}
expressFormula.setPromotionAmount(shipFee);
formulas.add(expressFormula);
//税费
... ...