Merge branch 'develop'

master
luoyang 6 years ago
commit b3eeb2f723

@ -29,8 +29,6 @@ public interface CityPartnerPrizeService {
List<JSONObject> getReferrerPrizeInfoList(String monthStr);
void generateAgent(String month,int orgId);
List<JSONObject> listAgentAvailableMonths(String year);
JSONObject getAgentPrizeInfo(String monthStr);

@ -1,5 +1,41 @@
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.CityPartnerCommissionAnalysis;
import au.com.royalpay.payment.manage.citypartner.beans.ReferrerCommissionAnalysis;
@ -69,6 +105,9 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
private FinancialSeniorPartnerCommissionMapper financialSeniorPartnerCommissionMapper;
@Resource
private FinancialSeniorPartnerCommissionDetailMapper financialSeniorPartnerCommissionDetailMapper;
@Resource
private MerchantInfoProvider merchantInfoProvider;
@Override
public List<JSONObject> listAvailableMonths(String year) {
@ -114,6 +153,10 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
for (JSONObject prize : partnerPrizes) {
plusKey(sum, prize, "gross_amount");
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, "org_charge");
prize.put("monthstr", monthStr);
@ -231,7 +274,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
sumResult.put("net_charge", netCharge);
sumResult.put("client_moniker", clientMoniker);
sumResult.put("channel_detail", entry.getValue());
sumResult.put("type", type);
sumResult.put("type",type);
partnerClientInfos.add(sumResult);
}
result.put("partner_client_infos", partnerClientInfos);
@ -255,9 +298,9 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
return result;
}
@Override
@Transactional
public void generate(String monthStr) {
public void generateold(String monthStr) {
Date mon = checkMonth(monthStr);
Calendar monthCal = Calendar.getInstance();
monthCal.setTime(mon);
@ -268,7 +311,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
BigDecimal alipayChargeRate = new BigDecimal("0.6");
BigDecimal wechatChargeRate = new BigDecimal("0.6");
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) {
alipayChargeRate = sysConfig.getBigDecimal("Alipay_charge_rate");
}
@ -329,7 +372,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
}
Runnable task = () -> {
orgIds.forEach((p) -> {
generateAgent(monthStr, p);
generateAgentold(monthStr, p);
});
generateReferrer(monthStr);
generateSenior(monthStr);
@ -337,6 +380,285 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
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;
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
@Transactional
public void generateReferrer(String monthStr) {
@ -371,9 +693,8 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
}
}
@Override
@Transactional
public void generateAgent(String monthStr, int orgId) {
public void generateAgentold(String monthStr, int orgId) {
JSONObject org = orgMapper.findOne(orgId);
if (org == null) {
// shall never happen
@ -425,6 +746,93 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
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

@ -69,6 +69,7 @@ public class CityPartnerPrizeController {
BigDecimal royalpayCharge = BigDecimal.ZERO;
BigDecimal orgCharge = BigDecimal.ZERO;
BigDecimal netCharge = BigDecimal.ZERO;
BigDecimal shareCharge = BigDecimal.ZERO;
String cityPartnerName = "";
int org_id = 0;
int type = 1;
@ -76,6 +77,7 @@ public class CityPartnerPrizeController {
grossAmount = grossAmount.add(jsonObject.getBigDecimal("gross_amount"));
totalCharge = totalCharge.add(jsonObject.getBigDecimal("total_charge"));
royalpayCharge = royalpayCharge.add(jsonObject.getBigDecimal("royalpay_charge"));
shareCharge = shareCharge.add(jsonObject.getBigDecimal("share_charge"));
orgCharge = orgCharge.add(jsonObject.getBigDecimal("org_charge"));
if (jsonObject.getBigDecimal("net_charge") != null) {
netCharge = netCharge.add(jsonObject.getBigDecimal("net_charge"));
@ -84,10 +86,14 @@ public class CityPartnerPrizeController {
cityPartnerName = jsonObject.getString("name");
type = jsonObject.getIntValue("commission_type");
}
if (entry.getValue().get(0).get("parent_org_id") != null) {
sumResult.put("org_type", "agent");
}
sumResult.put("gross_amount", grossAmount);
sumResult.put("total_charge", totalCharge);
sumResult.put("royalpay_charge", royalpayCharge);
sumResult.put("org_charge", orgCharge);
sumResult.put("share_charge", shareCharge);
sumResult.put("org_name", cityPartnerName);
sumResult.put("org_id", org_id);
sumResult.put("net_charge", netCharge);
@ -95,7 +101,13 @@ public class CityPartnerPrizeController {
sumResult.put("channel_detail", entry.getValue());
resultTotalCharge = resultTotalCharge.add(totalCharge);
resultRoyalpayCharge = resultRoyalpayCharge.add(royalpayCharge);
if ("agent".equals(sumResult.getString("org_type"))) {
resultRoyalpayCharge = resultRoyalpayCharge.add(shareCharge);
}
resultOrgCharge = resultOrgCharge.add(orgCharge);
if (!"agent".equals(sumResult.getString("org_type"))) {
resultOrgCharge = resultOrgCharge.add(shareCharge);
}
resultNetCharge = resultNetCharge.add(netCharge);
partnerInfos.add(sumResult);
}

@ -27,5 +27,6 @@ public interface FinancialAgentCommissionMapper {
List<JSONObject> list(@Param("year") int year, @Param("month") int month);
String getRecordId(@Param("org_id") int orgId, @Param("year") int year, @Param("month") int month, @Param("channel") String channel);
}

@ -19,6 +19,9 @@ public interface FinancialPartnerCommissionMapper {
@AutoSql(type = SqlType.INSERT)
void save(JSONObject commissionAnalysis);
@AutoSql(type = SqlType.UPDATE)
void update(JSONObject commission);
List<Integer> listAvailableMonths(@Param("year") int year);
List<JSONObject> listWithOrgInfo(@Param("year") int year, @Param("month") int month);
@ -32,4 +35,9 @@ public interface FinancialPartnerCommissionMapper {
List<JSONObject> analysisSenior(@Param("year") int year, @Param("month")int month,@Param("orgIds") List<String> orgIds);
JSONObject analysisSeniorForGenerate(@Param("year") int year, @Param("month")int month,@Param("orgIds") List<String> orgIds);
String getRecordId(@Param("org_id") int orgId, @Param("year") int year, @Param("month") int month, @Param("channel") String channel);
JSONObject findByChanel(@Param("year") int year, @Param("month") int month, @Param("org_id") int orgId,@Param("channel") String channel);
}

@ -104,6 +104,9 @@ public interface TransactionMapper {
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> listTransactionForCityPartnerCommissionByDate(@Param("year") int year, @Param("month") int month);
List<JSONObject> listTransactionForCityPartnerAgentCommissionByDate(@Param("year") int year, @Param("month") int month);
List<JSONObject> listTransactionsForCityPartnerCommission(@Param("year") int year, @Param("month") int month);

@ -23,4 +23,10 @@
INNER JOIN sys_org o ON o.org_id = c.org_id and o.parent_org_id is null
WHERE c.year = #{year} AND c.month = #{month}
</select>
<select id="getRecordId" resultType="java.lang.String">
SELECT
c.record_id
FROM financial_agent_commission c
WHERE c.org_id = #{org_id} AND c.year = #{year} AND c.month = #{month} AND c.channel = #{channel}
</select>
</mapper>

@ -58,6 +58,18 @@
</foreach>)
</select>
<select id="getRecordId" resultType="java.lang.String">
SELECT
c.record_id
FROM financial_partner_commission c
WHERE c.org_id = #{org_id} AND c.year = #{year} AND c.month = #{month} AND c.channel = #{channel}
</select>
<select id="findByChanel" resultType="com.alibaba.fastjson.JSONObject">
SELECT
*
FROM financial_partner_commission
WHERE year = #{year} AND month = #{month} and org_id=#{org_id} and channel=#{channel}
</select>
</mapper>

@ -662,7 +662,36 @@ select sum(if(temp.transaction_type='Credit',temp.clearing_amount*d.proportion,
]]>
</select>
<select id="listTransactionForCityPartnerCommissionByDate" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
select t.org_id,t.clearing_currency,t.client_id,t.channel,t.surcharge_rate,t.transaction_time,if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount) clearing_amount,
if(t.transaction_type = 'Credit', t.total_surcharge, -t.total_surcharge) total_surcharge,
if(t.transaction_type = 'Credit', t.channel_surcharge, -t.channel_surcharge) channel_surcharge,
t.order_id
from pmt_transactions t INNER JOIN sys_org so ON t.org_id = so.org_id AND so.is_valid = 1
AND so.type=0
AND so.citypartner = 1 AND so.commission = 1
AND year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month}
AND t.channel != 'Settlement' AND t.channel!='System'
ORDER BY t.client_id asc
]]>
</select>
<select id="listTransactionForCityPartnerAgentCommissionByDate" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
select t.org_id,t.client_id,t.channel,t.surcharge_rate,t.transaction_time,if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount) clearing_amount,
if(t.transaction_type = 'Credit', t.total_surcharge, -t.total_surcharge) total_surcharge,
if(t.transaction_type = 'Credit', t.channel_surcharge, -t.channel_surcharge) channel_surcharge,
t.order_id
from pmt_transactions t INNER JOIN sys_org so ON t.org_id = so.org_id AND so.is_valid = 1
AND so.type=0
AND so.parent_org_id !=''
AND so.citypartner = 1 AND so.commission = 1
AND year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month}
AND t.channel != 'Settlement' AND t.channel!='System'
ORDER BY t.client_id asc
]]>
</select>
<select id="listTransactionsForReferrerCommission" resultType="com.alibaba.fastjson.JSONObject">
SELECT
sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount))

@ -583,6 +583,11 @@ margin-bottom: 10%;"/>
<i class="fa fa-users"></i> <span>合伙人提成</span>
</a>
</li>
<li ui-sref-active="active" ng-if="('orgcommission'|withModule)">
<a ui-sref="analysis_org.info" ui-sref-opts="{reload:true}">
<i class="fa fa-hand-peace-o"></i> <span>合伙人提成计算说明</span>
</a>
</li>
<li ui-sref-active="active" ng-if="('cashbackAnalysis'|withModule)">
<a ui-sref="cashbackAnalysis">
<i class="fa fa-gift"></i> <span>商户营销账户</span>
@ -813,6 +818,11 @@ margin-bottom: 10%;"/>
<i class="fa fa-hand-peace-o"></i> <span>合伙人提成</span>
</a>
</li>
<li ui-sref-active="active" ng-if="('orgcommission'|withModule)">
<a ui-sref="analysis_org.info" ui-sref-opts="{reload:true}">
<i class="fa fa-hand-peace-o"></i> <span>合伙人提成计算说明</span>
</a>
</li>
</ul>
</li>

@ -26,6 +26,10 @@ define(['angular','../../analysis/org/analysis-org'], function (angular) {
url: '/commissionorg/months/{monthStr}',
templateUrl: '/static/config/orgcommission/templates/org_commission_month_root.html',
controller: 'commissionMonthRootCtrl'
}).state('analysis_org.info', {
url: '/commissionorg/info',
templateUrl: '/static/config/orgcommission/templates/org_commission_info.html',
controller: 'commissionMonthRootCtrl'
}).state('analysis_org.commission.month.org', {
url: '/org',
templateUrl: '/static/config/orgcommission/templates/org_commission_month.html',

@ -0,0 +1,33 @@
<div ui-view>
<section class="content">
<div class="box box-info">
<div class="box-body">
<h4>合伙人提成计算说明</h4>
<ul>
<li>2018-11-30更新</li>
<li>合伙人提成算法:按照合伙人签约的商户下每笔订单计算合伙人提成,提成规则明细如下: &nbsp&nbsp
<span style="color:red">(取整规则为四舍五入保留2位小数)</span>
</li>
<li>单笔订单 :&nbsp&nbsp(单笔订单交易金额 * 商家签约费率)<span style="font-size: 1px;color:red">取整</span> &nbsp&nbsp&nbsp - &nbsp&nbsp单笔订单交易金额 * 组织成本费率)<span style="font-size: 1px;color:red">取整</span> &nbsp&nbsp&nbsp
= &nbsp&nbsp&nbsp单笔订单合伙人提成</li>
<li>总交易额 : &nbsp合伙人签约的商户累计交易额</li>
<li>平台手续费:合伙人签约的商户(单笔订单交易金额 * 组织成本费率)<span style="font-size: 1px;color:red">取整</span> 累加</li>
<li>合伙人提成: 每笔订单合伙人提成累加</li>
<li>·······························································································································································</li>
<li>如合伙人存在二级代理,可从二级代理的交易额中得到分润,分润规则如下:</li>
<li>二级代理合伙人提成计算规则如同一级代理,分润从平台手续费中扣除。</li>
<li>如A合伙人与平台签约组织成本费率为1.5%A合伙人的二级代理B的签约组织成本费率为1.8%B的商户签约费率为3%</li>
<li>假设B当月只有一笔交易且交易额为1000总手续费为30平台手续费为18B合伙人提成为12。</li>
<li>计算A的分润时会将B的交易额1000 * A的组织成本费率 1.5% = 15A的分润就是 18-15=3而B合伙人平台手续费为15其中扣除3是A的分润</li>
</ul>
<h4>补充说明</h4>
<ul style="color:red">
<li >退款成功的订单不计入合伙人提成内</li>
<li>当本月有合伙人手续费存在欠款时,无法下载汇款文件</li>
</ul>
</div>
</div>
</section>
</div>

@ -33,18 +33,51 @@
<th>RoyalPay Charge</th>
<th>Net Charge</th>
<th>City Partner Charge</th>
<th>Share Charge</th>
<th>Type</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr ng-repeat-start="log in monthData.partner_info_list">
<td ng-bind="log.org_name"></td>
<td ng-bind="log.gross_amount|currency:'AUD'"></td>
<td ng-bind="log.total_charge|currency:'AUD'"></td>
<td ng-bind="log.royalpay_charge|currency:'AUD'"></td>
<td ng-bind="log.net_charge|currency:'AUD'"></td>
<td ng-bind="log.org_charge|currency:'AUD'"></td>
<td>
{{log.org_name}}
<span ng-if="log.org_type=='agent'">(二级代理)</span>
<span ng-if="log.org_type==null">(一级代理)</span>
</td>
<td ng-bind="log.gross_amount"></td>
<td ng-bind="log.total_charge"></td>
<td ng-if="log.org_type == 'agent' && log.share_charge!=0">
<span >
{{(log.royalpay_charge+log.share_charge)}}
</span>
<span style="color: red;font-size: 6px" >
({{log.royalpay_charge}}
</span>
<span style="color: red;font-size: 6px" ng-if="log.share_charge > 0 "> + </span>
<span style="color: red;font-size: 6px">
{{log.share_charge}})
</span>
</td>
<td ng-if="log.org_type != 'agent' || log.share_charge==0" ng-bind="log.royalpay_charge" ></td>
<td ng-bind="log.net_charge"></td>
<td ng-if="log.org_type==null && log.share_charge !=0">
<span>
{{(log.org_charge+log.share_charge)}}
</span>
<span style="color: red;font-size: 6px">
({{log.org_charge}}
</span>
<span style="color: red;font-size: 6px" ng-if="log.share_charge >= 0"> + </span>
<span style="color: red;font-size: 6px">
{{log.share_charge}})
</span>
</td>
<td ng-if="log.org_type=='agent' || log.share_charge ==0">
{{log.org_charge}}
</td>
<td ng-bind="log.share_charge"></td>
<td ng-bind="log.type|commission_type_filter"></td>
<td>
<a ui-sref=".orgdetail({orgId:log.org_id})">
@ -66,6 +99,7 @@
<th>RoyalPay Charge</th>
<th>Net Charge</th>
<th>City Partner Charge</th>
<th>Share Charge</th>
<th>channel</th>
</tr>
</thead>
@ -77,6 +111,7 @@
<td ng-bind="detail.royalpay_charge"></td>
<td ng-bind="detail.net_charge"></td>
<td ng-bind="detail.org_charge"></td>
<td ng-bind="detail.share_charge"></td>
<td ng-bind="detail.channel"></td>
</tr>
</tbody>

@ -435,6 +435,16 @@
</div>
</a>
</div>
<div ng-if="('orgcommission'|withModule)" class="col-sm-2 col-xs-6">
<a ui-sref="analysis_org.info" ui-sref-opts="{reload:true}">
<div class="description-block">
<img src="/static/images/main_menu/partner_commission.png"/>
<div class="description-text">
<span class="description-text">合伙人提成计算说明</span>
</div>
</div>
</a>
</div>
<!--
<div ng-if="('citypartner'|withModule)" class="col-sm-2 col-xs-6">
<a ui-sref="citypartner_reg" ui-sref-opts="{reload:true}">
@ -762,6 +772,15 @@
</div>
</div>
</a></div>
<div class="col-sm-2 col-xs-6">
<a ui-sref="analysis_org.info" ui-sref-opts="{reload:true}">
<div class="description-block">
<img src="/static/images/main_menu/finance_partner_contribution.png"/>
<div class="description-text">
<span class="description-text">合伙人提成计算说明</span>
</div>
</div>
</a></div>
<div ng-if="'cashbackAnalysis'|withModule" class="col-sm-2 col-xs-6">
<a ui-sref="cashbackAnalysis" ui-sref-opts="{reload:true}">
<div class="description-block">

@ -22,7 +22,6 @@ public class CityPartnerPrizeServiceImplTest {
private CityPartnerPrizeService cityPartnerPrizeService;
@Test
public void generateAgent() throws Exception {
cityPartnerPrizeService.generateAgent("2017-06",9);
}
@Test

Loading…
Cancel
Save