开合伙人子账号要验证手机号

This commit is contained in:
2026-07-12 17:53:54 +08:00
parent 908a5dcf0f
commit 3b4833b51a
7 changed files with 176 additions and 3 deletions
@@ -1,11 +1,21 @@
import { IsArray, IsIn, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { AccountStatus, PartnerStaffRole } from '@dukang/shared-types';
export class SendPartnerStaffPhoneSmsDto {
@IsString()
@IsNotEmpty()
phone: string;
}
export class CreatePartnerStaffDto {
@IsString()
@IsNotEmpty()
phone: string;
@IsString()
@IsNotEmpty()
smsCode: string;
@IsString()
@IsNotEmpty()
name: string;
@@ -3,7 +3,11 @@ import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard';
import { PartnerPrimaryGuard } from '../../common/guards/partner-primary.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { PartnerStaffService } from './partner-staff.service';
import { CreatePartnerStaffDto, UpdatePartnerStaffDto } from './dto/partner-staff.dto';
import {
CreatePartnerStaffDto,
SendPartnerStaffPhoneSmsDto,
UpdatePartnerStaffDto,
} from './dto/partner-staff.dto';
@Controller('partner/staff')
@UseGuards(JwtAuthGuard, PartnerPrimaryGuard)
@@ -15,6 +19,11 @@ export class PartnerStaffController {
return this.staffService.listStaff(user.actorId);
}
@Post('send-phone-sms')
sendPhoneSms(@CurrentUser() user: AuthUser, @Body() dto: SendPartnerStaffPhoneSmsDto) {
return this.staffService.sendStaffPhoneSms(user, dto.phone);
}
@Post()
create(@CurrentUser() user: AuthUser, @Body() dto: CreatePartnerStaffDto) {
return this.staffService.createStaff(user, dto);
@@ -3,11 +3,12 @@ import {
BadRequestException,
Injectable,
NotFoundException,
} from '@nestjs/common';
import { ClientApp, PartnerStaffRole, SmsScene } from '@dukang/shared-types';
import { PrismaService } from '../../common/prisma/prisma.module';
@@ -15,6 +16,7 @@ export class PartnerStaffService {
import type { AuthUser } from '../../common/guards/jwt-auth.guard';
import { AnalyticsService } from '../analytics/analytics.service';
import { AuthService } from './auth.service';
@@ -25,6 +27,48 @@ export class PartnerStaffService {
@Injectable()
export class PartnerStaffService {
constructor(
private readonly prisma: PrismaService,
private readonly analytics: AnalyticsService,
private readonly authService: AuthService,
) {}
async listStaff(parentAccountId: bigint) {
const rows = await this.prisma.partnerAccount.findMany({
where: { parentAccountId },
orderBy: { createdAt: 'desc' },
});
return rows.map((row) => this.toStaffItem(row));
}
async sendStaffPhoneSms(actor: AuthUser, phone: string) {
const parentAccountId = actor.actorId;
const parent = await this.prisma.partnerAccount.findUniqueOrThrow({
where: { id: parentAccountId },
});
if (parent.isPrimary !== 1) {
throw new BadRequestException('仅主账号可添加子账号');
}
@@ -42,6 +86,18 @@ export class PartnerStaffService {
const existing = await this.prisma.partnerAccount.findUnique({ where: { phone: normalized } });
if (existing) throw new BadRequestException('该手机号已被使用');
const masked = this.maskPhone(normalized);
try {
await this.authService.sendSms(normalized, SmsScene.PARTNER_STAFF_ADD, {
clientApp: ClientApp.PARTNER_H5,
});
this.trackStaffEvent(actor, parent.id, 'partner_staff_sms_send', parent.id, {
@@ -64,6 +120,7 @@ export class PartnerStaffService {
scene: SmsScene.PARTNER_STAFF_ADD,
status: 'failed',
reason: err.message,
@@ -180,3 +237,4 @@ export class PartnerStaffService {
name,
phone: this.maskPhone(phone),