Merge remote-tracking branch 'origin/alipayplus_aps' into alipayplus_aps

master
dalong306 3 years ago
commit 50da3e565f

@ -4,6 +4,7 @@ import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi;
import au.com.royalpay.payment.core.TransactionService; import au.com.royalpay.payment.core.TransactionService;
import au.com.royalpay.payment.core.beans.PaymentQueryResult; import au.com.royalpay.payment.core.beans.PaymentQueryResult;
import au.com.royalpay.payment.core.beans.PreOrderRequest; import au.com.royalpay.payment.core.beans.PreOrderRequest;
import au.com.royalpay.payment.core.beans.TransactionBizSubType;
import au.com.royalpay.payment.core.beans.coupon.CashCouponInfo; import au.com.royalpay.payment.core.beans.coupon.CashCouponInfo;
import au.com.royalpay.payment.core.beans.coupon.CouponInfo; import au.com.royalpay.payment.core.beans.coupon.CouponInfo;
import au.com.royalpay.payment.core.events.PaymentFinishedEvent; import au.com.royalpay.payment.core.events.PaymentFinishedEvent;
@ -163,7 +164,7 @@ public class OneDollarDayActivitySupportImpl implements OneDollarDayActivity, Pa
log.put("transaction_time", format.format(paymentQueryResult.getPayTime())); log.put("transaction_time", format.format(paymentQueryResult.getPayTime()));
log.put("clearing_status", 0); log.put("clearing_status", 0);
log.put("remark", "Activity: Day Of One Dollar"); log.put("remark", "Activity: Day Of One Dollar");
transactionService.saveTransaction(log); transactionService.saveTransaction(log, TransactionBizSubType.COUPON_PAY);
String transactionId = log.getString("transaction_id"); String transactionId = log.getString("transaction_id");
actDietOrderMapper.setTransactionId(orderId, transactionId, log.getDate("transaction_time")); actDietOrderMapper.setTransactionId(orderId, transactionId, log.getDate("transaction_time"));
} }
@ -214,7 +215,7 @@ public class OneDollarDayActivitySupportImpl implements OneDollarDayActivity, Pa
log.put("transaction_time", new Date()); log.put("transaction_time", new Date());
log.put("clearing_status", 0); log.put("clearing_status", 0);
log.put("remark", "Activity Refund: Day Of One Dollar"); log.put("remark", "Activity Refund: Day Of One Dollar");
transactionService.saveTransaction(log); transactionService.saveTransaction(log,TransactionBizSubType.COUPON_REFUND);
actDietOrderMapper.updateRefund(orderId, log.getString("transaction_id"), log.getDate("transaction_time")); actDietOrderMapper.updateRefund(orderId, log.getString("transaction_id"), log.getDate("transaction_time"));
} }

@ -1,6 +1,5 @@
package au.com.royalpay.payment.manage.analysis.core; package au.com.royalpay.payment.manage.analysis.core;
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.Date; import java.util.Date;

@ -10,10 +10,9 @@ public interface PlatformClearService {
JSONObject getChannelSettleLog(String channel); JSONObject getChannelSettleLog(String channel);
void verifySettleLogByDate(String start_date, String end_date, String channel) throws ParseException; void verifySettleLogByDate(String startDate, String endDate, String channel) throws ParseException;
void generateSettleLogs(); void generateSettleLogs();
void generateAliPaySettleLogs();
} }

@ -3,7 +3,7 @@ package au.com.royalpay.payment.manage.analysis.core.impls;
import au.com.royalpay.payment.channels.wechat.config.WeChatPayConfig; 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.config.WechatPayEnvironment;
import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi; 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.beans.SettlementLog;
import au.com.royalpay.payment.manage.analysis.core.EstimateAnalysisService; import au.com.royalpay.payment.manage.analysis.core.EstimateAnalysisService;
import au.com.royalpay.payment.manage.analysis.core.EstimateCacheSupport; import au.com.royalpay.payment.manage.analysis.core.EstimateCacheSupport;
import au.com.royalpay.payment.manage.analysis.mappers.EstimateAnalysisMapper; import au.com.royalpay.payment.manage.analysis.mappers.EstimateAnalysisMapper;

@ -1,34 +1,30 @@
package au.com.royalpay.payment.manage.analysis.core.impls; package au.com.royalpay.payment.manage.analysis.core.impls;
import au.com.royalpay.payment.channels.alipay.runtime.AlipayClient; import au.com.royalpay.payment.core.ChannelSettleVerify;
import au.com.royalpay.payment.channels.wechat.config.WeChatPayConfig; import au.com.royalpay.payment.core.beans.SettlementLog;
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.manage.analysis.core.PlatformClearService; 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.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.PageListUtils;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils; import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order; import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList; import com.github.miemiedev.mybatis.paginator.domain.PageList;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service @Service
public class PlatformClearAnalysisServiceImpl implements PlatformClearService { 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 sdfClear = new SimpleDateFormat("yyyy-MM-dd");
public static final SimpleDateFormat sdfNormal = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static final SimpleDateFormat sdfNormal = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Resource @Autowired(required = false)
private MpPaymentApi mpPaymentApi; private ChannelSettleVerify[] channelSettleVerifys;
@Resource
private AlipayClient alipayClient;
@Resource @Resource
private PlatformSettlementMapper platformSettlementMapper; private PlatformSettlementMapper platformSettlementMapper;
@Resource
private EstimateAnalysisMapper estimateAnalysisMapper;
@Resource
private AttachmentClient attachmentClient;
@Override @Override
public JSONObject getPlatformSettleLog(String channel, int page, int limit) { public JSONObject getPlatformSettleLog(String channel, int page, int limit) {
@ -58,10 +48,11 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
@Override @Override
public JSONObject getChannelSettleLog(String channel) { public JSONObject getChannelSettleLog(String channel) {
JSONObject sysLogs = new JSONObject(); 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")); 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("sys_refund_fee", debitLogs.getBigDecimal("rmb_amount"));
sysLogs.put("surcharge", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount"))); sysLogs.put("surcharge", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount")));
@ -74,121 +65,41 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
} }
@Override @Override
public void verifySettleLogByDate(String start_date, String end_date, String channel) { public void verifySettleLogByDate(String startDate, String endDate, String channel) {
if (StringUtils.equals("Alipay", channel)) { if (channelSettleVerifys == null) {
try { return;
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();
} }
} Arrays.stream(channelSettleVerifys).filter(verify -> verify.payChannel().getChannelCode().equalsIgnoreCase(channel))
.findFirst().ifPresent(verify -> {
private void generateAlipaySettleLogs() { try {
try { Date currentDate = sdfClear.parse(startDate);
List<Date> dateList = TimeZoneUtils.getStatetime(); Date end = sdfClear.parse(endDate);
for (Date dateStr : dateList) { while (!end.before(currentDate)) {
try { saveVerifyResults(currentDate, verify);
doVerifyAlipaySettleLog(dateStr); currentDate = DateUtils.addDays(currentDate, 1);
} catch (Exception e) { }
logger.error("获取" + dateStr + "Alipay清算记录失败", e); } catch (ParseException e) {
} throw new BadRequestException("Invalid Date Format");
} }
} 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");
}
@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 { private void saveVerifyResults(Date date, ChannelSettleVerify verify) {
if (aliSettleLog != null) { logger.info("starting verify for channel {} on {}", verify.payChannel(), date);
JSONObject settleFee = getAliSettle(aliSettleLog); 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(); JSONObject params = new JSONObject();
params.put("settle_date", dateStr); params.put("settle_date", settle.getSettlementDate());
params.put("start_date", dateStr); params.put("start_date", TimeZoneUtils.formatTime(settle.getStart(), TimeZoneUtils.PATTERN_NORMAL, "Asia/Shanghai"));
params.put("end_date", dateStr); params.put("end_date", TimeZoneUtils.formatTime(settle.getEnd(), TimeZoneUtils.PATTERN_NORMAL, "Asia/Shanghai"));
params.put("pay_fee", settleFee.getBigDecimal("credit")); if (verify.payChannel() == PayChannel.WECHAT) {
params.put("refund_fee", settleFee.getBigDecimal("debit")); params.put("settle_date", TimeZoneUtils.formatTime(settle.getSettlementDate(), TimeZoneUtils.PATTERN_NORMAL, "Asia/Shanghai"));
params.put("net_fee", settleFee.getBigDecimal("net_fee")); }
params.put("surcharge", settleFee.getBigDecimal("surcharge")); params.put("channel", verify.payChannel().getChannelCode());
params.put("settlement_fee", settleFee.getBigDecimal("settlement_fee"));
params.put("channel", channel);
params.put("last_update_date", new Date()); 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()) { if (sysClearData != null && !sysClearData.isEmpty()) {
params.put("sys_pay_fee", sysClearData.getBigDecimal("sys_pay_fee")); params.put("sys_pay_fee", sysClearData.getBigDecimal("sys_pay_fee"));
params.put("sys_refund_fee", sysClearData.getBigDecimal("sys_refund_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_surcharge", sysClearData.getBigDecimal("sys_surcharge"));
params.put("sys_settlement_fee", sysClearData.getBigDecimal("sys_settle_fee")); params.put("sys_settlement_fee", sysClearData.getBigDecimal("sys_settle_fee"));
} }
JSONObject check = platformSettlementMapper.findByDateMerchant(sdfClear.format(dateStr), channel, "All"); params.put("merchants", settle.getMerchantId());
if (check != null) { params.put("pay_fee", settle.getPayFee());
params.put("log_id", check.getString("log_id")); params.put("refund_fee", settle.getRefundFee());
platformSettlementMapper.update(params); params.put("net_fee", settle.getPayNetFee());
} else { if (verify.payChannel() != PayChannel.WECHAT) {
platformSettlementMapper.save(params); params.put("net_fee", settle.getPayFee().subtract(settle.getRefundFee()));
} }
} params.put("settlement_fee", settle.getSettlementFee());
} params.put("surcharge", settle.getPoundageFee());
params.put("unsettle_fee", settle.getUnsettlementFee());
public void doVerifyWechatSettleLog(Map<String, Date> settleDate) {
List<SettlementLog> tencentSettle = new ArrayList<>();
for (WeChatPayConfig.Merchant mch : WechatPayEnvironment.getEnv().getWechatMerchantConfigs()) {
try { try {
tencentSettle = mpPaymentApi.settlementLogs(settleDate.get("from"), settleDate.get("to"), mch.getMerchantId()); if (("1500474722".equals(settle.getMerchantId()) && settle.getSettlementDate().before(DateTime.parse("2018-06-02").toDate())) ||
if (tencentSettle == null) { ("1492874492".equals(settle.getMerchantId()) && settle.getSettlementDate().after(DateTime.parse("2018-06-05").toDate()))) {
logger.info("【{}】下没有清算记录", mch.getMerchantId()); 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 { } else {
for (SettlementLog settle : tencentSettle) { platformSettlementMapper.save(params);
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());
}
} }
params.clear();
} catch (Exception e) { } 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"); @Override
BigDecimal credit = BigDecimal.ZERO; // @Transactional
BigDecimal creditFee = BigDecimal.ZERO; public void generateSettleLogs() {
BigDecimal creditSettle = BigDecimal.ZERO; if (channelSettleVerifys != null) {
if (payments != null) { try {
for (int i = 0; i < payments.size(); i++) { List<Date> dateList = TimeZoneUtils.getStatetime();
JSONObject json = payments.getJSONObject(i); for (Date date : dateList) {
BigDecimal transactionAmount = json.getBigDecimal("transaction_amount"); for (ChannelSettleVerify verify : channelSettleVerifys) {
BigDecimal chargeFee = json.getBigDecimal("charge_fee"); try {
credit = credit.add(transactionAmount); saveVerifyResults(date, verify);
creditFee = creditFee.add(chargeFee); } catch (Exception e) {
if (json.containsKey("settle_amount")) { logger.error("[{}]{} failed to download settle file", date, verify.payChannel(), e);
creditSettle = creditSettle.add(json.getBigDecimal("settle_amount")); }
} else { }
creditSettle = creditSettle.add(transactionAmount.subtract(chargeFee));
} }
} 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 { private JSONObject getSystemClearingAmount(SettlementLog settlementLog, String channel) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 02:00:00");
JSONObject sysLogs = new JSONObject(); JSONObject sysLogs = new JSONObject();
String start_date = null; logger.info("{} System Settle Logs:{}<====>{}", channel, settlementLog.getStart(), settlementLog.getEnd());
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");
}
try { 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")); sysLogs.put("sys_pay_fee", creditLogs.getBigDecimal("aud_amount"));
JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog(settlementLog.getStart(), settlementLog.getEnd(), settlementLog.getMerchantId(), channel, "Debit");
JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog(start_date, end_date, channel, "Debit", wechat_rate);
sysLogs.put("sys_refund_fee", debitLogs.getBigDecimal("aud_amount")); sysLogs.put("sys_refund_fee", debitLogs.getBigDecimal("aud_amount"));
sysLogs.put("sys_net_fee", creditLogs.getBigDecimal("aud_amount").subtract(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", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount")));
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_settle_fee", sysLogs.getBigDecimal("sys_net_fee").subtract(sysLogs.getBigDecimal("sys_surcharge"))); 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; return sysLogs;
} catch (Exception e) { } catch (Exception e) {
// do nothing //do nothing
e.printStackTrace(); logger.error("Error caught on analysising {}", channel, e);
} }
return null; return null;
} }

@ -1,7 +1,7 @@
package au.com.royalpay.payment.manage.dev.web; package au.com.royalpay.payment.manage.dev.web;
import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi; 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.beans.SettlementLog;
import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; import au.com.royalpay.payment.manage.permission.manager.ManagerMapping;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;

@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.fund.core.impls;
import au.com.royalpay.payment.core.SettlementDetailCalculator; import au.com.royalpay.payment.core.SettlementDetailCalculator;
import au.com.royalpay.payment.core.TransactionService; import au.com.royalpay.payment.core.TransactionService;
import au.com.royalpay.payment.core.beans.TransactionBizSubType;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.manage.fund.beans.XPlanFundConfig; import au.com.royalpay.payment.manage.fund.beans.XPlanFundConfig;
import au.com.royalpay.payment.manage.fund.core.XPlanFundConfigService; import au.com.royalpay.payment.manage.fund.core.XPlanFundConfigService;
@ -303,7 +304,7 @@ public class XPlanFundProcessorImpl implements XPlanFundProcesor {
tradeTransaction.put("channel", "System"); tradeTransaction.put("channel", "System");
tradeTransaction.put("system_generate", 1); tradeTransaction.put("system_generate", 1);
tradeTransaction.put("remark", remark); tradeTransaction.put("remark", remark);
transactionService.saveTransaction(tradeTransaction); transactionService.saveTransaction(tradeTransaction, TransactionBizSubType.DEPOSIT);
return tradeTransaction; return tradeTransaction;
} }

@ -32,12 +32,14 @@ public interface PlatformSettlementMapper {
PageList<JSONObject> findSettleLogsAllMerchant(@Param("channel") String channel, PageBounds pageBounds); PageList<JSONObject> findSettleLogsAllMerchant(@Param("channel") String channel, PageBounds pageBounds);
JSONObject calculateSysSettleLog(@Param("start_date") String start_date, @Param("end_date") String end_date, @Param("channel") String channel, @Param("transaction_type") String type, @Param("wechat_rate") BigDecimal wechat_rate); JSONObject calculateSysSettleLog(@Param("start_date") Date startDate, @Param("end_date") Date endDate, @Param("channel") String channel,
@Param("pid") String pid, @Param("transaction_type") String type);
JSONObject calculateSysSettleLog5(@Param("start_date") String start_date, @Param("end_date") String end_date, @Param("channel") String channel, @Param("transaction_type") String type); BigDecimal calculateRmbCharge(@Param("start_date") Date start_date, @Param("end_date") Date end_date, @Param("channel") String channel);
BigDecimal calculateRmbCharge(@Param("start_date") String start_date, @Param("end_date") String end_date, @Param("channel") String channel,@Param("ali_rate") BigDecimal ali_rate);
@AutoSql(SqlType.DELETE) @AutoSql(SqlType.DELETE)
void delete(JSONObject params); void delete(JSONObject params);
JSONObject calculateChannelSysSettleLog(@Param("start_date") Date startDate, @Param("end_date") Date endDate, @Param("channel") String channel,
@Param("transaction_type") String type);
} }

@ -4,6 +4,7 @@ import au.com.royalpay.payment.core.PaymentApi;
import au.com.royalpay.payment.core.TransactionService; import au.com.royalpay.payment.core.TransactionService;
import au.com.royalpay.payment.core.beans.PaymentQueryResult; import au.com.royalpay.payment.core.beans.PaymentQueryResult;
import au.com.royalpay.payment.core.beans.PreOrderRequest; import au.com.royalpay.payment.core.beans.PreOrderRequest;
import au.com.royalpay.payment.core.beans.TransactionBizSubType;
import au.com.royalpay.payment.core.beans.coupon.CouponInfo; import au.com.royalpay.payment.core.beans.coupon.CouponInfo;
import au.com.royalpay.payment.core.events.PaymentFinishedEvent; import au.com.royalpay.payment.core.events.PaymentFinishedEvent;
import au.com.royalpay.payment.core.events.RefundSendEvent; import au.com.royalpay.payment.core.events.RefundSendEvent;
@ -66,6 +67,7 @@ public class CtripCouponProvideProcessor implements PaymentProcessor {
private PmtOrderMapper pmtOrderMapper; private PmtOrderMapper pmtOrderMapper;
@Resource @Resource
private TransactionService transactionService; private TransactionService transactionService;
@Override @Override
public String processorId() { public String processorId() {
return COUPON_ID + "_USE"; return COUPON_ID + "_USE";
@ -102,11 +104,11 @@ public class CtripCouponProvideProcessor implements PaymentProcessor {
return; return;
} }
JSONObject couponAccuessLog = new JSONObject(); JSONObject couponAccuessLog = new JSONObject();
couponAccuessLog.put("client_id",order.getIntValue("client_id")); couponAccuessLog.put("client_id", order.getIntValue("client_id"));
couponAccuessLog.put("customer_openid","创建订单时无"); couponAccuessLog.put("customer_openid", "创建订单时无");
couponAccuessLog.put("creation_date",new Date()); couponAccuessLog.put("creation_date", new Date());
couponAccuessLog.put("order_id",order.getString("order_id")); couponAccuessLog.put("order_id", order.getString("order_id"));
couponAccuessLog.put("coupon_id","CTRIP_"+tmpEle.getString("ctrip_coupon_id")); couponAccuessLog.put("coupon_id", "CTRIP_" + tmpEle.getString("ctrip_coupon_id"));
BigDecimal currentDiscount = paymentInfo.getDiscount(); BigDecimal currentDiscount = paymentInfo.getDiscount();
//携程满减 //携程满减
if (StringUtils.equals(couponInfo.getString("type"), "31")) { if (StringUtils.equals(couponInfo.getString("type"), "31")) {
@ -178,13 +180,13 @@ public class CtripCouponProvideProcessor implements PaymentProcessor {
useCoupontrans.put("clearing_status", 0); useCoupontrans.put("clearing_status", 0);
useCoupontrans.put("system_generate", 1); useCoupontrans.put("system_generate", 1);
useCoupontrans.put("remark", "Ctrip Coupon from Customer:" + couponLogId); useCoupontrans.put("remark", "Ctrip Coupon from Customer:" + couponLogId);
accuessCouponLog = payCouponAccuessLogMapper.findAccuessLogByOrderId(orderId,new PageBounds(Order.formString("last_update_date.desc"))).get(0); accuessCouponLog = payCouponAccuessLogMapper.findAccuessLogByOrderId(orderId, new PageBounds(Order.formString("last_update_date.desc"))).get(0);
if (accuessCouponLog != null) { if (accuessCouponLog != null) {
transactionService.saveTransaction(useCoupontrans); transactionService.saveTransaction(useCoupontrans, TransactionBizSubType.COUPON_PAY);
accuessCouponLog.put("is_valid", 1); accuessCouponLog.put("is_valid", 1);
accuessCouponLog.put("last_update_date", new Date()); accuessCouponLog.put("last_update_date", new Date());
accuessCouponLog.put("transaction_id", useCoupontrans.getString("transaction_id")); accuessCouponLog.put("transaction_id", useCoupontrans.getString("transaction_id"));
accuessCouponLog.put("customer_openid",order.getString("customer_id")); accuessCouponLog.put("customer_openid", order.getString("customer_id"));
payCouponAccuessLogMapper.update(accuessCouponLog); payCouponAccuessLogMapper.update(accuessCouponLog);
} }
@ -221,7 +223,7 @@ public class CtripCouponProvideProcessor implements PaymentProcessor {
trans.put("transaction_time", new Date()); trans.put("transaction_time", new Date());
trans.put("remark", "Refund for Customer Ctrip Coupon:" + coupon_id); trans.put("remark", "Refund for Customer Ctrip Coupon:" + coupon_id);
logger.info("正在退款的券的信息" + trans.toJSONString()); logger.info("正在退款的券的信息" + trans.toJSONString());
transactionService.saveTransaction(trans); transactionService.saveTransaction(trans, TransactionBizSubType.COUPON_REFUND);
logger.error("订单[" + orderId + "]发送全额退款,携程优惠券【" + coupon_id + "】转为Debit"); logger.error("订单[" + orderId + "]发送全额退款,携程优惠券【" + coupon_id + "】转为Debit");
accuessCouponLog.put("transaction_refund_id", trans.getString("transaction_id")); accuessCouponLog.put("transaction_refund_id", trans.getString("transaction_id"));
accuessCouponLog.put("refund_id", refundOrder.getString("refund_id")); accuessCouponLog.put("refund_id", refundOrder.getString("refund_id"));
@ -238,7 +240,7 @@ public class CtripCouponProvideProcessor implements PaymentProcessor {
} }
// 使用券的信息 // 使用券的信息
private JSONObject getPreOrderCoupon(String couponLogId,int clientId) { private JSONObject getPreOrderCoupon(String couponLogId, int clientId) {
JSONObject client = merchantInfoProvider.getClientInfo(clientId); JSONObject client = merchantInfoProvider.getClientInfo(clientId);
String timestamp = System.currentTimeMillis() + ""; String timestamp = System.currentTimeMillis() + "";
String base = CUSTOMER_APP_ID + timestamp + CUSTOMER_AUTH_CODE; String base = CUSTOMER_APP_ID + timestamp + CUSTOMER_AUTH_CODE;

@ -1,6 +1,7 @@
package au.com.royalpay.payment.manage.rservices.core.impl; package au.com.royalpay.payment.manage.rservices.core.impl;
import au.com.royalpay.payment.core.TransactionService; import au.com.royalpay.payment.core.TransactionService;
import au.com.royalpay.payment.core.beans.TransactionBizSubType;
import au.com.royalpay.payment.core.mappers.PmtOrderMapper; import au.com.royalpay.payment.core.mappers.PmtOrderMapper;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService; import au.com.royalpay.payment.manage.appclient.core.RetailAppService;
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper; import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
@ -166,7 +167,7 @@ public class RServicesApplyServiceImpl implements RServicesApplyService {
transaction.put("clearing_status", 0); transaction.put("clearing_status", 0);
transaction.put("remark", applyInfo.getString("service_code") + ":" + applyInfo.getString("title")); transaction.put("remark", applyInfo.getString("service_code") + ":" + applyInfo.getString("title"));
transaction.put("system_generate", 1); transaction.put("system_generate", 1);
transactionService.saveTransaction(transaction); transactionService.saveTransaction(transaction, TransactionBizSubType.OTHER);
JSONObject order = new JSONObject(); JSONObject order = new JSONObject();
order.put("order_id", orderId); order.put("order_id", orderId);
order.put("org_id", client.getIntValue("org_id")); order.put("org_id", client.getIntValue("org_id"));

@ -40,8 +40,4 @@ public class SettleEstimateTaskManger {
synchronizedScheduler.executeProcess("manage_task:genSettleLog", 120_000, () -> platformClearService.generateSettleLogs()); synchronizedScheduler.executeProcess("manage_task:genSettleLog", 120_000, () -> platformClearService.generateSettleLogs());
} }
@Scheduled(cron = "0 0 10 * * ?")
public void generateSettleLogs2() {
synchronizedScheduler.executeProcess("manage_task:generateAliPaySettleLog", 120_000, () -> platformClearService.generateAliPaySettleLogs());
}
} }

@ -3,9 +3,9 @@ package au.com.royalpay.payment.manage.tradelog.core.impls;
import au.com.royalpay.payment.channels.wechat.config.WeChatPayConfig; 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.config.WechatPayEnvironment;
import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi; 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.PaymentApi; import au.com.royalpay.payment.core.PaymentApi;
import au.com.royalpay.payment.core.TransactionService; import au.com.royalpay.payment.core.TransactionService;
import au.com.royalpay.payment.core.beans.SettlementLog;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.core.exceptions.OrderNotMatchException; import au.com.royalpay.payment.core.exceptions.OrderNotMatchException;
import au.com.royalpay.payment.core.exceptions.ParamInvalidException; import au.com.royalpay.payment.core.exceptions.ParamInvalidException;

@ -11,18 +11,17 @@
</select> </select>
<select id="calculateSysSettleLog" resultType="com.alibaba.fastjson.JSONObject"> <select id="calculateSysSettleLog" resultType="com.alibaba.fastjson.JSONObject">
SELECT SELECT sum(t.cny_amount) rmb_amount,
sum(cny_amount) rmb_amount, ifnull(sum(t.clearing_amount), 0.00) aud_amount,
ifnull(sum(clearing_amount),0.00) aud_amount, ifnull(sum(t.channel_surcharge), 0.00) charge_amount
ifnull(sum(ROUND(clearing_amount * #{wechat_rate},2)),0.00) charge_amount FROM pmt_transactions t
FROM inner join pmt_orders o on o.order_id = t.order_id
pmt_transactions WHERE o.merchant_id = #{pid}
WHERE and order_channel = #{channel}
order_channel = #{channel} AND transaction_type = #{transaction_type}
AND transaction_type = #{transaction_type} AND transaction_time >= #{start_date}
AND transaction_time >= #{start_date} AND #{end_date} > transaction_time
AND #{end_date} > transaction_time and system_generate = 0
and system_generate =0
</select> </select>
<select id="calculateRmbCharge" resultType="decimal"> <select id="calculateRmbCharge" resultType="decimal">
@ -38,20 +37,16 @@
AND #{end_date} > transaction_time AND #{end_date} > transaction_time
AND system_generate = 0 AND system_generate = 0
</select> </select>
<select id="calculateChannelSysSettleLog" resultType="com.alibaba.fastjson.JSONObject">
<select id="calculateSysSettleLog5" resultType="com.alibaba.fastjson.JSONObject"> SELECT sum(t.cny_amount) rmb_amount,
SELECT ifnull(sum(t.clearing_amount), 0.00) aud_amount,
ifnull(sum(cny_amount),0.00) rmb_amount, ifnull(sum(t.channel_surcharge), 0.00) charge_amount
ifnull(sum(clearing_amount),0.00) aud_amount, FROM pmt_transactions t
ifnull(sum(ROUND(cny_amount * 0.005,2)),0.00) charge_amount WHERE order_channel = #{channel}
FROM AND transaction_type = #{transaction_type}
pmt_transactions AND transaction_time >= #{start_date}
WHERE AND #{end_date} > transaction_time
order_channel = #{channel} and system_generate = 0
AND transaction_type = #{transaction_type}
AND transaction_time >= #{start_date}
AND #{end_date} > transaction_time
and system_generate =0
</select> </select>
</mapper> </mapper>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Loading…
Cancel
Save