From f0c7cee94e49565e4bc177a43770c71690761295 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 30 Jan 2026 11:41:58 -0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20lookupByPhone=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9C=AA=E8=BF=81=E7=A7=BB=E7=9A=84=201.0=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit P2P 转账验证手机号时,lookupByPhone 只查 users 表(V2 注册用户), 导致未登录过 2.0 的 1.0 老用户(CDC 同步在 synced_legacy_users 表) 被报"不存在"。修改为先查 users 表,未找到再查 synced_legacy_users。 Co-Authored-By: Claude Opus 4.5 --- .../src/application/services/user.service.ts | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/backend/services/auth-service/src/application/services/user.service.ts b/backend/services/auth-service/src/application/services/user.service.ts index 2929708b..48286d74 100644 --- a/backend/services/auth-service/src/application/services/user.service.ts +++ b/backend/services/auth-service/src/application/services/user.service.ts @@ -4,6 +4,8 @@ import { Phone, USER_REPOSITORY, UserRepository, + SYNCED_LEGACY_USER_REPOSITORY, + SyncedLegacyUserRepository, } from '@/domain'; export interface UserProfileResult { @@ -22,6 +24,8 @@ export class UserService { constructor( @Inject(USER_REPOSITORY) private readonly userRepository: UserRepository, + @Inject(SYNCED_LEGACY_USER_REPOSITORY) + private readonly syncedLegacyUserRepository: SyncedLegacyUserRepository, ) {} /** @@ -50,20 +54,32 @@ export class UserService { /** * 根据手机号查找用户(用于P2P转账验证) + * 先查 V2 users 表,未找到再查 synced_legacy_users 表 */ async lookupByPhone(phone: string): Promise<{ exists: boolean; accountSequence?: string; nickname?: string }> { const phoneVO = Phone.create(phone); - const user = await this.userRepository.findByPhone(phoneVO); - if (!user || user.status !== 'ACTIVE') { - return { exists: false }; + // 1. 先查 V2 用户表 + const user = await this.userRepository.findByPhone(phoneVO); + if (user && user.status === 'ACTIVE') { + return { + exists: true, + accountSequence: user.accountSequence.value, + nickname: user.isKycVerified ? this.maskName(user.realName!) : user.phone.masked, + }; } - return { - exists: true, - accountSequence: user.accountSequence.value, - nickname: user.isKycVerified ? this.maskName(user.realName!) : user.phone.masked, - }; + // 2. 查 1.0 同步用户表(未迁移的老用户) + const legacyUser = await this.syncedLegacyUserRepository.findByPhone(phoneVO); + if (legacyUser && legacyUser.status === 'ACTIVE' && !legacyUser.migratedToV2) { + return { + exists: true, + accountSequence: legacyUser.accountSequence.value, + nickname: legacyUser.nickname || legacyUser.phone.masked, + }; + } + + return { exists: false }; } /**