...
|
...
|
@@ -5,8 +5,6 @@ import com.yohoufo.common.utils.BigDecimalHelper; |
|
|
import com.yohoufo.order.model.dto.*;
|
|
|
import com.yohoufo.order.service.impl.MetaConfigService;
|
|
|
import com.yohoufo.order.service.impl.OrderDynamicConfig;
|
|
|
import com.yohoufo.order.service.seller.fee.GoodsServiceFeeRateDimension;
|
|
|
import com.yohoufo.order.service.seller.fee.GoodsServiceFeeRateWrapper;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
...
|
...
|
@@ -50,21 +48,23 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle |
|
|
@Override
|
|
|
public SellerOrderComputeResult compute(BigDecimal prdPrice,
|
|
|
SellerOrderComputeResult personalComputeConfig){
|
|
|
|
|
|
final boolean personalComputeConfigExist;
|
|
|
Integer uid = (personalComputeConfigExist= Objects.nonNull(personalComputeConfig)) ? personalComputeConfig.getUid() : null;
|
|
|
Integer storageId = personalComputeConfigExist ? personalComputeConfig.getStorageId() : null;
|
|
|
//计算保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200))
|
|
|
EarnestMoney earnestMoney = calEarnestMoney(prdPrice);
|
|
|
//init fee rate
|
|
|
List<ServiceFeeRate> psfr = personalComputeConfig!=null ? personalComputeConfig.getServiceFeeRates() : null;
|
|
|
List<ServiceFeeRate> psfr = personalComputeConfigExist ? personalComputeConfig.getServiceFeeRates() : null;
|
|
|
//目前根据商品类型匹配费率,未来的趋势是有多维度配置,根据策略择优
|
|
|
PlatformFeeDto ppf = personalComputeConfig!=null ? personalComputeConfig.getPlatformFee() : null;
|
|
|
PlatformFeeDto ppf = personalComputeConfigExist ? personalComputeConfig.getPlatformFee() : null;
|
|
|
//计算平台费用:1.鉴定费 2.包装费 3.货款抽成
|
|
|
Pair<ServiceFeeRate,PlatformFeeDto> calPlatformFee = calPlatformFee(prdPrice, psfr, ppf);
|
|
|
Pair<ServiceFeeRate,PlatformFeeDto> calPlatformFee = calPlatformFee(uid, storageId, prdPrice, psfr, ppf);
|
|
|
ServiceFeeRate serviceFeeRate = calPlatformFee.getLeft();
|
|
|
PlatformFeeDto platformFeeDto = calPlatformFee.getRight();
|
|
|
//计算支付服务费
|
|
|
BigDecimal bankTransferFee = calBankTransferFee(prdPrice, serviceFeeRate.getPayChannelRate());
|
|
|
logger.info("in SellerOrder Compute, prdPrice {}, platformFee {}, bankTransferFee {}",
|
|
|
prdPrice, platformFeeDto, bankTransferFee);
|
|
|
logger.info("in SellerOrder Compute,uid {} storageId {}, prdPrice {}, platformFee {}, bankTransferFee {}",
|
|
|
uid, storageId, prdPrice, platformFeeDto, bankTransferFee);
|
|
|
//计算收入
|
|
|
BigDecimal income = calIncome(prdPrice, platformFeeDto.getTotal(), bankTransferFee);
|
|
|
//目前只有预售有买家和卖家阶梯处罚
|
...
|
...
|
@@ -151,7 +151,11 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle |
|
|
* 服务费参与计算后需要考虑精度问题(四舍五入)
|
|
|
* @return
|
|
|
*/
|
|
|
protected Pair<ServiceFeeRate,PlatformFeeDto> calPlatformFee(BigDecimal price, List<ServiceFeeRate> serviceFeeRates, PlatformFeeDto ppf){
|
|
|
protected Pair<ServiceFeeRate,PlatformFeeDto> calPlatformFee(Integer uid,
|
|
|
Integer storageId,
|
|
|
BigDecimal price,
|
|
|
List<ServiceFeeRate> serviceFeeRates,
|
|
|
PlatformFeeDto ppf){
|
|
|
|
|
|
|
|
|
PlatformFeeDto platformFee = new PlatformFeeDto();
|
...
|
...
|
@@ -173,7 +177,7 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle |
|
|
}
|
|
|
//目前而言,商品抽成的阈值只有公共配置
|
|
|
PriceRange defaultGoodsServiceFeeRange = pfc.getGoodsServiceFeeRange();
|
|
|
ChooseServiceReeRateAndCalServiceFeeModel chooseServiceReeRateAndCalServiceFee = new ChooseServiceReeRateAndCalServiceFeeModel(price, serviceFeeRates, defaultGoodsServiceFeeRange)
|
|
|
ChooseServiceReeRateAndCalServiceFeeModel chooseServiceReeRateAndCalServiceFee = new ChooseServiceReeRateAndCalServiceFeeModel(uid, storageId, price, serviceFeeRates, defaultGoodsServiceFeeRange)
|
|
|
.invoke();
|
|
|
ServiceFeeRate serviceFeeRate = chooseServiceReeRateAndCalServiceFee.getServiceFeeRate();
|
|
|
BigDecimal serviceFee = chooseServiceReeRateAndCalServiceFee.getServiceFee();
|
...
|
...
|
@@ -231,13 +235,21 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle |
|
|
protected abstract Collection<BuyerPenalty.Fee> buildStagedCollection();
|
|
|
|
|
|
private class ChooseServiceReeRateAndCalServiceFeeModel {
|
|
|
private Integer uid;
|
|
|
private Integer storageId;
|
|
|
private BigDecimal price;
|
|
|
private List<ServiceFeeRate> serviceFeeRates;
|
|
|
private PriceRange defaultGoodsServiceFeeRange;
|
|
|
private ServiceFeeRate serviceFeeRate;
|
|
|
private BigDecimal serviceFee;
|
|
|
|
|
|
public ChooseServiceReeRateAndCalServiceFeeModel(BigDecimal price, List<ServiceFeeRate> serviceFeeRates, PriceRange defaultGoodsServiceFeeRange) {
|
|
|
public ChooseServiceReeRateAndCalServiceFeeModel(Integer uid,
|
|
|
Integer storageId,
|
|
|
BigDecimal price,
|
|
|
List<ServiceFeeRate> serviceFeeRates,
|
|
|
PriceRange defaultGoodsServiceFeeRange) {
|
|
|
this.uid = uid;
|
|
|
this.storageId = storageId;
|
|
|
this.price = price;
|
|
|
this.serviceFeeRates = serviceFeeRates;
|
|
|
this.defaultGoodsServiceFeeRange = defaultGoodsServiceFeeRange;
|
...
|
...
|
@@ -256,16 +268,27 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle |
|
|
serviceFeeRate = buildDefaultServiceFeeRate();
|
|
|
serviceFee = calServiceFee(price, serviceFeeRate, defaultGoodsServiceFeeRange);
|
|
|
} else {
|
|
|
for (ServiceFeeRate e : serviceFeeRates) {
|
|
|
PriceRange priceRange = Objects.nonNull(e.getGoodsPaymentPriceRange()) ? e.getGoodsPaymentPriceRange() : defaultGoodsServiceFeeRange;
|
|
|
BigDecimal tmp = calServiceFee(price, e, priceRange);
|
|
|
if (Objects.isNull(serviceFee) || serviceFee.compareTo(tmp) > 0) {
|
|
|
serviceFeeRate = e;
|
|
|
serviceFee = tmp;
|
|
|
}
|
|
|
}
|
|
|
ServiceFeeRate minSFR = matchMinRate(serviceFeeRates);
|
|
|
logger.info("compute CalServiceFee uid {} storageId {} price {} serviceFeeRates {} defaultGoodsServiceFeeRange {} minSFR{}",
|
|
|
uid, storageId, price, serviceFeeRates, defaultGoodsServiceFeeRange, minSFR);
|
|
|
PriceRange priceRange = Objects.nonNull(minSFR.getGoodsPaymentPriceRange()) ? minSFR.getGoodsPaymentPriceRange() : defaultGoodsServiceFeeRange;
|
|
|
BigDecimal tmp = calServiceFee(price, minSFR, priceRange);
|
|
|
serviceFeeRate = minSFR;
|
|
|
serviceFee = tmp;
|
|
|
}
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
private ServiceFeeRate matchMinRate(List<ServiceFeeRate> serviceFeeRates){
|
|
|
ServiceFeeRate min = null;
|
|
|
for (ServiceFeeRate e : serviceFeeRates) {
|
|
|
if (Objects.isNull(min) || min.getGoodsPaymentRate().compareTo(e.getGoodsPaymentRate()) > 0) {
|
|
|
min = e;
|
|
|
}
|
|
|
}
|
|
|
return min;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|