门店账号管理修改

This commit is contained in:
2026-07-07 00:01:16 +08:00
parent e85c4b9bcb
commit 7ca9fc8a35
25 changed files with 599 additions and 134 deletions
@@ -28,6 +28,11 @@ export class AdminStoresController {
return this.service.listStores(query);
}
@Post('phone/sms/send')
sendOpenSms(@Body() body: { phone: string }) {
return this.service.sendStoreOpenSms(body.phone);
}
@Get(':id')
detail(@Param('id') id: string) {
return this.service.detailStore(BigInt(id));
@@ -1,8 +1,10 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { ClientApp, SmsScene } from '@dukang/shared-types';
import { PrismaService } from '../../common/prisma/prisma.module';
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
import { mapStoreCompat } from '../../common/compat/v31-compat';
import { AuthService } from '../iam/auth.service';
import type { AdminStoreAccountsQueryDto, AdminStoreMediaQueryDto, AdminStoresQueryDto } from './dto/admin-query.dto';
import type {
CreateStoreAccountDto,
@@ -16,7 +18,16 @@ import type {
@Injectable()
export class AdminStoresService {
constructor(private readonly prisma: PrismaService) {}
constructor(
private readonly prisma: PrismaService,
private readonly authService: AuthService,
) {}
async sendStoreOpenSms(phone: string) {
return this.authService.sendSms(phone, SmsScene.STORE_ACCOUNT_OPEN, {
clientApp: ClientApp.HQ_WEB,
});
}
async listStores(query: AdminStoresQueryDto) {
const page = query.page ?? 1;
@@ -153,6 +164,16 @@ export class AdminStoresService {
}
async createStore(dto: CreateStoreDto) {
const normalizedPhone = dto.phone.trim();
if (!/^1[3-9]\d{9}$/.test(normalizedPhone)) {
throw new BadRequestException('请输入正确的手机号码');
}
await this.authService.verifySmsCode(normalizedPhone, dto.smsCode, SmsScene.STORE_ACCOUNT_OPEN);
const existingAccount = await this.prisma.storeAccount.findUnique({
where: { phone: normalizedPhone },
});
if (existingAccount) throw new BadRequestException('该手机号已绑定门店');
const partner = await this.prisma.partner.findUnique({ where: { id: BigInt(dto.partnerId) } });
if (!partner) throw new BadRequestException('开城合伙人不存在');
const city = await this.prisma.commonCity.findUnique({ where: { id: BigInt(dto.cityId) } });
@@ -167,7 +188,7 @@ export class AdminStoresService {
partnerId: partner.id,
categoryId: dto.categoryId ? BigInt(dto.categoryId) : null,
name: dto.name,
phone: dto.phone,
phone: normalizedPhone,
province: dto.province ?? city.province,
cityName: dto.city ?? city.name,
district: dto.district ?? '',
@@ -243,7 +264,7 @@ export class AdminStoresService {
await this.prisma.storeAccount.create({
data: {
storeId: store.id,
phone: dto.accountPhone ?? dto.phone,
phone: normalizedPhone,
name: dto.accountName ?? dto.name,
},
});
@@ -24,6 +24,10 @@ export class CreateStoreDto {
@IsNotEmpty()
phone: string;
@IsString()
@IsNotEmpty()
smsCode: string;
@IsOptional()
@IsString()
categoryId?: string;
@@ -52,10 +56,6 @@ export class CreateStoreDto {
@IsString()
coverUrl?: string;
@IsOptional()
@IsString()
accountPhone?: string;
@IsOptional()
@IsString()
accountName?: string;