门店账号管理修改

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
@@ -83,6 +83,15 @@ export class StoreService {
async createStore(partnerAccountId: bigint, body: Record<string, unknown>) {
const account = await this.getPartnerAccount(partnerAccountId);
const normalizedPhone = String(body.phone).trim();
if (!/^1[3-9]\d{9}$/.test(normalizedPhone)) {
throw new BadRequestException('联系电话须为11位手机号');
}
const existingAccount = await this.prisma.storeAccount.findUnique({
where: { phone: normalizedPhone },
});
if (existingAccount) throw new BadRequestException('该手机号已绑定门店');
const city = await this.resolvePartnerCity(account.partnerId, body.cityId);
const coverUrl = body.coverUrl ? String(body.coverUrl).trim() : '';
const envPhotoUrls = Array.isArray(body.envPhotoUrls)
@@ -96,7 +105,7 @@ export class StoreService {
partnerId: account.partnerId,
categoryId: body.categoryId ? BigInt(String(body.categoryId)) : null,
name: String(body.name),
phone: String(body.phone),
phone: normalizedPhone,
province: String(body.province ?? city.province ?? '河南省'),
cityName: String(body.city ?? city.name ?? '郑州市'),
district: String(body.district ?? ''),
@@ -174,11 +183,8 @@ export class StoreService {
await this.prisma.storeAccount.create({
data: {
storeId: store.id,
phone: await this.resolveStoreAccountPhone(
String(body.accountPhone ?? body.phone),
store.id,
),
name: String(body.accountName ?? body.name),
phone: normalizedPhone,
name: String(body.name),
},
});
@@ -310,13 +316,4 @@ export class StoreService {
if (!city) throw new BadRequestException('合伙人未绑定开城');
return city;
}
private async resolveStoreAccountPhone(phone: string, storeId: bigint): Promise<string> {
const normalized = phone.trim();
const existing = await this.prisma.storeAccount.findUnique({ where: { phone: normalized } });
if (!existing) return normalized;
const suffix = String(storeId).slice(-4);
const candidate = `${normalized.slice(0, 15)}${suffix}`.slice(0, 20);
return candidate;
}
}