优化支付订单成功逻辑
This commit is contained in:
1 parent
cef85b81ef
commit
d7bcbb4e1e
4 files changed
+134
-7
No files matched your search
+25
-2
@@ -16,6 +16,8 @@ import com.ruoyi.system.mapper.UsdtConfigMapper;
|
||||
import com.ruoyi.system.mapper.WalletAddressLedgerMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
@@ -36,6 +38,7 @@ public class WalletLedgerPostingService {
|
||||
private final AppsMapper appsMapper;
|
||||
private final AppsBalanceLedgerMapper appsLedgerMapper;
|
||||
private final UsdtConfigMapper configMapper;
|
||||
private final PaymentOrderOpenApiService paymentOrderOpenApiService;
|
||||
|
||||
public WalletLedgerPostingService(UsdtOrdersMapper ordersMapper,
|
||||
WalletAddressLedgerMapper ledgerMapper,
|
||||
@@ -43,7 +46,8 @@ public class WalletLedgerPostingService {
|
||||
IUsdtAggregationTaskItemService aggregationItemService,
|
||||
AppsMapper appsMapper,
|
||||
AppsBalanceLedgerMapper appsLedgerMapper,
|
||||
UsdtConfigMapper configMapper) {
|
||||
UsdtConfigMapper configMapper,
|
||||
PaymentOrderOpenApiService paymentOrderOpenApiService) {
|
||||
this.ordersMapper = ordersMapper;
|
||||
this.ledgerMapper = ledgerMapper;
|
||||
this.walletService = walletService;
|
||||
@@ -51,6 +55,7 @@ public class WalletLedgerPostingService {
|
||||
this.appsMapper = appsMapper;
|
||||
this.appsLedgerMapper = appsLedgerMapper;
|
||||
this.configMapper = configMapper;
|
||||
this.paymentOrderOpenApiService = paymentOrderOpenApiService;
|
||||
}
|
||||
|
||||
/** 将待支付订单结算为成功,同一订单重复扫描不会重复产生流水。 */
|
||||
@@ -92,7 +97,25 @@ public class WalletLedgerPostingService {
|
||||
ledgerMapper.insertSystemLedgerIgnoreDuplicate(ledger);
|
||||
|
||||
postOrderToAppBalance(order, transactionId, now);
|
||||
return ordersMapper.markOrderPaid(order.getId(), transactionId, now) == 1;
|
||||
if (ordersMapper.markOrderPaid(order.getId(), transactionId, now) != 1) {
|
||||
return false;
|
||||
}
|
||||
releasePaymentSlotAfterCommit(order);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 数据库确认支付事务提交后再释放 Redis 槽位,避免回滚时提前开放相同地址和金额。 */
|
||||
private void releasePaymentSlotAfterCommit(final UsdtOrdersPlus order) {
|
||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
paymentOrderOpenApiService.releasePaidOrderSlot(order);
|
||||
return;
|
||||
}
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
paymentOrderOpenApiService.releasePaidOrderSlot(order);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user