|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package au.com.royalpay.payment.manage.citypartner.beans;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.CommonConsts;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
@ -18,6 +20,7 @@ public class CityPartnerCommissionAnalysis {
|
|
|
|
|
private BigDecimal jdChargeRate;
|
|
|
|
|
private BigDecimal alipayonlineChargeRate;
|
|
|
|
|
private BigDecimal rate;
|
|
|
|
|
private BigDecimal orgRate;
|
|
|
|
|
private String channel;
|
|
|
|
|
private Map<Integer, List<JSONObject>> clientAnalysis = new HashMap<>();
|
|
|
|
|
private BigDecimal totalGrossAmount = BigDecimal.ZERO;
|
|
|
|
@ -26,7 +29,8 @@ public class CityPartnerCommissionAnalysis {
|
|
|
|
|
private BigDecimal totalOrgChargeSum = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalnetCharge = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
|
|
public CityPartnerCommissionAnalysis(int orgId, int year, int month, BigDecimal rate,String channel,BigDecimal alipayChargeRate,BigDecimal wechatChargeRate,BigDecimal jdChargeRate,BigDecimal alipayonlineChargeRate) {
|
|
|
|
|
public CityPartnerCommissionAnalysis(int orgId, int year, int month, BigDecimal rate, String channel, BigDecimal alipayChargeRate,
|
|
|
|
|
BigDecimal wechatChargeRate, BigDecimal jdChargeRate, BigDecimal alipayonlineChargeRate, BigDecimal orgRate) {
|
|
|
|
|
this.orgId = orgId;
|
|
|
|
|
this.year = year;
|
|
|
|
|
this.month = month;
|
|
|
|
@ -36,9 +40,22 @@ public class CityPartnerCommissionAnalysis {
|
|
|
|
|
this.wechatChargeRate = wechatChargeRate;
|
|
|
|
|
this.jdChargeRate = jdChargeRate;
|
|
|
|
|
this.alipayonlineChargeRate = alipayonlineChargeRate;
|
|
|
|
|
this.orgRate = orgRate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CityPartnerCommissionAnalysis attachAnalysis(JSONObject dayAnalysis,String channel) {
|
|
|
|
|
public CityPartnerCommissionAnalysis calculator(JSONObject dayAnalysis, String channel, int type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 1:
|
|
|
|
|
return attachAnalysis(dayAnalysis, channel);
|
|
|
|
|
case 3:
|
|
|
|
|
return attachNetCommissionAnalysis(dayAnalysis, channel);
|
|
|
|
|
default:
|
|
|
|
|
throw new ServerErrorException("unkonw calculate type");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CityPartnerCommissionAnalysis attachAnalysis(JSONObject dayAnalysis, String channel) {
|
|
|
|
|
int clientId = dayAnalysis.getIntValue("client_id");
|
|
|
|
|
List<JSONObject> clientTrades = clientAnalysis.get(clientId);
|
|
|
|
|
if (clientTrades == null) {
|
|
|
|
@ -47,31 +64,13 @@ public class CityPartnerCommissionAnalysis {
|
|
|
|
|
}
|
|
|
|
|
Date tradeDate = dayAnalysis.getDate("trade_date");
|
|
|
|
|
BigDecimal total = dayAnalysis.getBigDecimal("total");
|
|
|
|
|
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel+"_rate_value");
|
|
|
|
|
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel + "_rate_value");
|
|
|
|
|
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
|
|
|
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
|
|
|
BigDecimal thirdPartyPaymentCharge = BigDecimal.ZERO;
|
|
|
|
|
switch (channel){
|
|
|
|
|
case "alipay":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(alipayChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
break;
|
|
|
|
|
case "wechat":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(wechatChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
break;
|
|
|
|
|
case "jd":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(jdChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
break;
|
|
|
|
|
case "alipayonline":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(alipayonlineChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal netCharge = royalpayCharge.subtract(thirdPartyPaymentCharge);
|
|
|
|
|
|
|
|
|
|
BigDecimal thirdPartyPaymentCharge = getThirdPartyCharge(channel, total);
|
|
|
|
|
BigDecimal netCharge = royalpayCharge.subtract(thirdPartyPaymentCharge);
|
|
|
|
|
|
|
|
|
|
BigDecimal orgCharge = dayCharge.subtract(royalpayCharge);
|
|
|
|
|
|
|
|
|
@ -113,8 +112,8 @@ public class CityPartnerCommissionAnalysis {
|
|
|
|
|
item.put("total_charge", dayCharge);
|
|
|
|
|
item.put("royalpay_charge", royalpayCharge);
|
|
|
|
|
item.put("org_charge", orgCharge);
|
|
|
|
|
item.put("channel",channel);
|
|
|
|
|
item.put("net_charge",netCharge);
|
|
|
|
|
item.put("channel", channel);
|
|
|
|
|
item.put("net_charge", netCharge);
|
|
|
|
|
clientTrades.add(item);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
@ -130,8 +129,8 @@ public class CityPartnerCommissionAnalysis {
|
|
|
|
|
result.put("total_charge", totalChargeSum);
|
|
|
|
|
result.put("royalpay_charge", totalRoyalPayCharge);
|
|
|
|
|
result.put("org_charge", totalOrgChargeSum);
|
|
|
|
|
result.put("net_charge",totalnetCharge);
|
|
|
|
|
result.put("channel",channel);
|
|
|
|
|
result.put("net_charge", totalnetCharge);
|
|
|
|
|
result.put("channel", channel);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -147,4 +146,87 @@ public class CityPartnerCommissionAnalysis {
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CityPartnerCommissionAnalysis attachNetCommissionAnalysis(JSONObject dayAnalysis, String channel) {
|
|
|
|
|
int clientId = dayAnalysis.getIntValue("client_id");
|
|
|
|
|
List<JSONObject> clientTrades = clientAnalysis.get(clientId);
|
|
|
|
|
if (clientTrades == null) {
|
|
|
|
|
clientTrades = new ArrayList<>();
|
|
|
|
|
clientAnalysis.put(clientId, clientTrades);
|
|
|
|
|
}
|
|
|
|
|
Date tradeDate = dayAnalysis.getDate("trade_date");
|
|
|
|
|
BigDecimal total = dayAnalysis.getBigDecimal("total");
|
|
|
|
|
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel + "_rate_value");
|
|
|
|
|
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
|
|
|
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
|
|
|
BigDecimal thirdPartyPaymentCharge = getThirdPartyCharge(channel, total);
|
|
|
|
|
BigDecimal netCharge = royalpayCharge.subtract(thirdPartyPaymentCharge);
|
|
|
|
|
BigDecimal orgCharge = netCharge.multiply(orgRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
totalGrossAmount = totalGrossAmount.add(total);
|
|
|
|
|
totalChargeSum = totalChargeSum.add(dayCharge);
|
|
|
|
|
totalRoyalPayCharge = totalRoyalPayCharge.add(royalpayCharge);
|
|
|
|
|
totalOrgChargeSum = totalOrgChargeSum.add(orgCharge);
|
|
|
|
|
totalnetCharge = totalnetCharge.add(netCharge);
|
|
|
|
|
if (!clientTrades.isEmpty()) {
|
|
|
|
|
JSONObject item = clientTrades.get(clientTrades.size() - 1);
|
|
|
|
|
BigDecimal rate = item.getBigDecimal("client_rate");
|
|
|
|
|
if (rate.compareTo(dayRate) == 0) {
|
|
|
|
|
BigDecimal gross = item.getBigDecimal("gross_amount").add(total);
|
|
|
|
|
item.put("gross_amount", gross);
|
|
|
|
|
BigDecimal totalCharge = item.getBigDecimal("total_charge").add(dayCharge);
|
|
|
|
|
item.put("total_charge", totalCharge);
|
|
|
|
|
BigDecimal totalRoyalCharge = item.getBigDecimal("royalpay_charge").add(royalpayCharge);
|
|
|
|
|
item.put("royalpay_charge", totalRoyalCharge);
|
|
|
|
|
BigDecimal totalOrgCharge = item.getBigDecimal("org_charge").add(orgCharge);
|
|
|
|
|
item.put("org_charge", totalOrgCharge);
|
|
|
|
|
BigDecimal totalRoyalpayClearingCharge = item.getBigDecimal("net_charge").add(netCharge);
|
|
|
|
|
item.put("net_charge", totalRoyalpayClearingCharge);
|
|
|
|
|
Date from = item.getDate("date_from");
|
|
|
|
|
Date to = item.getDate("date_to");
|
|
|
|
|
from = from.before(tradeDate) ? from : tradeDate;
|
|
|
|
|
to = to.after(tradeDate) ? to : tradeDate;
|
|
|
|
|
item.put("date_from", from);
|
|
|
|
|
item.put("date_to", to);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
JSONObject item = new JSONObject();
|
|
|
|
|
item.put("year", year);
|
|
|
|
|
item.put("month", month);
|
|
|
|
|
item.put("date_from", tradeDate);
|
|
|
|
|
item.put("date_to", tradeDate);
|
|
|
|
|
item.put("client_rate", dayRate);
|
|
|
|
|
item.put("gross_amount", total);
|
|
|
|
|
item.put("total_charge", dayCharge);
|
|
|
|
|
item.put("royalpay_charge", royalpayCharge);
|
|
|
|
|
item.put("org_charge", orgCharge);
|
|
|
|
|
item.put("channel", channel);
|
|
|
|
|
item.put("net_charge", netCharge);
|
|
|
|
|
clientTrades.add(item);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal getThirdPartyCharge(String channel, BigDecimal total) {
|
|
|
|
|
BigDecimal thirdPartyPaymentCharge = BigDecimal.ZERO;
|
|
|
|
|
switch (channel) {
|
|
|
|
|
case "alipay":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(alipayChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
break;
|
|
|
|
|
case "wechat":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(wechatChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
break;
|
|
|
|
|
case "jd":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(jdChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
break;
|
|
|
|
|
case "alipayonline":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(alipayonlineChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return thirdPartyPaymentCharge;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|