mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
交易撤销重构
This commit is contained in:
@@ -33,4 +33,6 @@ public interface MemberAdapayRecordService{
|
||||
void updateSpendAmount(String paymentId, BigDecimal amount);
|
||||
|
||||
void updateRefundAmount(String paymentId, BigDecimal amount);
|
||||
|
||||
void updateSpendAmountAndRefundAmount(String paymentId, BigDecimal SpendAmount, BigDecimal RefundAmount);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,8 @@ public class MemberAdapayRecordServiceImpl implements MemberAdapayRecordService
|
||||
* @param SpendAmount 消费金额
|
||||
* @param RefundAmount 退款金额
|
||||
*/
|
||||
private void updateSpendAmountAndRefundAmount(String paymentId, BigDecimal SpendAmount, BigDecimal RefundAmount) {
|
||||
@Override
|
||||
public void updateSpendAmountAndRefundAmount(String paymentId, BigDecimal SpendAmount, BigDecimal RefundAmount) {
|
||||
MemberAdapayRecord record = selectByPaymentId(paymentId);
|
||||
if (record == null) {
|
||||
log.info("更新交易记录的消费金额和退款金额paymentId:{}, 查询为空", paymentId);
|
||||
@@ -124,6 +125,11 @@ public class MemberAdapayRecordServiceImpl implements MemberAdapayRecordService
|
||||
// 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额
|
||||
record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
|
||||
updateByPrimaryKeySelective(record);
|
||||
|
||||
// if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
// log.error("订单分账结束后账不平,paymentId:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
// paymentId, record.getPayAmt(), SpendAmount, RefundAmount);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2386,40 +2386,44 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(operation);
|
||||
|
||||
if (response != null && response.isNotFailed()) {
|
||||
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
BigDecimal reverseAmt = new BigDecimal(response.getReverse_amt());
|
||||
// 更新此笔交易单的消费金额 = 支付金额 - 撤销金额
|
||||
BigDecimal spendAmt = callbackRecord.getPayAmt().subtract(reverseAmt);
|
||||
record.setSpendAmt(spendAmt);
|
||||
// 退款金额
|
||||
record.setRefundAmt(reverseAmt);
|
||||
// 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额
|
||||
record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
|
||||
if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
logger.error("订单分账结束后账不平,paymentId:{}, orderCode:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
paymentId, dto.getOrderCode(), payAmt, spendAmt, reverseAmt);
|
||||
}
|
||||
memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
// MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
// // 更新此笔交易单的消费金额 = 支付金额 - 撤销金额
|
||||
// record.setSpendAmt(spendAmt);
|
||||
// // 退款金额
|
||||
// record.setRefundAmt(reverseAmt);
|
||||
// // 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额
|
||||
// record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
|
||||
// memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
|
||||
memberAdapayRecordService.updateSpendAmountAndRefundAmount(paymentId, spendAmt, reverseAmt);
|
||||
// if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
// logger.error("订单分账结束后账不平,paymentId:{}, orderCode:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
// paymentId, dto.getOrderCode(), payAmt, spendAmt, reverseAmt);
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
// 实时分账的调退款接口
|
||||
RefundResponse refundRequest = adapayService.createRefundRequest(paymentId, refundAmount, dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(),
|
||||
dto.getOrderCode());
|
||||
RefundResponse refundRequest = adapayService.createRefundRequest(paymentId, refundAmount,
|
||||
dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(), dto.getOrderCode());
|
||||
if (refundRequest != null && refundRequest.isNotFailed()) {
|
||||
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
BigDecimal refundAmt = new BigDecimal(refundRequest.getRefund_amt());
|
||||
// 更新此笔交易单的消费金额 = 支付金额 - 撤销金额
|
||||
BigDecimal spendAmt = callbackRecord.getPayAmt().subtract(refundAmt);
|
||||
record.setSpendAmt(spendAmt);
|
||||
// 退款金额
|
||||
record.setRefundAmt(refundAmt);
|
||||
// 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额
|
||||
record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
|
||||
if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
logger.error("订单分账结束后账不平,paymentId:{}, orderCode:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
paymentId, dto.getOrderCode(), payAmt, spendAmt, refundAmt);
|
||||
}
|
||||
memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
// MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
// record.setSpendAmt(spendAmt);
|
||||
// // 退款金额
|
||||
// record.setRefundAmt(refundAmt);
|
||||
// // 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额
|
||||
// record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
|
||||
// if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
// logger.error("订单分账结束后账不平,paymentId:{}, orderCode:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
// paymentId, dto.getOrderCode(), payAmt, spendAmt, refundAmt);
|
||||
// }
|
||||
// memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
|
||||
memberAdapayRecordService.updateSpendAmountAndRefundAmount(paymentId, spendAmt, refundAmt);
|
||||
}
|
||||
}
|
||||
// if (StringUtils.equals("", payMode)) {
|
||||
|
||||
Reference in New Issue
Block a user