|
|
package com.yohoufo.order.service.support;
|
|
|
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yohobuy.ufo.model.order.common.EntrySellerType;
|
|
|
import com.yohobuy.ufo.model.order.constants.SkupType;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderStatsResult;
|
|
|
import com.yohoufo.order.model.bo.PlatformServiceFeeDefinition;
|
|
|
import com.yohoufo.order.model.bo.SellerPlatformServiceFee;
|
|
|
import com.yohoufo.order.model.bo.SellerServiceFeeRuleDefinition;
|
|
|
import com.yohoufo.order.service.cache.SellerServiceFeeRuleCacheService;
|
|
|
import com.yohoufo.order.service.seller.setting.SellerService;
|
|
|
import com.yohoufo.order.service.stats.StatsConfigManager;
|
|
|
import com.yohoufo.order.service.stats.impl.SellerOrderStatsConfiguration;
|
|
|
import com.yohoufo.order.service.stats.impl.SellerOrderStatsEntry;
|
...
|
...
|
@@ -17,9 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by jiexiang.wu on 2019/7/23.
|
...
|
...
|
@@ -35,6 +35,47 @@ public class SellerPlatformServiceFeeSupport { |
|
|
@Autowired
|
|
|
private SellerServiceFeeRuleCacheService sellerServiceFeeRuleCacheService;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerService sellerService;
|
|
|
|
|
|
/**
|
|
|
* 当前周期
|
|
|
*
|
|
|
* @param uid
|
|
|
* @return
|
|
|
*/
|
|
|
public SellerPlatformServiceFee currentPeriod(int uid, SkupType skupType) {
|
|
|
//当前的扣点服务
|
|
|
SellerOrderStatsEntry currentStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).skupType(skupType).time(com.yohoufo.common.utils.DateUtil.getCurrentTimeSecond()).build();
|
|
|
SellerOrderStatsConfiguration currentStatsConfig = statsConfigurationManager.getStatsConfig(currentStatsEntry);
|
|
|
SellerOrderStatsResult statsResult = (SellerOrderStatsResult) statsConfigurationManager.getStatsProcessor(currentStatsConfig.getStatsProcessorName()).getResult(currentStatsEntry, currentStatsConfig);
|
|
|
if (Objects.isNull(statsResult)) {
|
|
|
statsResult = createEmptyStatsResult(uid);
|
|
|
}
|
|
|
return this.buildSellerPlatformServiceFee(uid, statsResult);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 下个周期的
|
|
|
*
|
|
|
* @param uid
|
|
|
* @return
|
|
|
*/
|
|
|
public SellerPlatformServiceFee nextPeriod(int uid, SkupType skupType) {
|
|
|
//下个周期
|
|
|
SellerOrderStatsEntry nextStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).skupType(skupType).build();
|
|
|
SellerOrderStatsConfiguration nextStatsConfig = statsConfigurationManager.getStatsConfig(nextStatsEntry);
|
|
|
//设置查询时间为下个周期的开始时间
|
|
|
nextStatsEntry.setTime(nextStatsConfig.getStatsUnit().nextPeriodTimeTuple(nextStatsConfig.getStatsPeriod(), nextStatsConfig.getStatsPeriod()).getKey());
|
|
|
SellerOrderStatsResult statsResult = (SellerOrderStatsResult) statsConfigurationManager.getStatsProcessor(nextStatsConfig.getStatsProcessorName()).getResult(nextStatsEntry, nextStatsConfig);
|
|
|
if (Objects.isNull(statsResult)) {
|
|
|
statsResult = createEmptyStatsResult(uid);
|
|
|
}
|
|
|
return this.buildSellerPlatformServiceFee(uid, statsResult);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取平台技术服务费比例
|
|
|
*
|
...
|
...
|
@@ -45,13 +86,8 @@ public class SellerPlatformServiceFeeSupport { |
|
|
public BigDecimal getPlatformServiceFeeRate(int uid, SkupType skupType) {
|
|
|
logger.info("[{}] in platformServiceFeeRate,skupType:{}", uid, skupType);
|
|
|
|
|
|
//1.获取卖家统计结果
|
|
|
SellerOrderStatsEntry statsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).skupType(skupType).time(DateUtil.getCurrentTimeSecond()).build();
|
|
|
SellerOrderStatsConfiguration statsConfig = statsConfigurationManager.getStatsConfig(statsEntry);
|
|
|
SellerOrderStatsResult statsResult = (SellerOrderStatsResult) statsConfigurationManager.getStatsProcessor(statsConfig.getStatsProcessorName()).getResult(statsEntry, statsConfig);
|
|
|
|
|
|
//2.通过统计结果获取费用定义
|
|
|
SellerPlatformServiceFee sellerPlatformServiceFee = buildSellerPlatformServiceFee(statsResult);
|
|
|
//查询当前周期的费用
|
|
|
SellerPlatformServiceFee sellerPlatformServiceFee = currentPeriod(uid, skupType);
|
|
|
|
|
|
//3.最终的费用
|
|
|
BigDecimal feeRate = sellerPlatformServiceFee.getFeeRate();
|
...
|
...
|
@@ -60,12 +96,36 @@ public class SellerPlatformServiceFeeSupport { |
|
|
return feeRate;
|
|
|
}
|
|
|
|
|
|
public SellerPlatformServiceFee buildSellerPlatformServiceFee(SellerOrderStatsResult statsResult) {
|
|
|
private SellerPlatformServiceFee buildSellerPlatformServiceFee(int uid, SellerOrderStatsResult statsResult) {
|
|
|
|
|
|
replaceEnterTypeIfNeed(statsResult);
|
|
|
|
|
|
//通过统计结果获取费用定义
|
|
|
PlatformServiceFeeDefinition platformServiceFeeDefinition = fetchPlatformServiceFeeDefinitionByStatsResult(statsResult);
|
|
|
|
|
|
return new SellerPlatformServiceFee(statsResult == null ? 0 : statsResult.getQuantity(),
|
|
|
platformServiceFeeDefinition == null ? PlatformServiceFeeDefinition.EMPTY_DEFINITION : platformServiceFeeDefinition);
|
|
|
return new SellerPlatformServiceFee(statsResult.getQuantity(), platformServiceFeeDefinition);
|
|
|
}
|
|
|
|
|
|
private SellerOrderStatsResult createEmptyStatsResult(int uid) {
|
|
|
SellerOrderStatsResult statsResult = new SellerOrderStatsResult();
|
|
|
statsResult.setUid(uid);
|
|
|
statsResult.setQuantity(0);
|
|
|
statsResult.setEnterType(-1);
|
|
|
return statsResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* enterType < 0,使用用户当前的入驻类型
|
|
|
*
|
|
|
* @param statsResult
|
|
|
*/
|
|
|
private void replaceEnterTypeIfNeed(SellerOrderStatsResult statsResult) {
|
|
|
if (statsResult.getEnterType() < 0) {
|
|
|
logger.info("[{}] use current enterType to replace for orderStatsResult", statsResult.getUid());
|
|
|
//查询用户当前入驻类型
|
|
|
EntrySellerType entrySellerType = sellerService.getEntrySellerType(statsResult.getUid());
|
|
|
statsResult.setEnterType(entrySellerType.getCode());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -75,9 +135,6 @@ public class SellerPlatformServiceFeeSupport { |
|
|
* @return
|
|
|
*/
|
|
|
private PlatformServiceFeeDefinition fetchPlatformServiceFeeDefinitionByStatsResult(SellerOrderStatsResult sellerOrderStatsResult) {
|
|
|
if (Objects.isNull(sellerOrderStatsResult)) {
|
|
|
return null;
|
|
|
}
|
|
|
//平台服务费的规则定义
|
|
|
List<SellerServiceFeeRuleDefinition> ruleDefinitions = sellerServiceFeeRuleCacheService.getRuleDefinitions();
|
|
|
//按统计码、入驻类型获取特定的规则
|
...
|
...
|
@@ -85,6 +142,6 @@ public class SellerPlatformServiceFeeSupport { |
|
|
.filter(ruleDefinition -> StringUtils.equals(ruleDefinition.getStatsCode(), sellerOrderStatsResult.getStatsCode()))
|
|
|
.filter(ruleDefinition -> ruleDefinition.getEnterType() == sellerOrderStatsResult.getEnterType())
|
|
|
.map(ruleDefinition -> ruleDefinition.getServiceFeeDefinition()).findFirst();
|
|
|
return psfdOp.isPresent() ? psfdOp.get() : null;
|
|
|
return psfdOp.isPresent() ? psfdOp.get() : PlatformServiceFeeDefinition.EMPTY_DEFINITION;
|
|
|
}
|
|
|
} |
...
|
...
|
|