|
|
|
@ -1,34 +1,30 @@
|
|
|
|
|
package au.com.royalpay.payment.manage.analysis.core.impls;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.channels.alipay.runtime.AlipayClient;
|
|
|
|
|
import au.com.royalpay.payment.channels.wechat.config.WeChatPayConfig;
|
|
|
|
|
import au.com.royalpay.payment.channels.wechat.config.WechatPayEnvironment;
|
|
|
|
|
import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi;
|
|
|
|
|
import au.com.royalpay.payment.channels.wechat.runtime.beans.SettlementLog;
|
|
|
|
|
import au.com.royalpay.payment.core.exceptions.ChannelNetworkException;
|
|
|
|
|
import au.com.royalpay.payment.core.ChannelSettleVerify;
|
|
|
|
|
import au.com.royalpay.payment.core.beans.SettlementLog;
|
|
|
|
|
import au.com.royalpay.payment.manage.analysis.core.PlatformClearService;
|
|
|
|
|
import au.com.royalpay.payment.manage.analysis.mappers.EstimateAnalysisMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.PlatformSettlementMapper;
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient;
|
|
|
|
|
import au.com.royalpay.payment.tools.defines.PayChannel;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.Order;
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageList;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
@ -37,16 +33,10 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
|
public static final SimpleDateFormat sdfClear = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
public static final SimpleDateFormat sdfNormal = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private MpPaymentApi mpPaymentApi;
|
|
|
|
|
@Resource
|
|
|
|
|
private AlipayClient alipayClient;
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
|
private ChannelSettleVerify[] channelSettleVerifys;
|
|
|
|
|
@Resource
|
|
|
|
|
private PlatformSettlementMapper platformSettlementMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private EstimateAnalysisMapper estimateAnalysisMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private AttachmentClient attachmentClient;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject getPlatformSettleLog(String channel, int page, int limit) {
|
|
|
|
@ -58,10 +48,11 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject getChannelSettleLog(String channel) {
|
|
|
|
|
JSONObject sysLogs = new JSONObject();
|
|
|
|
|
JSONObject creditLogs = platformSettlementMapper.calculateSysSettleLog5("2018-04-05 02:00:00", sdfNormal.format(new Date()), channel, "Credit");
|
|
|
|
|
Date fromDate = DateTime.parse("2018-04-05T02:00:00+10:00").toDate();
|
|
|
|
|
JSONObject creditLogs = platformSettlementMapper.calculateChannelSysSettleLog(fromDate, new Date(), channel, "Credit");
|
|
|
|
|
sysLogs.put("sys_pay_fee", creditLogs.getBigDecimal("rmb_amount"));
|
|
|
|
|
|
|
|
|
|
JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog5("2018-04-05 02:00:00", sdfNormal.format(new Date()), channel, "Debit");
|
|
|
|
|
JSONObject debitLogs = platformSettlementMapper.calculateChannelSysSettleLog(fromDate, new Date(), channel, "Debit");
|
|
|
|
|
sysLogs.put("sys_refund_fee", debitLogs.getBigDecimal("rmb_amount"));
|
|
|
|
|
|
|
|
|
|
sysLogs.put("surcharge", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount")));
|
|
|
|
@ -74,121 +65,41 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void verifySettleLogByDate(String start_date, String end_date, String channel) {
|
|
|
|
|
if (StringUtils.equals("Alipay", channel)) {
|
|
|
|
|
try {
|
|
|
|
|
doVerifyAlipaySettleLog(sdfClear.parse(end_date));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("PlatformClearAnalysisServiceImpl.verifySettleLogByDate ==> 校验" + end_date + "支付宝到账失败:", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.equals("AlipayOnline", channel)) {
|
|
|
|
|
try {
|
|
|
|
|
doVerifyAlipayOnlineSettleLog(sdfClear.parse(end_date));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("PlatformClearAnalysisServiceImpl.verifySettleLogByDate ==> 校验" + end_date + "支付宝Online到账失败:", e);
|
|
|
|
|
throw new ChannelNetworkException("校验失败:", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.equals("Wechat", channel)) {
|
|
|
|
|
try {
|
|
|
|
|
Map<String, Date> settleDate = new HashMap<>();
|
|
|
|
|
settleDate.put("from", sdfClear.parse(start_date));
|
|
|
|
|
settleDate.put("to", sdfClear.parse(end_date));
|
|
|
|
|
doVerifyWechatSettleLog(settleDate);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("PlatformClearAnalysisServiceImpl.verifySettleLogByDate ==> 校验" + end_date + "微信到账失败:", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
// @Transactional
|
|
|
|
|
public void generateSettleLogs() {
|
|
|
|
|
// deleteSettleLogs();
|
|
|
|
|
generateWechatSettleLogs();
|
|
|
|
|
generateAlipaySettleLogs();
|
|
|
|
|
generateAlipayOnlineSettleLogs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void generateAliPaySettleLogs() {
|
|
|
|
|
generateAlipaySettleLogs();
|
|
|
|
|
generateAlipayOnlineSettleLogs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public void generateWechatSettleLogs() {
|
|
|
|
|
try {
|
|
|
|
|
Map<String, Date> settleDate = TimeZoneUtils.getStatetimeDays();
|
|
|
|
|
logger.info("开始查询" + settleDate.get("from") + "到" + settleDate.get("to") + "的微信清算记录");
|
|
|
|
|
doVerifyWechatSettleLog(settleDate);
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
public void verifySettleLogByDate(String startDate, String endDate, String channel) {
|
|
|
|
|
if (channelSettleVerifys == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void generateAlipaySettleLogs() {
|
|
|
|
|
try {
|
|
|
|
|
List<Date> dateList = TimeZoneUtils.getStatetime();
|
|
|
|
|
for (Date dateStr : dateList) {
|
|
|
|
|
try {
|
|
|
|
|
doVerifyAlipaySettleLog(dateStr);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("获取" + dateStr + "Alipay清算记录失败", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("获取Alipay清算记录时间失败", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void generateAlipayOnlineSettleLogs() {
|
|
|
|
|
try {
|
|
|
|
|
List<Date> dateList = TimeZoneUtils.getStatetime();
|
|
|
|
|
for (Date dateStr : dateList) {
|
|
|
|
|
try {
|
|
|
|
|
doVerifyAlipayOnlineSettleLog(dateStr);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("获取" + dateStr + "AlipayOnline清算记录失败", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("获取AlipayOnline清算记录时间失败", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public void doVerifyAlipaySettleLog(Date dateStr) throws Exception {
|
|
|
|
|
JSONObject aliSettleLog = alipayClient.oldDownloadRetailSettlements(dateStr);
|
|
|
|
|
saveAlipaySettleLog(dateStr, aliSettleLog, "Alipay");
|
|
|
|
|
}
|
|
|
|
|
Arrays.stream(channelSettleVerifys).filter(verify -> verify.payChannel().getChannelCode().equalsIgnoreCase(channel))
|
|
|
|
|
.findFirst().ifPresent(verify -> {
|
|
|
|
|
try {
|
|
|
|
|
Date currentDate = sdfClear.parse(startDate);
|
|
|
|
|
Date end = sdfClear.parse(endDate);
|
|
|
|
|
while (!end.before(currentDate)) {
|
|
|
|
|
saveVerifyResults(currentDate, verify);
|
|
|
|
|
currentDate = DateUtils.addDays(currentDate, 1);
|
|
|
|
|
}
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
throw new BadRequestException("Invalid Date Format");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public void doVerifyAlipayOnlineSettleLog(Date dateStr) throws Exception {
|
|
|
|
|
JSONObject aliOnlineSettleLog = alipayClient.downloadOnlineSettlements(dateStr);
|
|
|
|
|
saveAlipaySettleLog(dateStr, aliOnlineSettleLog, "AlipayOnline");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveAlipaySettleLog(Date dateStr, JSONObject aliSettleLog, String channel) throws Exception {
|
|
|
|
|
if (aliSettleLog != null) {
|
|
|
|
|
JSONObject settleFee = getAliSettle(aliSettleLog);
|
|
|
|
|
private void saveVerifyResults(Date date, ChannelSettleVerify verify) {
|
|
|
|
|
logger.info("starting verify for channel {} on {}", verify.payChannel(), date);
|
|
|
|
|
List<SettlementLog> logs = verify.verifyResults(date);
|
|
|
|
|
logger.info("loaded {} settle logs for channel {} on {}", logs.size(), verify.payChannel(), date);
|
|
|
|
|
for (SettlementLog settle : logs) {
|
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
|
params.put("settle_date", dateStr);
|
|
|
|
|
params.put("start_date", dateStr);
|
|
|
|
|
params.put("end_date", dateStr);
|
|
|
|
|
params.put("pay_fee", settleFee.getBigDecimal("credit"));
|
|
|
|
|
params.put("refund_fee", settleFee.getBigDecimal("debit"));
|
|
|
|
|
params.put("net_fee", settleFee.getBigDecimal("net_fee"));
|
|
|
|
|
params.put("surcharge", settleFee.getBigDecimal("surcharge"));
|
|
|
|
|
params.put("settlement_fee", settleFee.getBigDecimal("settlement_fee"));
|
|
|
|
|
params.put("channel", channel);
|
|
|
|
|
params.put("settle_date", settle.getSettlementDate());
|
|
|
|
|
params.put("start_date", TimeZoneUtils.formatTime(settle.getStart(), TimeZoneUtils.PATTERN_NORMAL, "Asia/Shanghai"));
|
|
|
|
|
params.put("end_date", TimeZoneUtils.formatTime(settle.getEnd(), TimeZoneUtils.PATTERN_NORMAL, "Asia/Shanghai"));
|
|
|
|
|
if (verify.payChannel() == PayChannel.WECHAT) {
|
|
|
|
|
params.put("settle_date", TimeZoneUtils.formatTime(settle.getSettlementDate(), TimeZoneUtils.PATTERN_NORMAL, "Asia/Shanghai"));
|
|
|
|
|
}
|
|
|
|
|
params.put("channel", verify.payChannel().getChannelCode());
|
|
|
|
|
params.put("last_update_date", new Date());
|
|
|
|
|
JSONObject sysClearData = getSystemClearingAmount(dateStr, aliSettleLog, channel);
|
|
|
|
|
JSONObject sysClearData = getSystemClearingAmount(settle, verify.payChannel().getChannelCode());
|
|
|
|
|
if (sysClearData != null && !sysClearData.isEmpty()) {
|
|
|
|
|
params.put("sys_pay_fee", sysClearData.getBigDecimal("sys_pay_fee"));
|
|
|
|
|
params.put("sys_refund_fee", sysClearData.getBigDecimal("sys_refund_fee"));
|
|
|
|
@ -196,173 +107,74 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
|
params.put("sys_surcharge", sysClearData.getBigDecimal("sys_surcharge"));
|
|
|
|
|
params.put("sys_settlement_fee", sysClearData.getBigDecimal("sys_settle_fee"));
|
|
|
|
|
}
|
|
|
|
|
JSONObject check = platformSettlementMapper.findByDateMerchant(sdfClear.format(dateStr), channel, "All");
|
|
|
|
|
if (check != null) {
|
|
|
|
|
params.put("log_id", check.getString("log_id"));
|
|
|
|
|
platformSettlementMapper.update(params);
|
|
|
|
|
} else {
|
|
|
|
|
platformSettlementMapper.save(params);
|
|
|
|
|
params.put("merchants", settle.getMerchantId());
|
|
|
|
|
params.put("pay_fee", settle.getPayFee());
|
|
|
|
|
params.put("refund_fee", settle.getRefundFee());
|
|
|
|
|
params.put("net_fee", settle.getPayNetFee());
|
|
|
|
|
if (verify.payChannel() != PayChannel.WECHAT) {
|
|
|
|
|
params.put("net_fee", settle.getPayFee().subtract(settle.getRefundFee()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void doVerifyWechatSettleLog(Map<String, Date> settleDate) {
|
|
|
|
|
List<SettlementLog> tencentSettle = new ArrayList<>();
|
|
|
|
|
for (WeChatPayConfig.Merchant mch : WechatPayEnvironment.getEnv().getWechatMerchantConfigs()) {
|
|
|
|
|
params.put("settlement_fee", settle.getSettlementFee());
|
|
|
|
|
params.put("surcharge", settle.getPoundageFee());
|
|
|
|
|
params.put("unsettle_fee", settle.getUnsettlementFee());
|
|
|
|
|
try {
|
|
|
|
|
tencentSettle = mpPaymentApi.settlementLogs(settleDate.get("from"), settleDate.get("to"), mch.getMerchantId());
|
|
|
|
|
if (tencentSettle == null) {
|
|
|
|
|
logger.info("【{}】下没有清算记录", mch.getMerchantId());
|
|
|
|
|
if (("1500474722".equals(settle.getMerchantId()) && settle.getSettlementDate().before(DateTime.parse("2018-06-02").toDate())) ||
|
|
|
|
|
("1492874492".equals(settle.getMerchantId()) && settle.getSettlementDate().after(DateTime.parse("2018-06-05").toDate()))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
JSONObject check = platformSettlementMapper.findByDateMerchant(verify.payChannel() == PayChannel.WECHAT ? TimeZoneUtils.formatTime(settle.getSettlementDate(), TimeZoneUtils.PATTERN_NORMAL, "Asia/Shanghai") : sdfClear.format(settle.getSettlementDate()), verify.payChannel().getChannelCode(), settle.getMerchantId());
|
|
|
|
|
if (check != null) {
|
|
|
|
|
params.put("log_id", check.getString("log_id"));
|
|
|
|
|
platformSettlementMapper.update(params);
|
|
|
|
|
} else {
|
|
|
|
|
for (SettlementLog settle : tencentSettle) {
|
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
|
params.put("settle_date", settle.getSettlementDate());
|
|
|
|
|
params.put("start_date", settle.getStart());
|
|
|
|
|
params.put("end_date", settle.getEnd());
|
|
|
|
|
params.put("channel", "Wechat");
|
|
|
|
|
params.put("last_update_date", new Date());
|
|
|
|
|
JSONObject sysClearData = getSystemClearingAmount(null, settle, "Wechat");
|
|
|
|
|
if (sysClearData != null && !sysClearData.isEmpty()) {
|
|
|
|
|
params.put("sys_pay_fee", sysClearData.getBigDecimal("sys_pay_fee"));
|
|
|
|
|
params.put("sys_refund_fee", sysClearData.getBigDecimal("sys_refund_fee"));
|
|
|
|
|
params.put("sys_net_fee", sysClearData.getBigDecimal("sys_net_fee"));
|
|
|
|
|
params.put("sys_surcharge", sysClearData.getBigDecimal("sys_surcharge"));
|
|
|
|
|
params.put("sys_settlement_fee", sysClearData.getBigDecimal("sys_settle_fee"));
|
|
|
|
|
}
|
|
|
|
|
params.put("merchants", mch.getMerchantId());
|
|
|
|
|
params.put("pay_fee", settle.getPayFee());
|
|
|
|
|
params.put("refund_fee", settle.getRefundFee());
|
|
|
|
|
params.put("net_fee", settle.getPayNetFee());
|
|
|
|
|
params.put("settlement_fee", settle.getSettlementFee());
|
|
|
|
|
params.put("surcharge", settle.getPoundageFee());
|
|
|
|
|
params.put("unsettle_fee", settle.getUnsettlementFee());
|
|
|
|
|
|
|
|
|
|
JSONObject check = platformSettlementMapper.findByDateMerchant(sdfClear.format(settle.getSettlementDate()), "Wechat",
|
|
|
|
|
mch.getMerchantId());
|
|
|
|
|
if (check != null) {
|
|
|
|
|
params.put("log_id", check.getString("log_id"));
|
|
|
|
|
platformSettlementMapper.update(params);
|
|
|
|
|
} else {
|
|
|
|
|
platformSettlementMapper.save(params);
|
|
|
|
|
}
|
|
|
|
|
params.clear();
|
|
|
|
|
logger.info("{}的微信清算记录查询完成", mch.getMerchantId());
|
|
|
|
|
}
|
|
|
|
|
platformSettlementMapper.save(params);
|
|
|
|
|
}
|
|
|
|
|
params.clear();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("【{}】下没有清算记录", mch.getMerchantId(), e);
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JSONObject getAliSettle(JSONObject aliSettleLog) {
|
|
|
|
|
JSONObject alipaySettleLog = new JSONObject();
|
|
|
|
|
|
|
|
|
|
JSONArray payments = aliSettleLog.getJSONArray("payments");
|
|
|
|
|
BigDecimal credit = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal creditFee = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal creditSettle = BigDecimal.ZERO;
|
|
|
|
|
if (payments != null) {
|
|
|
|
|
for (int i = 0; i < payments.size(); i++) {
|
|
|
|
|
JSONObject json = payments.getJSONObject(i);
|
|
|
|
|
BigDecimal transactionAmount = json.getBigDecimal("transaction_amount");
|
|
|
|
|
BigDecimal chargeFee = json.getBigDecimal("charge_fee");
|
|
|
|
|
credit = credit.add(transactionAmount);
|
|
|
|
|
creditFee = creditFee.add(chargeFee);
|
|
|
|
|
if (json.containsKey("settle_amount")) {
|
|
|
|
|
creditSettle = creditSettle.add(json.getBigDecimal("settle_amount"));
|
|
|
|
|
} else {
|
|
|
|
|
creditSettle = creditSettle.add(transactionAmount.subtract(chargeFee));
|
|
|
|
|
@Override
|
|
|
|
|
// @Transactional
|
|
|
|
|
public void generateSettleLogs() {
|
|
|
|
|
if (channelSettleVerifys != null) {
|
|
|
|
|
try {
|
|
|
|
|
List<Date> dateList = TimeZoneUtils.getStatetime();
|
|
|
|
|
for (Date date : dateList) {
|
|
|
|
|
for (ChannelSettleVerify verify : channelSettleVerifys) {
|
|
|
|
|
try {
|
|
|
|
|
saveVerifyResults(date, verify);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("[{}]{} failed to download settle file", date, verify.payChannel(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (ParseException ignored) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
alipaySettleLog.put("credit", credit);
|
|
|
|
|
|
|
|
|
|
JSONArray refunds = aliSettleLog.getJSONArray("refunds");
|
|
|
|
|
logger.info("alipay的refunds清算总信息" + refunds.toJSONString());
|
|
|
|
|
BigDecimal debit = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal debitFee = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal debitSettle = BigDecimal.ZERO;
|
|
|
|
|
for (int i = 0; i < refunds.size(); i++) {
|
|
|
|
|
JSONObject json = refunds.getJSONObject(i);
|
|
|
|
|
BigDecimal transactionAmount = json.getBigDecimal("transaction_amount");
|
|
|
|
|
BigDecimal chargeFee = json.getBigDecimal("charge_fee");
|
|
|
|
|
debit = debit.add(transactionAmount);
|
|
|
|
|
debitFee = debitFee.add(chargeFee);
|
|
|
|
|
if (json.containsKey("settle_amount")) {
|
|
|
|
|
debitSettle = debitSettle.add(json.getBigDecimal("settle_amount"));
|
|
|
|
|
} else {
|
|
|
|
|
debitSettle = debitSettle.add(transactionAmount.subtract(chargeFee));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
alipaySettleLog.put("debit", debit);
|
|
|
|
|
alipaySettleLog.put("net_fee", credit.subtract(debit));
|
|
|
|
|
alipaySettleLog.put("surcharge", creditFee.subtract(debitFee));
|
|
|
|
|
alipaySettleLog.put("settlement_fee", creditSettle.subtract(debitSettle));
|
|
|
|
|
logger.info("阿里清算日志:" + alipaySettleLog.toJSONString());
|
|
|
|
|
return alipaySettleLog;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JSONObject getSystemClearingAmount(Date settle_date, Object settlementLog, String channel) throws Exception {
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 02:00:00");
|
|
|
|
|
private JSONObject getSystemClearingAmount(SettlementLog settlementLog, String channel) {
|
|
|
|
|
JSONObject sysLogs = new JSONObject();
|
|
|
|
|
String start_date = null;
|
|
|
|
|
String end_date = null;
|
|
|
|
|
if (StringUtils.equals("Alipay", channel)) {
|
|
|
|
|
JSONObject lastClearDay = estimateAnalysisMapper.findLastCleanDays(sdfClear.format(settle_date), 1);
|
|
|
|
|
start_date = sdf.format(lastClearDay.getDate("date_str"));
|
|
|
|
|
end_date = sdf.format(settle_date);
|
|
|
|
|
logger.info("Alipay System Settle Logs:" + start_date + "<====>" + end_date);
|
|
|
|
|
} else if (StringUtils.equals("Wechat", channel)) {
|
|
|
|
|
SettlementLog wechatSettleLog = (SettlementLog) settlementLog;
|
|
|
|
|
start_date = sdf.format(wechatSettleLog.getStart());
|
|
|
|
|
end_date = sdf.format(wechatSettleLog.getEnd());
|
|
|
|
|
logger.info("Wechat System Settle Logs:" + start_date + "<====>" + end_date);
|
|
|
|
|
} else if (StringUtils.equals("AlipayOnline", channel)) {
|
|
|
|
|
JSONObject alipayOnlineSettleLog = (JSONObject) settlementLog;
|
|
|
|
|
logger.info("AlipayOnline System Settle Logs:" + alipayOnlineSettleLog.getDate("min_time") + "<====>" + alipayOnlineSettleLog.getDate("max_time"));
|
|
|
|
|
start_date = sdf.format(alipayOnlineSettleLog.getDate("min_time"));
|
|
|
|
|
end_date = sdf.format(DateUtils.addDays(alipayOnlineSettleLog.getDate("max_time"), 1));
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2017-11-01后微信手续费0.5
|
|
|
|
|
BigDecimal wechat_rate;
|
|
|
|
|
if (end_date.compareTo("2017-11-01 03:00:00") <= 0) {
|
|
|
|
|
wechat_rate = new BigDecimal("0.006");
|
|
|
|
|
} else {
|
|
|
|
|
wechat_rate = new BigDecimal("0.005");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2018-09-01后Alipay_Online手续费0.006
|
|
|
|
|
BigDecimal alipay_online_rate;
|
|
|
|
|
if (end_date.compareTo("2018-09-01 02:00:00") <= 0) {
|
|
|
|
|
alipay_online_rate = new BigDecimal("0.018");
|
|
|
|
|
} else {
|
|
|
|
|
alipay_online_rate = new BigDecimal("0.006");
|
|
|
|
|
}
|
|
|
|
|
logger.info("{} System Settle Logs:{}<====>{}", channel, settlementLog.getStart(), settlementLog.getEnd());
|
|
|
|
|
try {
|
|
|
|
|
JSONObject creditLogs = platformSettlementMapper.calculateSysSettleLog(start_date, end_date, channel, "Credit", wechat_rate);
|
|
|
|
|
JSONObject creditLogs = platformSettlementMapper.calculateSysSettleLog(settlementLog.getStart(), settlementLog.getEnd(), settlementLog.getMerchantId(), channel, "Credit");
|
|
|
|
|
sysLogs.put("sys_pay_fee", creditLogs.getBigDecimal("aud_amount"));
|
|
|
|
|
|
|
|
|
|
JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog(start_date, end_date, channel, "Debit", wechat_rate);
|
|
|
|
|
JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog(settlementLog.getStart(), settlementLog.getEnd(), settlementLog.getMerchantId(), channel, "Debit");
|
|
|
|
|
sysLogs.put("sys_refund_fee", debitLogs.getBigDecimal("aud_amount"));
|
|
|
|
|
|
|
|
|
|
sysLogs.put("sys_net_fee", creditLogs.getBigDecimal("aud_amount").subtract(debitLogs.getBigDecimal("aud_amount")));
|
|
|
|
|
if (StringUtils.equals("Alipay", channel)) {
|
|
|
|
|
sysLogs.put("sys_surcharge", platformSettlementMapper.calculateRmbCharge(start_date, end_date, channel, BigDecimal.valueOf(0.006)));
|
|
|
|
|
} else if (StringUtils.equals("AlipayOnline", channel)) {
|
|
|
|
|
sysLogs.put("sys_surcharge", platformSettlementMapper.calculateRmbCharge(start_date, end_date, channel, alipay_online_rate));
|
|
|
|
|
} else {
|
|
|
|
|
sysLogs.put("sys_surcharge", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount")));
|
|
|
|
|
}
|
|
|
|
|
sysLogs.put("sys_surcharge", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount")));
|
|
|
|
|
sysLogs.put("sys_settle_fee", sysLogs.getBigDecimal("sys_net_fee").subtract(sysLogs.getBigDecimal("sys_surcharge")));
|
|
|
|
|
logger.info("calculated system result[{}|{}~{}]:{}", channel, settlementLog.getStart(), settlementLog.getEnd(), sysLogs);
|
|
|
|
|
return sysLogs;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// do nothing
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
//do nothing
|
|
|
|
|
logger.error("Error caught on analysising {}", channel, e);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|