fix: 收敛模板编辑发布契约并还原餐饮页面视觉
This commit is contained in:
1 parent
20bcb43534
commit
f4061a24bd
102 files changed
+4510
-870
No files matched your search
+52
-69
@@ -1,7 +1,7 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { PrismaClient, type Prisma } from "@prisma/client";
|
||||
import { getTemplatePackageManifestForVisualKey } from "@personal-brand/config";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { buildBrandReleaseSnapshot } from "../src/brand-release.service.js";
|
||||
import { getTemplateSampleContent } from "@personal-brand/config";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
@@ -20,7 +20,7 @@ const runtimeImages = {
|
||||
"https://images.unsplash.com/photo-1556761175-b413da4baf72?auto=format&fit=crop&w=1000&q=85",
|
||||
"https://images.unsplash.com/photo-1521737711867-e3b97375f902?auto=format&fit=crop&w=1000&q=85",
|
||||
],
|
||||
};
|
||||
} as const;
|
||||
|
||||
type OfferingKind = "service" | "product" | "package" | "subscription";
|
||||
|
||||
@@ -41,9 +41,10 @@ interface RuntimeSeedTemplate {
|
||||
type: string;
|
||||
title: string;
|
||||
content: string;
|
||||
summary?: string;
|
||||
config?: Record<string, unknown>;
|
||||
}>;
|
||||
inquiryForm: { name: string; fieldsSnapshot: Array<Record<string, unknown>> };
|
||||
inquiryForm?: { name: string; fieldsSnapshot: Array<Record<string, unknown>> };
|
||||
}
|
||||
|
||||
const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTemplate> = {
|
||||
@@ -51,6 +52,7 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
|
||||
templateKey: "personal",
|
||||
brandConfig: {
|
||||
visualTemplateKey: "linjing-editorial",
|
||||
templateData: { designPhilosophy: "先厘清问题,再设计表达" },
|
||||
founder: "林然",
|
||||
title: "品牌策略顾问",
|
||||
slogan: "用清晰的定位与可执行的表达,让专业被看见。",
|
||||
@@ -186,8 +188,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
|
||||
flowTitle: "从预订到取餐",
|
||||
},
|
||||
service: {
|
||||
coverageLabel: "取餐与配送",
|
||||
stepLabel: "步骤",
|
||||
processAction: "立即预订",
|
||||
},
|
||||
offerings: {
|
||||
@@ -277,24 +277,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
|
||||
},
|
||||
],
|
||||
trustContent: [
|
||||
{
|
||||
type: "schedule",
|
||||
title: "每周出摊日程",
|
||||
summary: "周一至周五晚餐与夜宵档",
|
||||
content: "二号校门外小吃商业街 · 17:00 - 22:30\n周六、周日承接团体单与夜市流动出摊",
|
||||
},
|
||||
{
|
||||
type: "coverage",
|
||||
title: "取餐与配送范围",
|
||||
summary: "提前预订,按约定时间取餐或配送",
|
||||
content: "摊位现场自取;满 3 份可配送至校内宿舍楼栋或实验楼门前。",
|
||||
},
|
||||
{
|
||||
type: "process",
|
||||
title: "定制餐品流程",
|
||||
summary: "从需求沟通到保温交付",
|
||||
content: "提交基本需求\n确认菜单与预算\n当日新鲜烹饪打包\n保温直达交付",
|
||||
},
|
||||
{
|
||||
type: "credential",
|
||||
title: "食品安全与制作承诺",
|
||||
@@ -312,20 +294,13 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
|
||||
content: "备料期 15 分钟内联系,出摊高峰 1 小时内回复。",
|
||||
},
|
||||
],
|
||||
inquiryForm: {
|
||||
name: "家庭聚餐咨询",
|
||||
fieldsSnapshot: [
|
||||
{ key: "name", label: "您的称呼", type: "text", required: true },
|
||||
{ key: "phone", label: "联系电话", type: "phone", required: true },
|
||||
{ key: "remark", label: "需求说明", type: "textarea", required: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
doors: {
|
||||
templateKey: "doors",
|
||||
retiredOfferingNames: ["别墅入户大门", "院门与围合系统", "室内户内门系统"],
|
||||
brandConfig: {
|
||||
visualTemplateKey: "linjing-editorial",
|
||||
templateData: { designPhilosophy: "让门与空间建立长期、克制的关系" },
|
||||
founder: "林叙安 (Lin XUAN)",
|
||||
title: "高端门系统建筑研造主理人",
|
||||
slogan: "为当代别墅空间,定制有秩序感与呼吸感的门",
|
||||
@@ -679,40 +654,39 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
|
||||
};
|
||||
|
||||
async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTemplate): Promise<void> {
|
||||
const packageSample = getTemplateSampleContent(template.templateKey);
|
||||
const sampleOfferings = packageSample?.offerings ?? [];
|
||||
const offerings = template.offerings.map((item, index) => ({
|
||||
...item,
|
||||
...(sampleOfferings[index]
|
||||
? {
|
||||
name: sampleOfferings[index].name,
|
||||
summary: sampleOfferings[index].summary,
|
||||
config: {
|
||||
...item.config,
|
||||
categoryKey: sampleOfferings[index].categoryKey,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
}));
|
||||
// 模板 package 的 sampleContent 只用于导入预览;演示品牌使用明确的品牌 fixture,
|
||||
// 避免把模板示例内容误当成所有品牌的数据库初始数据。
|
||||
const trustContent = template.trustContent;
|
||||
const inquiryFields = (packageSample?.fields ?? template.inquiryForm.fieldsSnapshot).map(
|
||||
(field) => ({
|
||||
...field,
|
||||
...(Array.isArray(field.options)
|
||||
? {
|
||||
options: field.options.map((option) =>
|
||||
typeof option === "string" ? { label: option, value: option } : option,
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
);
|
||||
// 这里只初始化明确的开发演示品牌;餐饮结构化槽位和表单取自对应 package,
|
||||
// 新增生产模板无需添加 seed 分支,品牌样例内容仍须由管理员显式导入。
|
||||
const offerings = template.offerings;
|
||||
const foodSample =
|
||||
template.templateKey === "food"
|
||||
? getTemplatePackageManifestForVisualKey("acheng-campus-food")?.sampleContent?.food
|
||||
: undefined;
|
||||
if (template.templateKey === "food" && !foodSample)
|
||||
throw new Error("Food development sample is missing");
|
||||
const trustContent = foodSample
|
||||
? foodSample.trustContent.map((item) => {
|
||||
const fixture = template.trustContent.find((entry) => entry.type === item.type);
|
||||
return { ...item, ...fixture, config: { ...item.config, ...fixture?.config } };
|
||||
})
|
||||
: template.trustContent;
|
||||
const inquiryFields = foodSample?.fields ?? template.inquiryForm?.fieldsSnapshot;
|
||||
const inquiryFormName = foodSample?.inquiryFormName ?? template.inquiryForm?.name;
|
||||
if (!inquiryFields?.length || !inquiryFormName)
|
||||
throw new Error("Development inquiry fixture is missing");
|
||||
const existingBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
|
||||
const existingConfig =
|
||||
existingBrand.config &&
|
||||
typeof existingBrand.config === "object" &&
|
||||
!Array.isArray(existingBrand.config)
|
||||
? (existingBrand.config as Record<string, unknown>)
|
||||
: {};
|
||||
await prisma.brandProfile.update({
|
||||
where: { id: brandId },
|
||||
data: {
|
||||
config: template.brandConfig,
|
||||
config: { ...existingConfig, ...template.brandConfig } as Prisma.InputJsonValue,
|
||||
...(existingBrand.slug === "default-brand" && !existingBrand.avatarUrl
|
||||
? { avatarUrl: "/assets/owner/portrait.jpg" }
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
for (const [sortOrder, item] of offerings.entries()) {
|
||||
@@ -747,7 +721,8 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
|
||||
select: { id: true, name: true },
|
||||
});
|
||||
for (const [index, item] of incompleteOfferings.entries()) {
|
||||
const image = template.offerings[index % template.offerings.length].image;
|
||||
const image = template.offerings[index % template.offerings.length]?.image;
|
||||
if (!image) throw new Error("Development fixture has no offering image");
|
||||
await prisma.offering.update({
|
||||
where: { id: item.id },
|
||||
data: {
|
||||
@@ -764,9 +739,17 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
|
||||
}
|
||||
for (const [sortOrder, item] of trustContent.entries()) {
|
||||
const existing = await prisma.trustContent.findFirst({
|
||||
where: { brandId, type: item.type, title: item.title },
|
||||
where: { brandId, type: item.type },
|
||||
orderBy: [{ isPublished: "desc" }, { sortOrder: "asc" }],
|
||||
});
|
||||
const data = { ...item, brandId, sortOrder, isPublished: true };
|
||||
const { config, ...fields } = item;
|
||||
const data = {
|
||||
...fields,
|
||||
brandId,
|
||||
sortOrder,
|
||||
isPublished: true,
|
||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
||||
};
|
||||
if (existing) await prisma.trustContent.update({ where: { id: existing.id }, data });
|
||||
else await prisma.trustContent.create({ data });
|
||||
}
|
||||
@@ -775,7 +758,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
|
||||
orderBy: { createdAt: "asc" },
|
||||
});
|
||||
const formData = {
|
||||
name: template.inquiryForm.name,
|
||||
name: inquiryFormName,
|
||||
purpose: "inquiry",
|
||||
targetType: "brand",
|
||||
submissionAction: "create-inquiry",
|
||||
@@ -788,14 +771,14 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
|
||||
}
|
||||
|
||||
async function ensureSeedRelease(brandId: string, actorId: string): Promise<void> {
|
||||
if (await prisma.brandRelease.findFirst({ where: { brandId } })) return;
|
||||
const snapshot = await buildBrandReleaseSnapshot(prisma, brandId);
|
||||
await prisma.brandRelease.deleteMany({ where: { brandId } });
|
||||
await prisma.brandRelease.create({
|
||||
data: {
|
||||
brandId,
|
||||
version: 1,
|
||||
status: "published",
|
||||
snapshot,
|
||||
snapshot: snapshot as unknown as Prisma.InputJsonValue,
|
||||
actorId,
|
||||
note: "seed 基线发布版本",
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user