fix(wallet): 提现失败解冻时优先使用 accountSequence 查找钱包
问题背景: - 原实现使用 userId 查找钱包进行解冻操作 - userId 来自外部 identity-service,存在变化风险 - 如果 userId 发生变化,可能导致解冻到错误的钱包 解决方案: - 优先使用 accountSequence 查找钱包(wallet-service 内部主键,稳定可靠) - 保留 userId 作为兜底查找方式,确保向后兼容 - 增加钱包找不到时的详细错误日志 改动点: - withdrawal-status.handler.ts: handleWithdrawalFailed() 方法 - 与认种(planting)的钱包查找逻辑保持一致 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
80b74e9877
commit
28c44d7219
|
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue