Authored by chenchao

add range as threshold 4 calculate goods service fee

@@ -19,6 +19,13 @@ public class PlatformFeeDto { @@ -19,6 +19,13 @@ public class PlatformFeeDto {
19 * 有货包装费(暂定5元) 19 * 有货包装费(暂定5元)
20 */ 20 */
21 BigDecimal packageFee;// = new BigDecimal(5); 21 BigDecimal packageFee;// = new BigDecimal(5);
22 - 22 + /**
  23 + * 货款抽成
  24 + */
23 BigDecimal serviceFee; 25 BigDecimal serviceFee;
  26 + /**
  27 + * 货款抽成上下限制
  28 + * from version 6.9.8
  29 + */
  30 + PriceRange goodsServiceFeeRange;
24 } 31 }
  1 +package com.yohoufo.order.model.dto;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Builder;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +@Data
  9 +@Builder
  10 +@AllArgsConstructor
  11 +@NoArgsConstructor
  12 +public class PriceRange {
  13 +
  14 + private double min;
  15 +
  16 + private double max;
  17 +}
@@ -14,7 +14,6 @@ import java.math.BigDecimal; @@ -14,7 +14,6 @@ import java.math.BigDecimal;
14 import java.util.Collection; 14 import java.util.Collection;
15 import java.util.Map; 15 import java.util.Map;
16 import java.util.Objects; 16 import java.util.Objects;
17 -import java.util.Optional;  
18 import java.util.function.Supplier; 17 import java.util.function.Supplier;
19 18
20 /** 19 /**
@@ -71,14 +70,20 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle @@ -71,14 +70,20 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
71 return result; 70 return result;
72 } 71 }
73 72
74 - protected BigDecimal calCrossWithThreshold(BigDecimal min, BigDecimal max, BigDecimal calByRate){  
75 - if(calByRate.compareTo(min) < 0){  
76 - calByRate = min; 73 + protected BigDecimal calCrossWithThreshold(BigDecimal min, BigDecimal max, BigDecimal fee){
  74 + boolean minIsLegal = isPositive(min);
  75 + if(minIsLegal && fee.compareTo(min) < 0){
  76 + fee = min;
77 } 77 }
78 - if (calByRate.compareTo(max) > 0){  
79 - calByRate = max; 78 + boolean maxIsLegal = isPositive(max);
  79 + if (maxIsLegal && fee.compareTo(max) > 0){
  80 + fee = max;
80 } 81 }
81 - return calByRate; 82 + return fee;
  83 + }
  84 +
  85 + private boolean isPositive(BigDecimal val){
  86 + return Objects.nonNull(val) && BigDecimal.ZERO.compareTo(val) < 0;
82 } 87 }
83 88
84 protected BigDecimal halfUp(BigDecimal fee){ 89 protected BigDecimal halfUp(BigDecimal fee){
@@ -119,17 +124,21 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle @@ -119,17 +124,21 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
119 Supplier<PlatformFeeDto> plaformFeeConfigSupplier = ()->getPlatformFeeDtoConfig(); 124 Supplier<PlatformFeeDto> plaformFeeConfigSupplier = ()->getPlatformFeeDtoConfig();
120 BigDecimal appraiseFee; 125 BigDecimal appraiseFee;
121 BigDecimal packageFee; 126 BigDecimal packageFee;
  127 + //公共配置
  128 + PlatformFeeDto pfc = plaformFeeConfigSupplier.get();
  129 + //个性化配置为空,使用公共配置
122 if (ppf == null){ 130 if (ppf == null){
123 - PlatformFeeDto pfc = plaformFeeConfigSupplier.get(); 131 +
124 appraiseFee = pfc.getAppraiseFee(); 132 appraiseFee = pfc.getAppraiseFee();
125 packageFee = pfc.getPackageFee(); 133 packageFee = pfc.getPackageFee();
  134 +
126 }else{ 135 }else{
127 - appraiseFee = ppf.getAppraiseFee() != null ? ppf.getAppraiseFee() : plaformFeeConfigSupplier.get().getAppraiseFee();  
128 - packageFee = ppf.getPackageFee() != null ? ppf.getPackageFee() : plaformFeeConfigSupplier.get().getPackageFee(); 136 + appraiseFee = ppf.getAppraiseFee() != null ? ppf.getAppraiseFee() : pfc.getAppraiseFee();
  137 + packageFee = ppf.getPackageFee() != null ? ppf.getPackageFee() : pfc.getPackageFee();
129 } 138 }
130 -  
131 - BigDecimal serviceFee = price.multiply(goodsServiceRate);  
132 - 139 + //目前而言,商品抽成的阈值只有公共配置
  140 + PriceRange goodsServiceFeeRange = pfc.getGoodsServiceFeeRange();
  141 + BigDecimal serviceFee = calGoodsServiceFee(goodsServiceFeeRange, price, goodsServiceRate);
133 platformFee.setAppraiseFee(halfUp(appraiseFee)); 142 platformFee.setAppraiseFee(halfUp(appraiseFee));
134 platformFee.setPackageFee(halfUp(packageFee)); 143 platformFee.setPackageFee(halfUp(packageFee));
135 BigDecimal total = appraiseFee.add(packageFee).add(serviceFee); 144 BigDecimal total = appraiseFee.add(packageFee).add(serviceFee);
@@ -139,6 +148,24 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle @@ -139,6 +148,24 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
139 return platformFee; 148 return platformFee;
140 } 149 }
141 150
  151 +
  152 + BigDecimal calGoodsServiceFee(PriceRange goodsServiceFeeRange, BigDecimal price, BigDecimal goodsServiceRate){
  153 + BigDecimal serviceFee = price.multiply(goodsServiceRate);
  154 + //没有配置上下限
  155 + if (Objects.isNull(goodsServiceFeeRange)){
  156 + logger.info("calGoodsServiceFee no config goodsServiceFeeRange, price {} goodsServiceRate {}",
  157 + price, goodsServiceRate);
  158 + }else{
  159 + BigDecimal min = new BigDecimal(goodsServiceFeeRange.getMin());
  160 + BigDecimal max = new BigDecimal(goodsServiceFeeRange.getMax());
  161 + serviceFee = calCrossWithThreshold(min, max, serviceFee);
  162 + }
  163 +
  164 + return serviceFee;
  165 + }
  166 +
  167 +
  168 +
142 protected abstract PlatformFeeDto buildDefaultPlatformFeeDto(); 169 protected abstract PlatformFeeDto buildDefaultPlatformFeeDto();
143 170
144 171