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