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 }; } /**