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

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
@@ -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),