fix: 推荐码必填 + referral-service种子用户userId修复
1. register-by-phone.dto.ts: inviterReferralCode 改为必填 2. user-application.service.ts: 添加日志和推荐码验证 3. referral-service/seed.ts: userId改为25129999999(与accountSequence一致) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4e52b53657
commit
74c78440f7
|
|
@ -54,12 +54,12 @@ export class RegisterByPhoneDto {
|
|||
@IsObject()
|
||||
deviceName?: DeviceNameDto;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
example: 'RWAABC1234',
|
||||
description: '邀请人推荐码 (6-20位大写字母和数字)',
|
||||
@ApiProperty({
|
||||
example: 'SEED01',
|
||||
description: '邀请人推荐码 (6-20位大写字母和数字) - 必填',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@IsNotEmpty({ message: '推荐码不能为空' })
|
||||
@Matches(/^[A-Z0-9]{6,20}$/, { message: '推荐码格式错误' })
|
||||
inviterReferralCode?: string;
|
||||
inviterReferralCode: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,26 +248,31 @@ export class UserApplicationService {
|
|||
}
|
||||
this.logger.log(`[REGISTER] Phone number validated`);
|
||||
|
||||
// 3. 验证邀请码
|
||||
let inviterSequence: AccountSequence | null = null;
|
||||
if (command.inviterReferralCode) {
|
||||
const referralCode = ReferralCode.create(command.inviterReferralCode);
|
||||
const referralValidation =
|
||||
await this.validatorService.validateReferralCode(referralCode);
|
||||
if (!referralValidation.isValid) {
|
||||
this.logger.warn(
|
||||
`[REGISTER] Referral code invalid: ${command.inviterReferralCode}`,
|
||||
);
|
||||
throw new ApplicationError(referralValidation.errorMessage!);
|
||||
}
|
||||
const inviter =
|
||||
await this.userRepository.findByReferralCode(referralCode);
|
||||
inviterSequence = inviter!.accountSequence;
|
||||
this.logger.log(
|
||||
`[REGISTER] Inviter validated: ${inviterSequence.value}`,
|
||||
);
|
||||
// 3. 验证邀请码 (必填)
|
||||
if (!command.inviterReferralCode) {
|
||||
this.logger.warn(`[REGISTER] Missing required referral code`);
|
||||
throw new ApplicationError('推荐码不能为空');
|
||||
}
|
||||
|
||||
const referralCode = ReferralCode.create(command.inviterReferralCode);
|
||||
const referralValidation =
|
||||
await this.validatorService.validateReferralCode(referralCode);
|
||||
if (!referralValidation.isValid) {
|
||||
this.logger.warn(
|
||||
`[REGISTER] Referral code invalid: ${command.inviterReferralCode}`,
|
||||
);
|
||||
throw new ApplicationError(referralValidation.errorMessage!);
|
||||
}
|
||||
const inviter = await this.userRepository.findByReferralCode(referralCode);
|
||||
if (!inviter) {
|
||||
this.logger.warn(
|
||||
`[REGISTER] Inviter not found for code: ${command.inviterReferralCode}`,
|
||||
);
|
||||
throw new ApplicationError('推荐码对应的用户不存在');
|
||||
}
|
||||
const inviterSequence = inviter.accountSequence;
|
||||
this.logger.log(`[REGISTER] Inviter validated: ${inviterSequence.value}`);
|
||||
|
||||
// 4. 生成用户序列号
|
||||
const accountSequence =
|
||||
await this.sequenceGenerator.generateNextUserSequence();
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ const prisma = new PrismaClient();
|
|||
// 用于为未来的注册用户提供初始推荐码
|
||||
// ============================================
|
||||
const SEED_USER = {
|
||||
userId: BigInt(5),
|
||||
accountSequence: 'D25122100000', // 种子用户 (序号0,真实用户从1开始)
|
||||
userId: BigInt(25129999999), // 从 accountSequence 去掉 D 前缀
|
||||
accountSequence: 'D25129999999', // 种子用户 (特殊序号,区别于真实用户)
|
||||
myReferralCode: 'SEED01',
|
||||
usedReferralCode: null, // 根节点无推荐人
|
||||
referrerId: null, // 根节点
|
||||
|
|
|
|||
Loading…
Reference in New Issue