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