fix bd commission

master
eason 6 years ago
parent 9b031f73bb
commit ac40e858da

@ -78,7 +78,7 @@ public class BDPrizeServiceImpl implements BDPrizeService {
private static BigDecimal percent = new BigDecimal(100); private static BigDecimal percent = new BigDecimal(100);
private static String[] channels = new String[]{"Wechat", "Alipay", "Bestpay", "jd", "AlipayOnline"}; private static String[] channels = new String[]{"Wechat", "Alipay", "Bestpay", "jd", "AlipayOnline","hf"};
@Override @Override
public void generateRecord() { public void generateRecord() {
@ -133,10 +133,14 @@ public class BDPrizeServiceImpl implements BDPrizeService {
} }
} }
//BD Leader Prize //BD Leader Prize
//bd_type:1 销售总监 2 大客户经理 3悉尼分公司经理 4 COO 5 NGDepartment
//todo 10月开始悉尼分公司经理不享受悉尼销售组提成
List<JSONObject> bdLeaders = managerMapper.listByRole(1, ManagerRole.BD_LEADER.getMask()); List<JSONObject> bdLeaders = managerMapper.listByRole(1, ManagerRole.BD_LEADER.getMask());
for (JSONObject leader : bdLeaders) { for (JSONObject leader : bdLeaders) {
BigDecimal groupAmount = transactionMapper.TotalAmountForBDLeaderPrize(now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,leader.getString("manager_id")); BigDecimal groupAmount = transactionMapper.TotalAmountForBDLeaderPrize(now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,leader.getString("manager_id"));
JSONObject rateJson = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, groupAmount.toString(), 1); JSONObject bdConfig = financialBDConfigMapper.getBdConfig(leader.getString("manager_id"));
int bd_type = ("Sydney").equals(bdConfig.getString("city"))?2:1;//sydney leader 即悉尼大客户经理
JSONObject rateJson = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, groupAmount.toString(), bd_type);
BigDecimal groupPrize = new BigDecimal(0); BigDecimal groupPrize = new BigDecimal(0);
if (rateJson != null) { if (rateJson != null) {
groupPrize = groupAmount.multiply(new BigDecimal(rateJson.getString("commission_rate")).divide(percent)).setScale(2, BigDecimal.ROUND_DOWN); groupPrize = groupAmount.multiply(new BigDecimal(rateJson.getString("commission_rate")).divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
@ -212,28 +216,44 @@ public class BDPrizeServiceImpl implements BDPrizeService {
DateTime monthDate = new DateTime(month); DateTime monthDate = new DateTime(month);
//bd manager commission //bd manager commission
JSONObject cityPrizeLog = new JSONObject(); // JSONObject cityPrizeLog = new JSONObject();
cityPrizeLog.put("total_amount", cplTotalprize); // cityPrizeLog.put("total_amount", cplTotalprize);
JSONObject cplRate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, cplTotalprize.toString(), 2); // JSONObject cplRate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, cplTotalprize.toString(), 2);
if (cplRate == null) { // if (cplRate == null) {
cityPrizeLog.put("total_prize", 0.00); // cityPrizeLog.put("total_prize", 0.00);
// } else {
// BigDecimal _commission_rate = new BigDecimal(cplRate.getString("commission_rate"));
// BigDecimal _total_amount = new BigDecimal(cityPrizeLog.getString("total_amount"));
// BigDecimal total_prize = _total_amount.multiply(_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
// cityPrizeLog.put("total_prize", total_prize);
// }
// report.put("cityPrizeLogs", cityPrizeLog);
//bd_type=3 悉尼分公司经理 悉尼销售组和大客户组流水提成
JSONObject sydneyPrizeLog = new JSONObject();
BigDecimal sydneyAmount = transactionMapper.TotalAmountForSydneyGMPrize(monthDate.getYear(), monthDate.getMonthOfYear());
sydneyPrizeLog.put("total_amount",sydneyAmount);
JSONObject sydneyGMRate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, sydneyAmount.toString(), 3);
if (sydneyGMRate == null) {
sydneyPrizeLog.put("total_prize", 0.00);
} else { } else {
BigDecimal _commission_rate = new BigDecimal(cplRate.getString("commission_rate")); BigDecimal sydney_commission_rate = new BigDecimal(sydneyGMRate.getString("commission_rate"));
BigDecimal _total_amount = new BigDecimal(cityPrizeLog.getString("total_amount")); BigDecimal total_prize = sydneyAmount.multiply(sydney_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
BigDecimal total_prize = _total_amount.multiply(_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN); sydneyPrizeLog.put("total_prize", total_prize);
cityPrizeLog.put("total_prize", total_prize);
} }
report.put("cityPrizeLogs", cityPrizeLog); report.put("sydneyPrizeLog", sydneyPrizeLog);
//Director commission //COO & NJ commission
JSONObject directPrizeLogs = new JSONObject();
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
params.put("begin", TimeZoneUtils.beginDate(TimeZoneUtils.getFirstDay(monthDate.toString()))); params.put("begin", TimeZoneUtils.beginDate(TimeZoneUtils.getFirstDay(monthDate.toString())));
params.put("end", TimeZoneUtils.getPerFirstDayOfMonth(TimeZoneUtils.getLastDay(monthDate.toString()))); params.put("end", TimeZoneUtils.getPerFirstDayOfMonth(TimeZoneUtils.getLastDay(monthDate.toString())));
BigDecimal totalprize = transactionAnalysisMapper.analysisTotalAmount(params); BigDecimal totalprize = transactionAnalysisMapper.analysisTotalAmount(params);
JSONObject directPrizeLogs = new JSONObject();
directPrizeLogs.put("total_amount", totalprize); directPrizeLogs.put("total_amount", totalprize);
JSONObject rate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, totalprize.toString(), 3); JSONObject rate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, totalprize.toString(), 4);
if (rate == null) { if (rate == null) {
directPrizeLogs.put("total_prize", 0.00); directPrizeLogs.put("total_prize", 0.00);
} else { } else {
@ -243,6 +263,18 @@ public class BDPrizeServiceImpl implements BDPrizeService {
directPrizeLogs.put("total_prize", total_prize); directPrizeLogs.put("total_prize", total_prize);
} }
report.put("directPrizeLogs", directPrizeLogs); report.put("directPrizeLogs", directPrizeLogs);
JSONObject ngDepartmentPrizeLog = new JSONObject();
ngDepartmentPrizeLog.put("total_amount", totalprize);
JSONObject ngRate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, totalprize.toString(), 5);
if (ngRate == null) {
ngDepartmentPrizeLog.put("total_prize", 0.00);
} else {
BigDecimal ng_commission_rate = new BigDecimal(ngRate.getString("commission_rate"));
BigDecimal ng_total_prize = totalprize.multiply(ng_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
ngDepartmentPrizeLog.put("total_prize", ng_total_prize);
}
report.put("ngDepartmentPrizeLog", ngDepartmentPrizeLog);
return report; return report;
} }

@ -46,16 +46,16 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
public BDPrizeCalculatorDefaultImpl rateConfig(List<JSONObject> rateConfig) { public BDPrizeCalculatorDefaultImpl rateConfig(List<JSONObject> rateConfig) {
for (JSONObject rateCfgItem : rateConfig) { for (JSONObject rateCfgItem : rateConfig) {
int level = rateCfgItem.getIntValue("bd_level"); int level = rateCfgItem.getIntValue("bd_level");
int monthLevel = rateCfgItem.getIntValue("time_range"); int kpiRange = rateCfgItem.getIntValue("kpi_range");
Map<Integer, List<JSONObject>> rates = rateConfigMap.get(level); Map<Integer, List<JSONObject>> rates = rateConfigMap.get(level);
if (rates == null) { if (rates == null) {
rates = new HashMap<>(); rates = new HashMap<>();
rateConfigMap.put(level, rates); rateConfigMap.put(level, rates);
} }
List<JSONObject> rate = rates.get(monthLevel); List<JSONObject> rate = rates.get(kpiRange);
if (rate == null) { if (rate == null) {
rate = new ArrayList<>(); rate = new ArrayList<>();
rates.put(monthLevel, rate); rates.put(kpiRange, rate);
} }
rate.add(rateCfgItem); rate.add(rateCfgItem);
} }
@ -90,10 +90,12 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
for (Map.Entry<String, JSONObject> detail : resultItem.getValue().entrySet()) { for (Map.Entry<String, JSONObject> detail : resultItem.getValue().entrySet()) {
JSONObject detailItem = detail.getValue(); JSONObject detailItem = detail.getValue();
int clientId = detailItem.getIntValue("client_id"); int clientId = detailItem.getIntValue("client_id");
int months = detailItem.getIntValue("client_create_months"); // int months = detailItem.getIntValue("client_create_months");
BigDecimal bdRate = getRate(bdLevel, months, detailItem.getIntValue("client_source"), detailItem.getBigDecimal("rate_value"));
BigDecimal totalTransaction = detailItem.getBigDecimal("total_transaction"); BigDecimal totalTransaction = detailItem.getBigDecimal("total_transaction");
BigDecimal coefficient = detailItem.getBigDecimal("coefficient"); BigDecimal coefficient = detailItem.getBigDecimal("coefficient");
BigDecimal realTransaction = totalTransaction.multiply(coefficient).setScale(2,BigDecimal.ROUND_DOWN);
int prizeLevel = getKpiPrizeLevel(realTransaction,log.getBigDecimal("kpi_amount"));
BigDecimal bdRate = getNewRate(bdLevel, prizeLevel, detailItem.getIntValue("client_source"), detailItem.getBigDecimal("rate_value"));
BigDecimal prizeValue = totalTransaction.multiply(coefficient).multiply(bdRate).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN); BigDecimal prizeValue = totalTransaction.multiply(coefficient).multiply(bdRate).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN);
BigDecimal donation = BigDecimal.ZERO; BigDecimal donation = BigDecimal.ZERO;
if (clientsWithBDAwayDeterminor.clientWithBDAway(clientId, month)) { if (clientsWithBDAwayDeterminor.clientWithBDAway(clientId, month)) {
@ -209,4 +211,39 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
} }
throw new ServerErrorException("Prize Rate Config has no equalize:bdLevel=" + bdLevel + ",months=" + months + ",clientRate=" + clientRate.doubleValue()); throw new ServerErrorException("Prize Rate Config has no equalize:bdLevel=" + bdLevel + ",months=" + months + ",clientRate=" + clientRate.doubleValue());
} }
private BigDecimal getNewRate(int bdLevel, int kpiRange, int clientSource, BigDecimal clientRate) {
BigDecimal prizeRate = BigDecimal.ZERO;
Map<Integer, List<JSONObject>> rates = rateConfigMap.get(bdLevel);
List<JSONObject> rate = rates.get(kpiRange);
for (JSONObject rateCfg : rate) {
if (rateCfg.getBigDecimal("rate_from").compareTo(clientRate) <= 0 && rateCfg.getBigDecimal("rate_to").compareTo(clientRate) >= 0) {
prizeRate= rateCfg.getBigDecimal("prize_rate");
continue;
}
}
if (clientSource == 1) {
return prizeRate;
} else {
return prizeRate.divide(BigDecimal.valueOf(2),3,BigDecimal.ROUND_HALF_DOWN);
}
}
private int getKpiPrizeLevel(BigDecimal transactionAmount,BigDecimal kpiAmount){
BigDecimal rate = transactionAmount.divide(kpiAmount,2,BigDecimal.ROUND_HALF_DOWN);
if (rate.compareTo(BigDecimal.valueOf(0.5))<0){
return 1;
}
if (rate.compareTo(BigDecimal.valueOf(0.8))<0){
return 2;
}
if (rate.compareTo(BigDecimal.valueOf(1))<0){
return 3;
}
if (rate.compareTo(BigDecimal.valueOf(1.2))<0){
return 4;
}
return 5;
}
} }

@ -94,6 +94,8 @@ public interface TransactionMapper {
List<JSONObject> listTransactionsForBDPrize(@Param("year") int year, @Param("month") int month, @Param("channel") String channel); List<JSONObject> listTransactionsForBDPrize(@Param("year") int year, @Param("month") int month, @Param("channel") String channel);
BigDecimal TotalAmountForBDLeaderPrize(@Param("year") int year, @Param("month") int month, @Param("bd_group") String bd_group); BigDecimal TotalAmountForBDLeaderPrize(@Param("year") int year, @Param("month") int month, @Param("bd_group") String bd_group);
BigDecimal TotalAmountForSydneyGMPrize(@Param("year") int year, @Param("month") int month);
List<JSONObject> listTransactionsForCityPartnerCommission(@Param("year") int year, @Param("month") int month); List<JSONObject> listTransactionsForCityPartnerCommission(@Param("year") int year, @Param("month") int month);

@ -495,10 +495,7 @@
INNER JOIN pmt_orders o ON o.order_id = t.order_id INNER JOIN pmt_orders o ON o.order_id = t.order_id
INNER JOIN sys_clients c ON c.client_id = o.client_id AND c.org_id = 1 INNER JOIN sys_clients c ON c.client_id = o.client_id AND c.org_id = 1
WHERE year(o.create_time) = #{year} AND month(o.create_time) = #{month} AND t.channel != 'Settlement' WHERE year(o.create_time) = #{year} AND month(o.create_time) = #{month} AND t.channel != 'Settlement'
<if test="channel=='Wechat'"> <if test="channel!=null">
and t.channel not in ('Alipay','Bestpay')
</if>
<if test="channel!='Wechat'">
and t.channel = #{channel} and t.channel = #{channel}
</if> </if>
GROUP BY o.client_id, trade_date GROUP BY o.client_id, trade_date
@ -528,6 +525,30 @@
where b.is_valid=1 and b.start_date&lt;=now() and (b.end_date is null or b.end_date &gt;= now()) where b.is_valid=1 and b.start_date&lt;=now() and (b.end_date is null or b.end_date &gt;= now())
AND c.bd_group=#{bd_group} or c.manager_id=#{bd_group}) AND c.bd_group=#{bd_group} or c.manager_id=#{bd_group})
</select> </select>
<select id="TotalAmountForSydneyGMPrize" resultType="java.math.BigDecimal">
SELECT
sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount))
total
FROM pmt_transactions t
INNER JOIN pmt_orders o ON o.order_id = t.order_id
INNER JOIN sys_clients c ON c.client_id = o.client_id AND c.org_id = 1
WHERE year(o.create_time) = #{year} AND month(o.create_time) = #{month}
AND(
t.transaction_type = 'Credit'
OR t.refund_id IS NOT NULL
)
AND(
o. STATUS =5
OR o. STATUS =6
OR o. STATUS =7
)
and t.client_id in
(SELECT b.client_id FROM sys_client_bd b
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id
where b.is_valid=1 and b.start_date&lt;=now() and (b.end_date is null or b.end_date &gt;= now())
AND c.city='Sydney')
</select>
<select id="listTransactionsForCityPartnerCommission" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransactionsForCityPartnerCommission" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT SELECT

Loading…
Cancel
Save