fix(auth): lookupByPhone 支持查询未迁移的 1.0 用户

P2P 转账验证手机号时,lookupByPhone 只查 users 表(V2 注册用户),
导致未登录过 2.0 的 1.0 老用户(CDC 同步在 synced_legacy_users 表)
被报"不存在"。修改为先查 users 表,未找到再查 synced_legacy_users。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-30 11:41:58 -08:00
parent 187b82e9ac
commit f0c7cee94e
1 changed files with 24 additions and 8 deletions

View File

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