包含: - furniture-3d-system:Next.js 16 全栈应用(资产中心、产品管理、3D装配动画) - autocad-plugin:AutoCAD 家具导出插件源码 - 资产中心改造:编辑弹窗化、删除功能、Toast反馈、自定义Select组件 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
243 lines
7.6 KiB
TypeScript
243 lines
7.6 KiB
TypeScript
/**
|
||
* 创建测试产品数据
|
||
*/
|
||
|
||
import { PrismaClient } from '@prisma/client'
|
||
|
||
const prisma = new PrismaClient()
|
||
|
||
async function main() {
|
||
console.log('开始创建测试产品...')
|
||
|
||
// 获取第一个用户作为创建者和 SKU 负责人
|
||
const user = await prisma.user.findFirst({
|
||
where: { status: 'ACTIVE' },
|
||
})
|
||
|
||
if (!user) {
|
||
console.error('❌ 没有找到活跃用户,请先创建用户')
|
||
process.exit(1)
|
||
}
|
||
|
||
console.log(`使用用户: ${user.name} (${user.email})`)
|
||
|
||
// 测试产品数据
|
||
const testProducts = [
|
||
{
|
||
modelNumber: 'SF-001',
|
||
name: '现代简约三人沙发',
|
||
description: '采用高品质布艺面料,内置高密度海绵,舒适耐用。简约设计风格,适合现代家居环境。',
|
||
category: '客厅家具',
|
||
thumbnailUrl: '/placeholder-sofa.jpg',
|
||
skus: [
|
||
{
|
||
skuCode: 'SF-001-GRAY-3S',
|
||
attributes: { color: '灰色', size: '三人座', material: '布艺' },
|
||
price: 3999.00,
|
||
costPrice: 2000.00,
|
||
stock: 50,
|
||
images: ['/placeholder-sofa.jpg'],
|
||
},
|
||
{
|
||
skuCode: 'SF-001-BLUE-3S',
|
||
attributes: { color: '蓝色', size: '三人座', material: '布艺' },
|
||
price: 3999.00,
|
||
costPrice: 2000.00,
|
||
stock: 30,
|
||
images: ['/placeholder-sofa.jpg'],
|
||
},
|
||
],
|
||
assemblySteps: [
|
||
{
|
||
order: 1,
|
||
title: '准备工作',
|
||
description: '打开包装,检查所有配件是否齐全。准备好螺丝刀和扳手。',
|
||
partIds: ['base', 'cushions', 'legs'],
|
||
transform: { position: [0, 0, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 1000,
|
||
easing: 'ease-out',
|
||
},
|
||
{
|
||
order: 2,
|
||
title: '安装沙发腿',
|
||
description: '将四个沙发腿分别固定在底座的四个角上,使用螺丝拧紧。',
|
||
partIds: ['legs'],
|
||
transform: { position: [0, 0.2, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 1500,
|
||
easing: 'ease-in-out',
|
||
},
|
||
{
|
||
order: 3,
|
||
title: '放置坐垫',
|
||
description: '将坐垫和靠垫按照标记位置放置好。',
|
||
partIds: ['cushions'],
|
||
transform: { position: [0, 0.5, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 1000,
|
||
easing: 'ease-out',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
modelNumber: 'TB-002',
|
||
name: '北欧风格餐桌',
|
||
description: '实木材质,环保健康。桌面经过多道工序打磨,光滑细腻。简洁的北欧设计,适合4-6人使用。',
|
||
category: '餐厅家具',
|
||
thumbnailUrl: '/placeholder-table.jpg',
|
||
skus: [
|
||
{
|
||
skuCode: 'TB-002-OAK-L',
|
||
attributes: { color: '橡木色', size: '大号(1.6m)', material: '实木' },
|
||
price: 2599.00,
|
||
costPrice: 1300.00,
|
||
stock: 40,
|
||
images: ['/placeholder-table.jpg'],
|
||
},
|
||
],
|
||
assemblySteps: [
|
||
{
|
||
order: 1,
|
||
title: '组装桌腿',
|
||
description: '将四条桌腿与桌腿支架连接,确保螺丝拧紧。',
|
||
partIds: ['legs', 'support'],
|
||
transform: { position: [0, 0, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 1500,
|
||
easing: 'ease-out',
|
||
},
|
||
{
|
||
order: 2,
|
||
title: '安装桌面',
|
||
description: '将桌面翻转,将组装好的桌腿固定在桌面底部。',
|
||
partIds: ['tabletop'],
|
||
transform: { position: [0, 0.8, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 2000,
|
||
easing: 'ease-in-out',
|
||
},
|
||
{
|
||
order: 3,
|
||
title: '最后检查',
|
||
description: '将餐桌翻转回正面,检查所有连接处是否牢固。',
|
||
partIds: ['tabletop', 'legs'],
|
||
transform: { position: [0, 0.75, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 1000,
|
||
easing: 'ease-out',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
modelNumber: 'BK-003',
|
||
name: '多功能书架',
|
||
description: '五层设计,大容量储物空间。采用环保板材,结构稳固。可用于书房、客厅或卧室。',
|
||
category: '书房家具',
|
||
thumbnailUrl: '/placeholder-bookshelf.jpg',
|
||
skus: [
|
||
{
|
||
skuCode: 'BK-003-WHITE-5L',
|
||
attributes: { color: '白色', size: '五层', material: '环保板材' },
|
||
price: 1299.00,
|
||
costPrice: 650.00,
|
||
stock: 60,
|
||
images: ['/placeholder-bookshelf.jpg'],
|
||
},
|
||
{
|
||
skuCode: 'BK-003-WALNUT-5L',
|
||
attributes: { color: '胡桃木色', size: '五层', material: '环保板材' },
|
||
price: 1399.00,
|
||
costPrice: 700.00,
|
||
stock: 45,
|
||
images: ['/placeholder-bookshelf.jpg'],
|
||
},
|
||
],
|
||
assemblySteps: [
|
||
{
|
||
order: 1,
|
||
title: '组装侧板',
|
||
description: '将左右两块侧板与底板连接,使用木榫和螺丝固定。',
|
||
partIds: ['side-panels', 'bottom'],
|
||
transform: { position: [0, 0, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 1500,
|
||
easing: 'ease-out',
|
||
},
|
||
{
|
||
order: 2,
|
||
title: '安装层板',
|
||
description: '按照预留孔位,依次安装各层隔板。',
|
||
partIds: ['shelves'],
|
||
transform: { position: [0, 0.5, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 2000,
|
||
easing: 'ease-in-out',
|
||
},
|
||
{
|
||
order: 3,
|
||
title: '固定顶板',
|
||
description: '将顶板固定在书架顶部,确保整体结构稳固。',
|
||
partIds: ['top'],
|
||
transform: { position: [0, 1.5, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 1000,
|
||
easing: 'ease-out',
|
||
},
|
||
{
|
||
order: 4,
|
||
title: '安装背板',
|
||
description: '将背板用小钉子固定在书架背面,增加稳定性。',
|
||
partIds: ['back-panel'],
|
||
transform: { position: [0, 0.75, -0.2], rotation: [0, 0, 0], scale: [1, 1, 1] },
|
||
duration: 1500,
|
||
easing: 'ease-in-out',
|
||
},
|
||
],
|
||
},
|
||
]
|
||
|
||
// 创建产品
|
||
for (const productData of testProducts) {
|
||
console.log(`\n创建产品: ${productData.modelNumber} - ${productData.name}`)
|
||
|
||
const { skus, assemblySteps, ...productInfo } = productData
|
||
|
||
const product = await prisma.product.create({
|
||
data: {
|
||
...productInfo,
|
||
createdBy: user.id,
|
||
skus: {
|
||
create: skus.map(sku => ({
|
||
...sku,
|
||
price: sku.price,
|
||
costPrice: sku.costPrice,
|
||
ownerId: user.id,
|
||
})),
|
||
},
|
||
assemblySteps: {
|
||
create: assemblySteps,
|
||
},
|
||
shareLinks: {
|
||
create: {
|
||
token: `share-${productData.modelNumber.toLowerCase()}-${Date.now()}`,
|
||
viewCount: Math.floor(Math.random() * 50),
|
||
},
|
||
},
|
||
},
|
||
include: {
|
||
skus: true,
|
||
assemblySteps: true,
|
||
shareLinks: true,
|
||
},
|
||
})
|
||
|
||
console.log(` ✓ 创建成功`)
|
||
console.log(` - SKU数量: ${product.skus.length}`)
|
||
console.log(` - 装配步骤: ${product.assemblySteps.length}`)
|
||
console.log(` - 分享链接: ${product.shareLinks.length}`)
|
||
}
|
||
|
||
console.log('\n✅ 所有测试产品创建完成!')
|
||
}
|
||
|
||
main()
|
||
.catch((e) => {
|
||
console.error('❌ 创建失败:', e)
|
||
process.exit(1)
|
||
})
|
||
.finally(async () => {
|
||
await prisma.$disconnect()
|
||
})
|