记录退款金额到订单支付记录

This commit is contained in:
2024-01-17 16:35:03 +08:00
parent 5a35135500
commit 8f7e3eaa94
8 changed files with 61 additions and 42 deletions

View File

@@ -1,7 +1,5 @@
package com.jsowell.pile.service.programlogic;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -489,7 +487,7 @@ public abstract class AbstractProgramLogic implements InitializingBean {
BigDecimal tempAmount = new BigDecimal(orderAmount.toString()); // 临时金额
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfos = parseDeductionRecord(record.getDeductionRecord());
List<PaymentInfo> paymentInfos = orderPayRecordService.parseDeductionRecord(record.getDeductionRecord());
for (PaymentInfo object : paymentInfos) {
String paymentId = object.getPaymentId();
BigDecimal payAmount = new BigDecimal(object.getAmount()); // 此交易单支付的金额
@@ -517,29 +515,6 @@ public abstract class AbstractProgramLogic implements InitializingBean {
return resultList;
}
/**
* 解析deductionRecord
* 【公共方法】
*/
public List<PaymentInfo> parseDeductionRecord(String deductionRecord) {
List<PaymentInfo> resultList = Lists.newArrayList();
if (StringUtils.isBlank(deductionRecord)) {
return resultList;
}
Object object = JSON.parse(deductionRecord);
// 都放入list里
String s = JSON.toJSONString(object);
if (object instanceof JSONArray) {
List<PaymentInfo> paymentInfos = JSON.parseArray(s, PaymentInfo.class);
resultList.addAll(paymentInfos);
} else {
PaymentInfo paymentInfo = JSON.parseObject(s, PaymentInfo.class);
resultList.add(paymentInfo);
}
return resultList;
}
/**
* 从redis中取出实时记录保存到表中j
* 当订单完成的时候调用

View File

@@ -173,7 +173,7 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
// 把消费金额冻结
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
List<PaymentInfo> paymentInfoList = orderPayRecordService.parseDeductionRecord(record.getDeductionRecord());
// 循环冻结金额
for (PaymentInfo paymentInfo : paymentInfoList) {
String paymentId = paymentInfo.getPaymentId();
@@ -677,20 +677,15 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
// BigDecimal refundAmt = null; // 交易退款金额
// 延迟分账未确认调撤销调撤销接口退款
// PaymentReverseOperation operation = new PaymentReverseOperation();
// operation.setPaymentId(paymentId);
// operation.setReverseAmt(refundAmount);
// operation.setMerchantKey(dto.getWechatAppId());
// operation.setMemberId(dto.getMemberId());
// operation.setScenarioType(ScenarioEnum.ORDER.getValue());
// operation.setOrderCode(dto.getOrderCode());
// PaymentReverseResponse response = adapayService.createPaymentReverseRequest(operation);
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(paymentId, refundAmount,
dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(), dto.getOrderCode());
if (response != null && response.isNotFailed()) {
// 交易退款金额
BigDecimal refundAmt = new BigDecimal(response.getReverse_amt());
memberAdapayRecordService.updateRefundAmountFromFreezeAmount(paymentId, refundAmt);
// 更新订单支付记录的退款金额
orderPayRecordService.updateRefundAmount(dto.getOrderCode(), paymentId, refundAmt);
}
}
}

View File

@@ -284,7 +284,7 @@ public class NotDelayMerchantProgramLogic extends AbstractProgramLogic {
// 把消费金额冻结
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
List<PaymentInfo> paymentInfoList = orderPayRecordService.parseDeductionRecord(record.getDeductionRecord());
// 循环冻结金额
for (PaymentInfo paymentInfo : paymentInfoList) {
String paymentId = paymentInfo.getPaymentId();