diff --git a/.codex-tasks/multibrand-isolation-epic/PROGRESS.md b/.codex-tasks/multibrand-isolation-epic/PROGRESS.md index 4496d50..df35f19 100644 --- a/.codex-tasks/multibrand-isolation-epic/PROGRESS.md +++ b/.codex-tasks/multibrand-isolation-epic/PROGRESS.md @@ -15,3 +15,4 @@ - 全量门禁已通过:`format:check`、`lint`、`typecheck`、Admin build、Miniapp fixture/visual fixture、API integration `28/28`。 - API lint 保留 6 个既有测试文件 `any` warning,无 error。 - 小程序运行时已从唯一配置读取 `brandSlug`,公共请求层统一注入品牌上下文;客户和管理请求不会误带公共品牌参数。 +- 补齐了两个品牌的运行时 seed 数据:主理人资料、首页图、模块、信任内容、咨询表单、业务项封面和媒体配置;并将品牌 `config` 展开为小程序直接使用的字段,修复切换品牌后空首页、无案例图和“我的”空数据问题。 diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index fe30886..98826be 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -3,6 +3,142 @@ import bcrypt from "bcryptjs"; const prisma = new PrismaClient(); +const runtimeImages = { + doors: [ + "https://images.unsplash.com/photo-1513694203232-719a280e022f?auto=format&fit=crop&w=1000&q=85", + "https://images.unsplash.com/photo-1541123437800-1bb1317badc2?auto=format&fit=crop&w=1000&q=85", + "https://images.unsplash.com/photo-1505691938895-1758d7feb511?auto=format&fit=crop&w=1000&q=85", + ], + food: [ + "https://images.unsplash.com/photo-1547592180-85f173990554?auto=format&fit=crop&w=1000&q=85", + "https://images.unsplash.com/photo-1603133872878-684f208fb84b?auto=format&fit=crop&w=1000&q=85", + "https://images.unsplash.com/photo-1559847844-5315695dadae?auto=format&fit=crop&w=1000&q=85", + ], +}; + +async function ensureRuntimeContent( + brandId: string, + templateKey: "food" | "doors", + offerings: Array<{ name: string; summary: string; image: string; categoryKey: string }>, +): Promise { + await prisma.brandProfile.update({ + where: { id: brandId }, + data: { + config: { + founder: templateKey === "doors" ? "林境主理人" : "阿成", + title: templateKey === "doors" ? "别墅门系统设计顾问" : "私房菜主理人", + slogan: + templateKey === "doors" ? "让每一扇门,成为建筑秩序的开始。" : "认真做好每一顿家常饭。", + phone: templateKey === "doors" ? "13800000000" : "", + wechat: templateKey === "doors" ? "linjing-doors" : "", + studioAddress: templateKey === "doors" ? "城市设计中心 3F" : "大学城生活区东门附近", + heroImage: runtimeImages[templateKey][0], + }, + }, + }); + for (const [sortOrder, item] of offerings.entries()) { + const offering = await prisma.offering.findUnique({ + where: { brandId_name: { brandId, name: item.name } }, + }); + if (!offering) continue; + await prisma.offering.update({ + where: { id: offering.id }, + data: { + coverUrl: item.image, + summary: item.summary, + sortOrder: sortOrder + 1, + isEnabled: true, + config: { + categoryKey: item.categoryKey, + keywords: templateKey === "doors" ? ["定制", "别墅", "门系统"] : ["现做", "家常", "定制"], + media: [{ url: item.image, alt: item.name, type: "image" }], + sections: [], + }, + }, + }); + } + const moduleDefinitions = [ + ["founder-card", "主理人介绍"], + ["brand-hero", "品牌首屏"], + ["trust-proof", "信任与案例"], + ["offering-list", "业务提供项"], + ["inquiry", "咨询入口"], + ] as const; + for (const [sortOrder, [type, title]] of moduleDefinitions.entries()) { + const existing = await prisma.brandModule.findFirst({ where: { brandId, type } }); + if (existing) { + await prisma.brandModule.update({ + where: { id: existing.id }, + data: { isEnabled: true, sortOrder, title }, + }); + } else { + await prisma.brandModule.create({ + data: { brandId, type, title, sortOrder, source: "seed", isEnabled: true }, + }); + } + } + const incompleteOfferings = await prisma.offering.findMany({ + where: { brandId, isEnabled: true, coverUrl: null }, + select: { id: true, name: true }, + }); + for (const [index, item] of incompleteOfferings.entries()) { + const image = runtimeImages[templateKey][index % runtimeImages[templateKey].length]; + await prisma.offering.update({ + where: { id: item.id }, + data: { + coverUrl: image, + config: { + categoryKey: "custom", + keywords: templateKey === "doors" ? ["定制", "门系统"] : ["家常", "定制"], + media: [{ url: image, alt: item.name, type: "image" }], + sections: [], + }, + }, + }); + } + const trustCount = await prisma.trustContent.count({ where: { brandId } }); + if (!trustCount) { + const trustItems = + templateKey === "doors" + ? [ + ["profile", "主理人的门作观", "从建筑关系出发,认真处理每一扇门。"], + ["portfolio", "别墅门系统案例", "围绕入户、庭院和室内空间建立完整门系统。"], + ["process", "从测量到交付", "现场测量、方案沟通、深化确认和落地交付。"], + ] + : [ + ["profile", "关于阿成", "每天认真做好一顿家常饭。"], + ["process", "认真做饭的流程", "提前准备食材,现做现出餐,认真沟通每一次需求。"], + ]; + await prisma.trustContent.createMany({ + data: trustItems.map(([type, title, content], sortOrder) => ({ + brandId, + type, + title, + content, + sortOrder, + isPublished: true, + })), + }); + } + const formCount = await prisma.inquiryForm.count({ where: { brandId } }); + if (!formCount) { + await prisma.inquiryForm.create({ + data: { + brandId, + name: templateKey === "doors" ? "门系统方案咨询" : "家庭聚餐咨询", + purpose: "inquiry", + targetType: "brand", + submissionAction: "create-inquiry", + fieldsSnapshot: [ + { key: "name", label: "您的称呼", type: "text", required: true }, + { key: "phone", label: "联系电话", type: "phone", required: true }, + { key: "remark", label: "需求说明", type: "textarea", required: false }, + ], + }, + }); + } +} + async function main(): Promise { const brand = await prisma.brandProfile.upsert({ where: { id: "00000000-0000-0000-0000-000000000001" }, @@ -52,6 +188,26 @@ async function main(): Promise { if (existing) await prisma.offering.update({ where: { id: existing.id }, data: offering }); else await prisma.offering.create({ data: { ...offering, kind: "service" } }); } + await ensureRuntimeContent(brand.id, "food", [ + { + name: "红烧肉双拼套餐", + summary: "红烧肉、时蔬、米饭", + image: runtimeImages.food[0], + categoryKey: "set-meal", + }, + { + name: "小炒鸡套餐", + summary: "现炒鸡块、时蔬、米饭", + image: runtimeImages.food[1], + categoryKey: "set-meal", + }, + { + name: "家庭聚餐私厨", + summary: "根据人数、地点和口味人工沟通报价", + image: runtimeImages.food[2], + categoryKey: "private-chef", + }, + ]); for (const name of ["普通套餐", "私厨", "配送", "自取", "熟客", "重点跟进"]) { await prisma.tag.upsert({ @@ -122,6 +278,26 @@ async function main(): Promise { update: { isEnabled: true, role: "owner" }, create: { adminUserId: admin.id, brandId: doorsBrand.id, role: "owner" }, }); + await ensureRuntimeContent(doorsBrand.id, "doors", [ + { + name: "别墅入户大门", + summary: "结合建筑立面与入户动线定制门体、五金和安装方案。", + image: runtimeImages.doors[0], + categoryKey: "entrance-door", + }, + { + name: "院门与围合系统", + summary: "院门、围墙和庭院动线的一体化设计与施工配合。", + image: runtimeImages.doors[1], + categoryKey: "garden-door", + }, + { + name: "室内户内门系统", + summary: "根据空间风格定制户内门、隐形门和装饰门。", + image: runtimeImages.doors[2], + categoryKey: "interior-door", + }, + ]); } main().finally(() => prisma.$disconnect()); diff --git a/apps/api/src/modules/public/public-workspace.controller.ts b/apps/api/src/modules/public/public-workspace.controller.ts index b0fbc8e..e1ed1d7 100644 --- a/apps/api/src/modules/public/public-workspace.controller.ts +++ b/apps/api/src/modules/public/public-workspace.controller.ts @@ -98,6 +98,10 @@ export class PublicWorkspaceController { : "linjing-editorial"; const visualTemplate = getVisualTemplate(visualTemplateKey) ?? getVisualTemplate("linjing-editorial"); + const runtimeBrand = { + ...(brand ?? {}), + ...brandConfig, + }; const runtimeModules: RuntimeModule[] = modules.map((module) => ({ key: module.type, type: this.moduleType(module.type), @@ -169,7 +173,7 @@ export class PublicWorkspaceController { const inquiryForm = inquiryForms[0] ?? null; const runtimeWorkspace: RuntimeWorkspace = { schemaVersion: "1.0.0", - brand: brand ?? {}, + brand: runtimeBrand, navigation: { tabs: [ { key: "home", label: "首页", page: "pages/index/index" }, @@ -203,7 +207,7 @@ export class PublicWorkspaceController { const response = { ...runtimeWorkspace, contractVersion: "1.0", - brand, + brand: runtimeBrand, template: template ? { key: template.key, diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index f4a5abe..7bf3dee 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -58,6 +58,9 @@ test("health and public content are available without authentication", async () assert.ok(Array.isArray(runtime.capabilities)); assert.ok(runtime.theme.colors.background); assert.ok(Array.isArray(runtime.plugins)); + assert.equal(runtime.brand.founder, "阿成"); + assert.ok(runtime.offerings.every((item) => item.coverUrl)); + assert.ok(runtime.trustContent.length > 0); const bySlug = await request("/public/workspace?brandSlug=default-brand"); assert.equal(bySlug.statusCode, 200); assert.equal(JSON.parse(bySlug.body).brand.id, brandId); diff --git a/apps/miniapp/pages/index/index.js b/apps/miniapp/pages/index/index.js index 602c3f9..0a1f5f7 100644 --- a/apps/miniapp/pages/index/index.js +++ b/apps/miniapp/pages/index/index.js @@ -39,6 +39,7 @@ Page({ theme: workspace.theme || {}, hero: { ...this.data.hero, + image: activeBrand.heroImage || this.data.hero.image, eyebrow: activeBrand.tagline || activeBrand.name, title: firstOffering.name || activeBrand.name, slogan: activeBrand.description || "以专业经验建立长期信任", diff --git a/apps/miniapp/utils/config.js b/apps/miniapp/utils/config.js index f83df9f..f323f8a 100644 --- a/apps/miniapp/utils/config.js +++ b/apps/miniapp/utils/config.js @@ -8,6 +8,6 @@ module.exports = { return app.globalData.brand || {}; }, get brandSlug() { - return app.globalData.brandSlug || "default-brand"; + return wx.getStorageSync("brandSlug") || app.globalData.brandSlug || "default-brand"; }, };