开店需要验证手机号
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { loadAppConfig } from '@dukang/shared-types';
|
||||
import { loadAppConfig, ClientApp, SmsScene } from '@dukang/shared-types';
|
||||
import { PARTNER_STAFF_ROLE_LABELS, PartnerStaffRole, type PartnerLeaderboardPeriod } from '@dukang/shared-types';
|
||||
import { PrismaService } from '../../common/prisma/prisma.module';
|
||||
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
|
||||
@@ -12,6 +12,7 @@ import { mapStoreCompat } from '../../common/compat/v31-compat';
|
||||
import { parseBigIntParam } from '../../common/parse-bigint';
|
||||
import { AnalyticsService } from '../analytics/analytics.service';
|
||||
import { PartnerCityService } from '../city-scope/partner-city.service';
|
||||
import { AuthService } from '../iam/auth.service';
|
||||
|
||||
@Injectable()
|
||||
export class StoreService {
|
||||
@@ -21,6 +22,7 @@ export class StoreService {
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly analyticsService: AnalyticsService,
|
||||
private readonly partnerCityService: PartnerCityService,
|
||||
private readonly authService: AuthService,
|
||||
) {}
|
||||
|
||||
async listOpenStores(cityCode?: string) {
|
||||
@@ -139,9 +141,29 @@ export class StoreService {
|
||||
};
|
||||
}
|
||||
|
||||
async sendPartnerStorePhoneSms(phone: string) {
|
||||
const check = await this.partnerCheckStorePhone(phone);
|
||||
if (!check.available) {
|
||||
throw new BadRequestException(check.message ?? '该手机号不可用于门店账号');
|
||||
}
|
||||
return this.authService.sendSms(phone.trim(), SmsScene.PARTNER_STORE_OPEN, {
|
||||
clientApp: ClientApp.PARTNER_H5,
|
||||
}).then(() => {
|
||||
const normalizedPhone = phone.trim();
|
||||
const masked =
|
||||
normalizedPhone.length >= 7
|
||||
? `${normalizedPhone.slice(0, 3)}****${normalizedPhone.slice(-4)}`
|
||||
: normalizedPhone;
|
||||
return { ok: true, maskedPhone: masked };
|
||||
});
|
||||
}
|
||||
|
||||
async createStore(partnerAccountId: bigint, body: Record<string, unknown>) {
|
||||
const { primaryId } = await this.resolvePartnerScope(partnerAccountId);
|
||||
const normalizedPhone = String(body.phone).trim();
|
||||
const smsCode = body.smsCode ? String(body.smsCode).trim() : '';
|
||||
if (!smsCode) throw new BadRequestException('请输入门店手机号验证码');
|
||||
await this.authService.verifySmsCode(normalizedPhone, smsCode, SmsScene.PARTNER_STORE_OPEN);
|
||||
const confirmBindExisting = body.confirmBindExisting === true || body.confirmBindExisting === 'true';
|
||||
await this.assertStorePhoneAvailable(normalizedPhone, confirmBindExisting);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user