Authored by LUOXC

Merge branch 'dev_货款抽成服务费上下限' into hotfix-0719

... ... @@ -19,6 +19,13 @@ public class PlatformFeeDto {
* 有货包装费(暂定5元)
*/
BigDecimal packageFee;// = new BigDecimal(5);
/**
* 货款抽成
*/
BigDecimal serviceFee;
/**
* 货款抽成上下限制
* from version 6.9.8
*/
PriceRange goodsServiceFeeRange;
}
... ...
package com.yohoufo.order.model.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PriceRange {
private double min;
private double max;
}
... ...
... ... @@ -14,7 +14,6 @@ import java.math.BigDecimal;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
/**
... ... @@ -71,14 +70,20 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
return result;
}
protected BigDecimal calCrossWithThreshold(BigDecimal min, BigDecimal max, BigDecimal calByRate){
if(calByRate.compareTo(min) < 0){
calByRate = min;
protected BigDecimal calCrossWithThreshold(BigDecimal min, BigDecimal max, BigDecimal fee){
boolean minIsLegal = isPositive(min);
if(minIsLegal && fee.compareTo(min) < 0){
fee = min;
}
if (calByRate.compareTo(max) > 0){
calByRate = max;
boolean maxIsLegal = isPositive(max);
if (maxIsLegal && fee.compareTo(max) > 0){
fee = max;
}
return calByRate;
return fee;
}
private boolean isPositive(BigDecimal val){
return Objects.nonNull(val) && BigDecimal.ZERO.compareTo(val) < 0;
}
protected BigDecimal halfUp(BigDecimal fee){
... ... @@ -119,17 +124,21 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
Supplier<PlatformFeeDto> plaformFeeConfigSupplier = ()->getPlatformFeeDtoConfig();
BigDecimal appraiseFee;
BigDecimal packageFee;
//公共配置
PlatformFeeDto pfc = plaformFeeConfigSupplier.get();
//个性化配置为空,使用公共配置
if (ppf == null){
PlatformFeeDto pfc = plaformFeeConfigSupplier.get();
appraiseFee = pfc.getAppraiseFee();
packageFee = pfc.getPackageFee();
}else{
appraiseFee = ppf.getAppraiseFee() != null ? ppf.getAppraiseFee() : plaformFeeConfigSupplier.get().getAppraiseFee();
packageFee = ppf.getPackageFee() != null ? ppf.getPackageFee() : plaformFeeConfigSupplier.get().getPackageFee();
appraiseFee = ppf.getAppraiseFee() != null ? ppf.getAppraiseFee() : pfc.getAppraiseFee();
packageFee = ppf.getPackageFee() != null ? ppf.getPackageFee() : pfc.getPackageFee();
}
BigDecimal serviceFee = price.multiply(goodsServiceRate);
//目前而言,商品抽成的阈值只有公共配置
PriceRange goodsServiceFeeRange = pfc.getGoodsServiceFeeRange();
BigDecimal serviceFee = calGoodsServiceFee(goodsServiceFeeRange, price, goodsServiceRate);
platformFee.setAppraiseFee(halfUp(appraiseFee));
platformFee.setPackageFee(halfUp(packageFee));
BigDecimal total = appraiseFee.add(packageFee).add(serviceFee);
... ... @@ -139,6 +148,24 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
return platformFee;
}
BigDecimal calGoodsServiceFee(PriceRange goodsServiceFeeRange, BigDecimal price, BigDecimal goodsServiceRate){
BigDecimal serviceFee = price.multiply(goodsServiceRate);
//没有配置上下限
if (Objects.isNull(goodsServiceFeeRange)){
logger.info("calGoodsServiceFee no config goodsServiceFeeRange, price {} goodsServiceRate {}",
price, goodsServiceRate);
}else{
BigDecimal min = new BigDecimal(goodsServiceFeeRange.getMin());
BigDecimal max = new BigDecimal(goodsServiceFeeRange.getMax());
serviceFee = calCrossWithThreshold(min, max, serviceFee);
}
return serviceFee;
}
protected abstract PlatformFeeDto buildDefaultPlatformFeeDto();
... ...