|
|
@ -1,5 +1,41 @@
|
|
|
|
package au.com.royalpay.payment.manage.citypartner.core.impls;
|
|
|
|
package au.com.royalpay.payment.manage.citypartner.core.impls;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import javax.swing.plaf.basic.BasicScrollPaneUI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientBankAccountMapper;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.CommonConsts;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.AgentCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.AgentCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.CityPartnerCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.CityPartnerCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.ReferrerCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.ReferrerCommissionAnalysis;
|
|
|
@ -69,6 +105,9 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
private FinancialSeniorPartnerCommissionMapper financialSeniorPartnerCommissionMapper;
|
|
|
|
private FinancialSeniorPartnerCommissionMapper financialSeniorPartnerCommissionMapper;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private FinancialSeniorPartnerCommissionDetailMapper financialSeniorPartnerCommissionDetailMapper;
|
|
|
|
private FinancialSeniorPartnerCommissionDetailMapper financialSeniorPartnerCommissionDetailMapper;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private MerchantInfoProvider merchantInfoProvider;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<JSONObject> listAvailableMonths(String year) {
|
|
|
|
public List<JSONObject> listAvailableMonths(String year) {
|
|
|
@ -114,6 +153,10 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
for (JSONObject prize : partnerPrizes) {
|
|
|
|
for (JSONObject prize : partnerPrizes) {
|
|
|
|
plusKey(sum, prize, "gross_amount");
|
|
|
|
plusKey(sum, prize, "gross_amount");
|
|
|
|
plusKey(sum, prize, "total_charge");
|
|
|
|
plusKey(sum, prize, "total_charge");
|
|
|
|
|
|
|
|
//暂只处理合伙人提成总额
|
|
|
|
|
|
|
|
if (prize.get("parent_org_id") == null) {
|
|
|
|
|
|
|
|
prize.put("org_charge", prize.getBigDecimal("org_charge").add(prize.getBigDecimal("share_charge")));
|
|
|
|
|
|
|
|
}
|
|
|
|
plusKey(sum, prize, "royalpay_charge");
|
|
|
|
plusKey(sum, prize, "royalpay_charge");
|
|
|
|
plusKey(sum, prize, "org_charge");
|
|
|
|
plusKey(sum, prize, "org_charge");
|
|
|
|
prize.put("monthstr", monthStr);
|
|
|
|
prize.put("monthstr", monthStr);
|
|
|
@ -255,9 +298,9 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public void generate(String monthStr) {
|
|
|
|
public void generateold(String monthStr) {
|
|
|
|
Date mon = checkMonth(monthStr);
|
|
|
|
Date mon = checkMonth(monthStr);
|
|
|
|
Calendar monthCal = Calendar.getInstance();
|
|
|
|
Calendar monthCal = Calendar.getInstance();
|
|
|
|
monthCal.setTime(mon);
|
|
|
|
monthCal.setTime(mon);
|
|
|
@ -268,7 +311,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
BigDecimal alipayChargeRate = new BigDecimal("0.6");
|
|
|
|
BigDecimal alipayChargeRate = new BigDecimal("0.6");
|
|
|
|
BigDecimal wechatChargeRate = new BigDecimal("0.6");
|
|
|
|
BigDecimal wechatChargeRate = new BigDecimal("0.6");
|
|
|
|
BigDecimal jdChargeRate = new BigDecimal("0.9");
|
|
|
|
BigDecimal jdChargeRate = new BigDecimal("0.9");
|
|
|
|
BigDecimal alipayonlineChargeRate = new BigDecimal("2.0");
|
|
|
|
BigDecimal alipayonlineChargeRate = new BigDecimal("0.6");
|
|
|
|
if (sysConfig.getBigDecimal("Alipay_charge_rate") != null) {
|
|
|
|
if (sysConfig.getBigDecimal("Alipay_charge_rate") != null) {
|
|
|
|
alipayChargeRate = sysConfig.getBigDecimal("Alipay_charge_rate");
|
|
|
|
alipayChargeRate = sysConfig.getBigDecimal("Alipay_charge_rate");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -329,7 +372,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Runnable task = () -> {
|
|
|
|
Runnable task = () -> {
|
|
|
|
orgIds.forEach((p) -> {
|
|
|
|
orgIds.forEach((p) -> {
|
|
|
|
generateAgent(monthStr, p);
|
|
|
|
generateAgentold(monthStr, p);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
generateReferrer(monthStr);
|
|
|
|
generateReferrer(monthStr);
|
|
|
|
generateSenior(monthStr);
|
|
|
|
generateSenior(monthStr);
|
|
|
@ -337,6 +380,290 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
new Thread(task).start();
|
|
|
|
new Thread(task).start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
|
|
|
public void generate(String monthStr) {
|
|
|
|
|
|
|
|
Date mon = checkMonth(monthStr);
|
|
|
|
|
|
|
|
Calendar monthCal = Calendar.getInstance();
|
|
|
|
|
|
|
|
monthCal.setTime(mon);
|
|
|
|
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<JSONObject> list = financialPartnerCommissionMapper.list(year, month);
|
|
|
|
|
|
|
|
if (list!=null &&list.size() > 0) {
|
|
|
|
|
|
|
|
throw new ServerErrorException("请不要重复生成合伙人记录");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
financialPartnerCommissionDetailMapper.clearData(year, month, 1);
|
|
|
|
|
|
|
|
financialPartnerCommissionMapper.clearData(year, month, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject sysConfig = sysConfigManager.getSysConfig();
|
|
|
|
|
|
|
|
BigDecimal alipayChargeRate = new BigDecimal("0.6");
|
|
|
|
|
|
|
|
BigDecimal wechatChargeRate = new BigDecimal("0.6");
|
|
|
|
|
|
|
|
BigDecimal jdChargeRate = new BigDecimal("0.9");
|
|
|
|
|
|
|
|
BigDecimal alipayonlineChargeRate = new BigDecimal("0.6");
|
|
|
|
|
|
|
|
if (sysConfig.getBigDecimal("Alipay_charge_rate") != null) {
|
|
|
|
|
|
|
|
alipayChargeRate = sysConfig.getBigDecimal("Alipay_charge_rate");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sysConfig.getBigDecimal("Wechat_charge_rate") != null) {
|
|
|
|
|
|
|
|
wechatChargeRate = sysConfig.getBigDecimal("Wechat_charge_rate");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sysConfig.getBigDecimal("jd_charge_rate") != null) {
|
|
|
|
|
|
|
|
jdChargeRate = sysConfig.getBigDecimal("jd_charge_rate");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sysConfig.getBigDecimal("alipayonline_charge_rate") != null) {
|
|
|
|
|
|
|
|
alipayonlineChargeRate = sysConfig.getBigDecimal("alipayonline_charge_rate");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject channelCharge = new JSONObject();
|
|
|
|
|
|
|
|
channelCharge.put("alipayChargeRate", alipayChargeRate);
|
|
|
|
|
|
|
|
channelCharge.put("wechatChargeRate", wechatChargeRate);
|
|
|
|
|
|
|
|
channelCharge.put("jdChargeRate", jdChargeRate);
|
|
|
|
|
|
|
|
channelCharge.put("alipayonlineChargeRate", alipayonlineChargeRate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<JSONObject> transactionDetail = transactionMapper.listTransactionForCityPartnerCommissionByDate(year, month);
|
|
|
|
|
|
|
|
Map<Integer, List<JSONObject>> groupByOrgMap = transactionDetail.stream().collect(Collectors.groupingBy(e -> e.getInteger("org_id")));
|
|
|
|
|
|
|
|
for (Map.Entry<Integer, List<JSONObject>> oneOrg : groupByOrgMap.entrySet()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int orgId = oneOrg.getKey();
|
|
|
|
|
|
|
|
JSONObject org = orgMapper.findOne(orgId);
|
|
|
|
|
|
|
|
if (org == null) {
|
|
|
|
|
|
|
|
// shall never happen
|
|
|
|
|
|
|
|
throw new ServerErrorException("Organization Id not exists:" + orgId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (org.getInteger("commission_type")!=1) {
|
|
|
|
|
|
|
|
generateold(monthStr);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<JSONObject> items = oneOrg.getValue();
|
|
|
|
|
|
|
|
Map<String, List<JSONObject>> groupByChannelMap = items.stream().collect(Collectors.groupingBy(e -> e.getString("channel")));
|
|
|
|
|
|
|
|
List<JSONObject> channelAmount = orgChannelAmount(org,groupByChannelMap, channelCharge);
|
|
|
|
|
|
|
|
for (JSONObject channel : channelAmount) {
|
|
|
|
|
|
|
|
channel.put("share_charge", 0);
|
|
|
|
|
|
|
|
channel.put("month", month);
|
|
|
|
|
|
|
|
channel.put("year", year);
|
|
|
|
|
|
|
|
channel.put("org_id", orgId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
financialPartnerCommissionMapper.save(channel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<Integer, List<JSONObject>> groupByClientMap = transactionDetail.stream().collect(Collectors.groupingBy(e -> e.getInteger("client_id")));
|
|
|
|
|
|
|
|
for (Map.Entry<Integer, List<JSONObject>> oneClient : groupByClientMap.entrySet()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject org = orgMapper.findOne(oneClient.getValue().get(0).getInteger("org_id"));
|
|
|
|
|
|
|
|
Map<String, List<JSONObject>> groupByChannel = oneClient.getValue().stream().collect(Collectors.groupingBy(e -> e.getString("channel")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<JSONObject> clientChannelAmount = clientChannelAmount(oneClient.getKey(),org, groupByChannel, channelCharge,year,month,1);
|
|
|
|
|
|
|
|
for (JSONObject channel : clientChannelAmount) {
|
|
|
|
|
|
|
|
financialPartnerCommissionDetailMapper.save(channel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runnable task = () -> {
|
|
|
|
|
|
|
|
generateAgent(monthStr, channelCharge);
|
|
|
|
|
|
|
|
generateReferrer(monthStr);
|
|
|
|
|
|
|
|
generateSenior(monthStr);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
new Thread(task).start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<JSONObject> orgChannelAmount(JSONObject orgInfo,Map<String, List<JSONObject>> channelMap,JSONObject channelCharge) {
|
|
|
|
|
|
|
|
List<JSONObject> amountByChannel = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<JSONObject>> oneChannel : channelMap.entrySet()) {
|
|
|
|
|
|
|
|
BigDecimal total = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal total_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal net_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal royalpay_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
|
|
|
String channel = oneChannel.getKey();
|
|
|
|
|
|
|
|
if (orgInfo.get(channel.toLowerCase() + "_rate_value")==null) {
|
|
|
|
|
|
|
|
throw new ServerErrorException(orgInfo.get("org_id") + "组织未设置"+ channel + "渠道成本手续费");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (JSONObject params : oneChannel.getValue()) {
|
|
|
|
|
|
|
|
//增加货币判断
|
|
|
|
|
|
|
|
int i = currencyScale(params.getString("clearing_currency"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total = total.add(params.getBigDecimal("clearing_amount"));
|
|
|
|
|
|
|
|
total_surage = total_surage.add(params.getBigDecimal("total_surcharge")).setScale(i, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
royalpay_surage = royalpay_surage.add(params.getBigDecimal("clearing_amount").multiply(orgInfo.getBigDecimal(channel.toLowerCase() + "_rate_value").divide(CommonConsts.HUNDRED, 4, RoundingMode.DOWN)).setScale(i, RoundingMode.HALF_UP));
|
|
|
|
|
|
|
|
// net_surage = net_surage.add(getThirdPartyCharge(params.getString("channel"), params.getBigDecimal("clearing_amount"), channelCharge));
|
|
|
|
|
|
|
|
net_surage = net_surage.add(params.getBigDecimal("channel_surcharge"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BigDecimal org_charge = total_surage.subtract(royalpay_surage);
|
|
|
|
|
|
|
|
json.put("channel",channel);
|
|
|
|
|
|
|
|
json.put("gross_amount",total);
|
|
|
|
|
|
|
|
json.put("total_charge",total_surage);
|
|
|
|
|
|
|
|
json.put("net_charge",net_surage);
|
|
|
|
|
|
|
|
json.put("org_rate", orgInfo.getBigDecimal(channel.toLowerCase() + "_rate_value"));
|
|
|
|
|
|
|
|
json.put("royalpay_charge", royalpay_surage);
|
|
|
|
|
|
|
|
json.put("org_charge", org_charge);
|
|
|
|
|
|
|
|
json.put("commission_type", "1");
|
|
|
|
|
|
|
|
json.put("create_time", new Date());
|
|
|
|
|
|
|
|
amountByChannel.add(json);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return amountByChannel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<JSONObject> parentOrgChannelAmount(JSONObject orgInfo,JSONObject parentOrgInfo,Map<String, List<JSONObject>> channelMap,JSONObject channelCharge) {
|
|
|
|
|
|
|
|
List<JSONObject> amountByChannel = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<JSONObject>> oneChannel : channelMap.entrySet()) {
|
|
|
|
|
|
|
|
BigDecimal total = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal total_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal net_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal royalpay_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal share_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
|
|
|
String channel = oneChannel.getKey();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (JSONObject params : oneChannel.getValue()) {
|
|
|
|
|
|
|
|
//增加货币判断
|
|
|
|
|
|
|
|
int i = currencyScale(params.getString("clearing_currency"));
|
|
|
|
|
|
|
|
BigDecimal parent_surage = params.getBigDecimal("clearing_amount").multiply(parentOrgInfo.getBigDecimal(channel.toLowerCase() + "_rate_value").divide(CommonConsts.HUNDRED, 4, RoundingMode.DOWN)).setScale(i, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
BigDecimal roy_surage = (params.getBigDecimal("clearing_amount").multiply(orgInfo.getBigDecimal(channel.toLowerCase() + "_rate_value").divide(CommonConsts.HUNDRED, 4, RoundingMode.DOWN)).setScale(i, RoundingMode.HALF_UP));
|
|
|
|
|
|
|
|
total = total.add(params.getBigDecimal("clearing_amount"));
|
|
|
|
|
|
|
|
total_surage = total_surage.add(params.getBigDecimal("total_surcharge")).setScale(i, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
royalpay_surage = royalpay_surage.add(roy_surage);
|
|
|
|
|
|
|
|
//net_surage = net_surage.add(getThirdPartyCharge(params.getString("channel"), params.getBigDecimal("clearing_amount"), channelCharge));
|
|
|
|
|
|
|
|
net_surage = net_surage.add(params.getBigDecimal("channel_surcharge"));
|
|
|
|
|
|
|
|
share_surage = share_surage.add(roy_surage.subtract(parent_surage)).setScale(i,RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BigDecimal org_charge = total_surage.subtract(royalpay_surage);
|
|
|
|
|
|
|
|
json.put("channel",channel);
|
|
|
|
|
|
|
|
json.put("gross_amount",total);
|
|
|
|
|
|
|
|
json.put("total_charge",total_surage);
|
|
|
|
|
|
|
|
json.put("net_charge",net_surage);
|
|
|
|
|
|
|
|
json.put("org_rate", orgInfo.getBigDecimal(channel.toLowerCase() + "_rate_value"));
|
|
|
|
|
|
|
|
json.put("partner_charge", royalpay_surage);
|
|
|
|
|
|
|
|
json.put("share_charge", share_surage);
|
|
|
|
|
|
|
|
json.put("org_charge", org_charge);
|
|
|
|
|
|
|
|
json.put("commission_type", "1");
|
|
|
|
|
|
|
|
json.put("create_time", new Date());
|
|
|
|
|
|
|
|
amountByChannel.add(json);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return amountByChannel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//type 1:一级代理 2:二级代理
|
|
|
|
|
|
|
|
public List<JSONObject> clientChannelAmount(int clientId,JSONObject orgInfo,Map<String, List<JSONObject>> channelMap,JSONObject channelCharge,int year,int month,int type) {
|
|
|
|
|
|
|
|
List<JSONObject> amountByChannel = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<JSONObject>> oneChannel : channelMap.entrySet()) {
|
|
|
|
|
|
|
|
JSONObject rate = merchantInfoProvider.clientCurrentRate(clientId, oneChannel.getValue().get(0).getDate("transaction_time"),oneChannel.getKey());
|
|
|
|
|
|
|
|
String recordId = "";
|
|
|
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
|
|
|
recordId = financialPartnerCommissionMapper.getRecordId(orgInfo.getInteger("org_id"), year, month, oneChannel.getKey());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == 2) {
|
|
|
|
|
|
|
|
recordId = financialAgentCommissionMapper.getRecordId(orgInfo.getInteger("org_id"), year, month, oneChannel.getKey());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BigDecimal total = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal total_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal net_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
BigDecimal royalpay_surage = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
Date datefrom = new Date();
|
|
|
|
|
|
|
|
Date dateto = new Date();
|
|
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
|
|
|
String channel = oneChannel.getKey();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (JSONObject params : oneChannel.getValue()) {
|
|
|
|
|
|
|
|
//增加货币判断
|
|
|
|
|
|
|
|
int i = currencyScale(params.getString("clearing_currency"));
|
|
|
|
|
|
|
|
if (total.compareTo(BigDecimal.ZERO)==0 ) {
|
|
|
|
|
|
|
|
datefrom = params.getDate("transaction_time");
|
|
|
|
|
|
|
|
dateto = params.getDate("transaction_time");
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
if (params.getDate("transaction_time").before(datefrom)) {
|
|
|
|
|
|
|
|
datefrom = params.getDate("transaction_time");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.getDate("transaction_time").after(dateto)) {
|
|
|
|
|
|
|
|
dateto = params.getDate("transaction_time");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total = total.add(params.getBigDecimal("clearing_amount"));
|
|
|
|
|
|
|
|
total_surage = total_surage.add(params.getBigDecimal("total_surcharge")).setScale(i, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
royalpay_surage = royalpay_surage.add(params.getBigDecimal("clearing_amount").multiply(orgInfo.getBigDecimal(channel.toLowerCase() + "_rate_value").divide(CommonConsts.HUNDRED, 4, RoundingMode.DOWN)).setScale(i, RoundingMode.HALF_UP));
|
|
|
|
|
|
|
|
//net_surage = net_surage.add(getThirdPartyCharge(params.getString("channel"), params.getBigDecimal("clearing_amount"), channelCharge));
|
|
|
|
|
|
|
|
net_surage = net_surage.add(params.getBigDecimal("channel_surcharge"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BigDecimal org_charge = total_surage.subtract(royalpay_surage);
|
|
|
|
|
|
|
|
if(channel.toLowerCase().equals("alipay_direct")){
|
|
|
|
|
|
|
|
channel = channel.replace("_", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
json.put("channel",channel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json.put("record_id",recordId);
|
|
|
|
|
|
|
|
json.put("client_id",clientId);
|
|
|
|
|
|
|
|
json.put("client_rate",rate.getBigDecimal("rate_value").setScale(2,RoundingMode.DOWN));
|
|
|
|
|
|
|
|
json.put("gross_amount",total);
|
|
|
|
|
|
|
|
json.put("total_charge",total_surage);
|
|
|
|
|
|
|
|
json.put("org_rate", orgInfo.getBigDecimal(channel.toLowerCase() + "_rate_value"));
|
|
|
|
|
|
|
|
json.put("royalpay_charge", royalpay_surage);
|
|
|
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
|
|
|
json.put("net_charge",net_surage);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == 2) {
|
|
|
|
|
|
|
|
json.put("org_net_charge",net_surage);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
json.put("org_charge", org_charge);
|
|
|
|
|
|
|
|
json.put("commission_type", "1");
|
|
|
|
|
|
|
|
json.put("create_time", new Date());
|
|
|
|
|
|
|
|
json.put("date_from", DateFormatUtils.format(datefrom,"yyyy-MM-dd"));
|
|
|
|
|
|
|
|
json.put("date_to", DateFormatUtils.format(dateto,"yyyy-MM-dd"));
|
|
|
|
|
|
|
|
json.put("year", year);
|
|
|
|
|
|
|
|
json.put("month", month);
|
|
|
|
|
|
|
|
amountByChannel.add(json);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return amountByChannel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int currencyScale(String currency) {
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
switch (currency) {
|
|
|
|
|
|
|
|
case "JPY":
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
i = 2;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BigDecimal getThirdPartyCharge(String channel, BigDecimal total,JSONObject chargeRate) {
|
|
|
|
|
|
|
|
BigDecimal thirdPartyPaymentCharge = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
switch (channel) {
|
|
|
|
|
|
|
|
case "Alipay":
|
|
|
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(chargeRate.getBigDecimal("alipayChargeRate").divide(CommonConsts.HUNDRED, 4, BigDecimal.ROUND_DOWN)).setScale(2,RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Wechat":
|
|
|
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(chargeRate.getBigDecimal("wechatChargeRate").divide(CommonConsts.HUNDRED, 4, BigDecimal.ROUND_DOWN)).setScale(2,RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "jd":
|
|
|
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(chargeRate.getBigDecimal("jdChargeRate").divide(CommonConsts.HUNDRED, 4, BigDecimal.ROUND_DOWN)).setScale(2,RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "AlipayOnline":
|
|
|
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(chargeRate.getBigDecimal("alipayonlineChargeRate").divide(CommonConsts.HUNDRED, 4, BigDecimal.ROUND_DOWN)).setScale(2,RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return thirdPartyPaymentCharge;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public void generateReferrer(String monthStr) {
|
|
|
|
public void generateReferrer(String monthStr) {
|
|
|
@ -371,9 +698,8 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public void generateAgent(String monthStr, int orgId) {
|
|
|
|
public void generateAgentold(String monthStr, int orgId) {
|
|
|
|
JSONObject org = orgMapper.findOne(orgId);
|
|
|
|
JSONObject org = orgMapper.findOne(orgId);
|
|
|
|
if (org == null) {
|
|
|
|
if (org == null) {
|
|
|
|
// shall never happen
|
|
|
|
// shall never happen
|
|
|
@ -425,6 +751,93 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
financialAgentCommissionDetailMapper.save(detail);
|
|
|
|
financialAgentCommissionDetailMapper.save(detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
|
|
|
public void generateAgent(String monthStr,JSONObject channelCharge) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date mon = checkMonth(monthStr);
|
|
|
|
|
|
|
|
Calendar monthCal = Calendar.getInstance();
|
|
|
|
|
|
|
|
monthCal.setTime(mon);
|
|
|
|
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
financialAgentCommissionMapper.clearData(year, month);
|
|
|
|
|
|
|
|
financialAgentCommissionDetailMapper.clearData(year, month);
|
|
|
|
|
|
|
|
List<JSONObject> transactionDetail = transactionMapper.listTransactionForCityPartnerAgentCommissionByDate(year, month);
|
|
|
|
|
|
|
|
Map<Integer, List<JSONObject>> groupByOrgMap = transactionDetail.stream().collect(Collectors.groupingBy(e -> e.getInteger("org_id")));
|
|
|
|
|
|
|
|
for (Map.Entry<Integer, List<JSONObject>> oneOrg : groupByOrgMap.entrySet()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int orgId = oneOrg.getKey();
|
|
|
|
|
|
|
|
JSONObject org = orgMapper.findOne(orgId);
|
|
|
|
|
|
|
|
if (org == null) {
|
|
|
|
|
|
|
|
// shall never happen
|
|
|
|
|
|
|
|
throw new ServerErrorException("Organization Id not exists:" + orgId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject parentOrg = orgMapper.findOne(org.getInteger("parent_org_id"));
|
|
|
|
|
|
|
|
if (parentOrg == null) {
|
|
|
|
|
|
|
|
// shall never happen
|
|
|
|
|
|
|
|
throw new ServerErrorException("Parent Organization Id not exists:" + orgId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (org.getInteger("commission_type")!=1) {
|
|
|
|
|
|
|
|
generateold(monthStr);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<JSONObject> items = oneOrg.getValue();
|
|
|
|
|
|
|
|
Map<String, List<JSONObject>> groupByChannelMap = items.stream().collect(Collectors.groupingBy(e -> e.getString("channel")));
|
|
|
|
|
|
|
|
List<JSONObject> channelAmount = parentOrgChannelAmount(org,parentOrg,groupByChannelMap, channelCharge);
|
|
|
|
|
|
|
|
for (JSONObject channel : channelAmount) {
|
|
|
|
|
|
|
|
if (channel.getBigDecimal("share_charge").compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
|
|
|
|
JSONObject parentCommission = financialPartnerCommissionMapper.findByChanel(year, month, parentOrg.getInteger("org_id"), channel.getString("channel"));
|
|
|
|
|
|
|
|
if (parentCommission == null) {
|
|
|
|
|
|
|
|
JSONObject temp = new JSONObject();
|
|
|
|
|
|
|
|
temp.put("org_id", parentOrg.getInteger("org_id"));
|
|
|
|
|
|
|
|
temp.put("year", year);
|
|
|
|
|
|
|
|
temp.put("month", month);
|
|
|
|
|
|
|
|
temp.put("create_time", new Date());
|
|
|
|
|
|
|
|
temp.put("org_rate", 0);
|
|
|
|
|
|
|
|
temp.put("gross_amount", 0);
|
|
|
|
|
|
|
|
temp.put("total_charge", 0);
|
|
|
|
|
|
|
|
temp.put("royalpay_charge", 0);
|
|
|
|
|
|
|
|
temp.put("org_charge", 0);
|
|
|
|
|
|
|
|
temp.put("share_charge", 0);
|
|
|
|
|
|
|
|
temp.put("channel", channel.getString("channel"));
|
|
|
|
|
|
|
|
temp.put("net_charge", 0);
|
|
|
|
|
|
|
|
temp.put("commission_type", 1);
|
|
|
|
|
|
|
|
temp.put("settle_surcharge", 0);
|
|
|
|
|
|
|
|
financialPartnerCommissionMapper.save(temp);
|
|
|
|
|
|
|
|
parentCommission = temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
parentCommission.put("share_charge", parentCommission.getBigDecimal("share_charge").add(channel.getBigDecimal("share_charge")));
|
|
|
|
|
|
|
|
financialPartnerCommissionMapper.update(parentCommission);
|
|
|
|
|
|
|
|
JSONObject mineCommission = financialPartnerCommissionMapper.findByChanel(year, month, orgId, channel.getString("channel"));
|
|
|
|
|
|
|
|
mineCommission.put("share_charge", mineCommission.getBigDecimal("share_charge").subtract(channel.getBigDecimal("share_charge")));
|
|
|
|
|
|
|
|
financialPartnerCommissionMapper.update(mineCommission);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.put("month", month);
|
|
|
|
|
|
|
|
channel.put("year", year);
|
|
|
|
|
|
|
|
channel.put("org_id", orgId);
|
|
|
|
|
|
|
|
//撤销agent表
|
|
|
|
|
|
|
|
// financialAgentCommissionMapper.save(channel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//撤销agent表
|
|
|
|
|
|
|
|
// Map<Integer, List<JSONObject>> groupByClientMap = transactionDetail.stream().collect(Collectors.groupingBy(e -> e.getInteger("client_id")));
|
|
|
|
|
|
|
|
// for (Map.Entry<Integer, List<JSONObject>> oneClient : groupByClientMap.entrySet()) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// JSONObject org = orgMapper.findOne(oneClient.getValue().get(0).getInteger("org_id"));
|
|
|
|
|
|
|
|
// Map<String, List<JSONObject>> groupByChannel = oneClient.getValue().stream().collect(Collectors.groupingBy(e -> e.getString("channel")));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// List<JSONObject> clientChannelAmount = clientChannelAmount(oneClient.getKey(),org, groupByChannel, channelCharge,year,month,2);
|
|
|
|
|
|
|
|
// for (JSONObject channel : clientChannelAmount) {
|
|
|
|
|
|
|
|
// financialAgentCommissionDetailMapper.save(channel);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|