fix(wallet-service): 修复 allocateToUserWallet 使用 accountSequence 查找钱包

- targetId 现在是 accountSequence (如 D2512120001),不再是 userId
- 移除无效的 BigInt(targetId) 转换
- 从 wallet 对象获取 userId 用于流水记录和缓存失效

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-12 19:15:47 -08:00
parent 518667e88e
commit 96f031da35
1 changed files with 5 additions and 10 deletions

View File

@ -612,15 +612,10 @@ export class WalletApplicationService {
allocation: FundAllocationItem, allocation: FundAllocationItem,
orderId: string, orderId: string,
): Promise<void> { ): Promise<void> {
const userId = BigInt(allocation.targetId); // targetId 是 accountSequence (如 D2512120001),优先用它查找钱包
const wallet = await this.walletRepo.findByAccountSequence(allocation.targetId);
// 优先按 accountSequence 查找,如果未找到则按 userId 查找
let wallet = await this.walletRepo.findByAccountSequence(allocation.targetId);
if (!wallet) { if (!wallet) {
wallet = await this.walletRepo.findByUserId(userId); this.logger.warn(`Wallet not found for accountSequence ${allocation.targetId}, skipping allocation`);
}
if (!wallet) {
this.logger.warn(`Wallet not found for user/accountSequence ${allocation.targetId}, skipping allocation`);
return; return;
} }
@ -640,7 +635,7 @@ export class WalletApplicationService {
// 记录流水 // 记录流水
const ledgerEntry = LedgerEntry.create({ const ledgerEntry = LedgerEntry.create({
accountSequence: wallet.accountSequence, accountSequence: wallet.accountSequence,
userId: UserId.create(userId), userId: wallet.userId, // 从钱包获取 userId
entryType: LedgerEntryType.REWARD_PENDING, entryType: LedgerEntryType.REWARD_PENDING,
amount, amount,
refOrderId: orderId, refOrderId: orderId,
@ -653,7 +648,7 @@ export class WalletApplicationService {
}); });
await this.ledgerRepo.save(ledgerEntry); await this.ledgerRepo.save(ledgerEntry);
await this.walletCacheService.invalidateWallet(userId); await this.walletCacheService.invalidateWallet(wallet.userId.value);
this.logger.debug( this.logger.debug(
`Allocated ${allocation.amount} USDT to user ${allocation.targetId} for ${allocation.allocationType}`, `Allocated ${allocation.amount} USDT to user ${allocation.targetId} for ${allocation.allocationType}`,