diff --git a/backend/services/wallet-service/src/application/event-handlers/withdrawal-status.handler.ts b/backend/services/wallet-service/src/application/event-handlers/withdrawal-status.handler.ts index b8fb3a98..10622bbc 100644 --- a/backend/services/wallet-service/src/application/event-handlers/withdrawal-status.handler.ts +++ b/backend/services/wallet-service/src/application/event-handlers/withdrawal-status.handler.ts @@ -103,12 +103,19 @@ export class WithdrawalStatusHandler implements OnModuleInit { // Refund frozen funds back to available balance if needed if (order.needsUnfreeze()) { - const wallet = await this.walletRepo.findByUserId(order.userId.value); + // 优先使用 accountSequence 查找钱包(更可靠,避免 userId 变化导致扣错人) + let wallet = await this.walletRepo.findByAccountSequence(order.accountSequence); + if (!wallet) { + // 兜底:使用 userId 查找 + wallet = await this.walletRepo.findByUserId(order.userId.value); + } if (wallet) { // Unfreeze the amount (add back to available balance) wallet.unfreeze(order.amount); await this.walletRepo.save(wallet); - this.logger.log(`[FAILED] Refunded ${order.amount.value} USDT to user ${order.userId}`); + this.logger.log(`[FAILED] Refunded ${order.amount.value} USDT to account ${order.accountSequence}`); + } else { + this.logger.error(`[FAILED] Wallet not found for accountSequence: ${order.accountSequence}, userId: ${order.userId}`); } }