import { PrismaClient } from "@prisma/client"; 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" }, update: {}, create: { slug: "default-brand", id: "00000000-0000-0000-0000-000000000001", name: "阿成家常菜", templateKey: "food", tagline: "现做家常套餐,也为小型聚餐定制一桌热饭菜", description: "每天认真做好一顿家常饭。", hours: "周一至周六 10:30-20:00", address: "大学城生活区东门附近", deliveryNote: "目前支持部分学生宿舍楼配送,无法送达时会主动联系。", }, }); const offerings = [ { brandId: brand.id, name: "红烧肉双拼套餐", description: "红烧肉、时蔬、米饭", priceText: "¥28 / 份", priceAmount: 2800, sortOrder: 1, }, { brandId: brand.id, name: "小炒鸡套餐", description: "现炒鸡块、时蔬、米饭", priceText: "¥25 / 份", priceAmount: 2500, sortOrder: 2, }, { brandId: brand.id, name: "家庭聚餐私厨", description: "根据人数、地点和口味人工沟通报价", priceText: "面议", sortOrder: 3, }, ]; for (const offering of offerings) { const existing = await prisma.offering.findFirst({ where: { brandId: brand.id, name: offering.name }, }); 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({ where: { brandId_name: { brandId: brand.id, name } }, update: {}, create: { brandId: brand.id, name, isPreset: true }, }); } const admin = await prisma.adminUser.upsert({ where: { username: "admin" }, update: {}, create: { username: "admin", passwordHash: await bcrypt.hash(process.env.SEED_ADMIN_PASSWORD ?? "change-me-now-123", 12), displayName: "品牌管理员", }, }); await prisma.brandMembership.upsert({ where: { adminUserId_brandId: { adminUserId: admin.id, brandId: brand.id } }, update: { isEnabled: true, role: "owner" }, create: { adminUserId: admin.id, brandId: brand.id, role: "owner" }, }); const doorsBrand = await prisma.brandProfile.upsert({ where: { id: "00000000-0000-0000-0000-000000000002" }, update: {}, create: { id: "00000000-0000-0000-0000-000000000002", slug: "linjing-doors", name: "林境门作", templateKey: "doors", tagline: "为别墅空间定制有秩序感的门系统", description: "从入户大门到室内户内门,提供完整的门系统设计与落地服务。", hours: "周一至周六 09:00-18:00", address: "城市设计中心 3F", contactPhone: "13800000000", contactWechat: "linjing-doors", }, }); for (const offering of [ { name: "别墅入户大门", description: "结合建筑立面与入户动线定制门体、五金和安装方案。", priceText: "预约沟通", sortOrder: 1, }, { name: "院门与围合系统", description: "院门、围墙和庭院动线的一体化设计与施工配合。", priceText: "预约沟通", sortOrder: 2, }, { name: "室内户内门系统", description: "根据空间风格定制户内门、隐形门和装饰门。", priceText: "预约沟通", sortOrder: 3, }, ]) { await prisma.offering.upsert({ where: { brandId_name: { brandId: doorsBrand.id, name: offering.name } }, update: offering, create: { ...offering, brandId: doorsBrand.id, kind: "service" }, }); } await prisma.brandMembership.upsert({ where: { adminUserId_brandId: { adminUserId: admin.id, brandId: doorsBrand.id } }, 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());