From 0a13bcd8765e7272ad26a53ccb1bd04340cfdd95 Mon Sep 17 00:00:00 2001 From: yuan <1551130722@qq.com> Date: Mon, 9 Jul 2018 10:36:16 +0800 Subject: [PATCH] fix BD Commissions --- .../bdprize/core/impls/BDPrizeServiceImpl.java | 2 +- .../support/impls/BDPrizeCalculatorDefaultImpl.java | 13 ++++++++++--- .../financial/FinancialBDPrizeLogMapper.java | 2 +- .../manage/mappers/payment/TransactionMapper.xml | 2 +- src/main/ui/static/config/bdprize/bdprize.js | 7 ++++--- .../bdprize/templates/bd_prize_month_report.html | 5 ++++- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java index 317283c6a..c52dac881 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java @@ -145,7 +145,7 @@ public class BDPrizeServiceImpl implements BDPrizeService { for (JSONObject leader : bdLeaders) { BigDecimal groupAmount = transactionMapper.TotalAmountForBDLeaderPrize(now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,leader.getString("manager_id")); JSONObject bdConfig = financialBDConfigMapper.getBdConfig(leader.getString("manager_id")); - int bd_type = ("Sydney").equals(bdConfig.getString("city"))?2:1;//sydney leader 即悉尼大客户经理 + int bd_type = bdConfig ==null?2:("Sydney").equals(bdConfig.getString("city"))?2:1;//sydney leader 即悉尼大客户经理 JSONObject rateJson = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, groupAmount.toString(), bd_type); BigDecimal groupPrize = new BigDecimal(0); if (rateJson != null) { diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java index cf130a9d3..7107827b1 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java @@ -86,15 +86,22 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator { log.put("total_amount", 0); log.put("total_prize", 0); log.put("total_donation", 0); + BigDecimal totalAmount = log.getBigDecimal("total_amount"); List details = new ArrayList<>(); + for (Map.Entry detail : resultItem.getValue().entrySet()) { + JSONObject detailItem = detail.getValue(); + BigDecimal totalTransaction = detailItem.getBigDecimal("total_transaction"); + BigDecimal coefficient = detailItem.getBigDecimal("coefficient"); + BigDecimal realTransaction = totalTransaction.multiply(coefficient).setScale(2,BigDecimal.ROUND_DOWN); + totalAmount = totalAmount.add(realTransaction); + } for (Map.Entry detail : resultItem.getValue().entrySet()) { JSONObject detailItem = detail.getValue(); int clientId = detailItem.getIntValue("client_id"); // int months = detailItem.getIntValue("client_create_months"); BigDecimal totalTransaction = detailItem.getBigDecimal("total_transaction"); BigDecimal coefficient = detailItem.getBigDecimal("coefficient"); - BigDecimal realTransaction = totalTransaction.multiply(coefficient).setScale(2,BigDecimal.ROUND_DOWN); - int prizeLevel = getKpiPrizeLevel(realTransaction,log.getBigDecimal("kpi_amount")); + int prizeLevel = getKpiPrizeLevel(totalAmount,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 donation = BigDecimal.ZERO; @@ -231,7 +238,7 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator { } private int getKpiPrizeLevel(BigDecimal transactionAmount,BigDecimal kpiAmount){ - if (kpiAmount.equals(BigDecimal.ZERO)){//未设置kpi金额的按照最小完成度来计算 + if (kpiAmount.compareTo(BigDecimal.ZERO)==0){//未设置kpi金额的按照最小完成度来计算 return 1; } BigDecimal rate = transactionAmount.divide(kpiAmount,2,BigDecimal.ROUND_HALF_DOWN); diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeLogMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeLogMapper.java index adb0bc5a1..cbd0e1005 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeLogMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeLogMapper.java @@ -19,7 +19,7 @@ public interface FinancialBDPrizeLogMapper { @AutoSql(type = SqlType.INSERT) void save(JSONObject log); - @Select("SELECT fbpl.prize_log_id,fbpl.record_id,fbpl.manager_id,fbpl.bd_name,fbpl.bd_level,SUM(fbpl.total_amount) total_amount, " + + @Select("SELECT fbpl.prize_log_id,fbpl.record_id,fbpl.manager_id,fbpl.bd_name,fbpl.kpi_amount,fbpl.bd_level,SUM(fbpl.total_amount) total_amount, " + "SUM(fbpl.total_prize) total_prize,SUM(fbpl.total_donation) total_donation, SUM(fbpl.send_prize) send_prize, " + "SUM(fbpl.hold_prize) hold_prize,fbpl.last_punish,fbpl.prize_type,sysm.is_valid FROM financial_bd_prize_log fbpl, " + "sys_managers sysm " + diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml index a6480b29e..0d527bf43 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml @@ -504,7 +504,7 @@