shop/prisma/schema.prisma
2025-10-11 21:19:20 +08:00

245 lines
6.5 KiB
Plaintext

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
email String @unique
name String?
phone String?
avatar String?
wechatOpenid String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// 分销相关
distributorId String?
// 积分和等级
pointBalance Int @default(0)
membershipLevel String @default("explore") // explore,品鉴,调香
}
model Product {
id String @id @default(cuid())
name String
description String?
price Float
originalPrice Float?
images String // JSON array of image URLs
category String
tags String // JSON array
inventory Int @default(0)
salesCount Int @default(0)
status String @default("active") // active, inactive
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model GroupBuyConfig {
id String @id @default(cuid())
productId String @unique
// 阶梯拼团配置
tier3People Int @default(3)
tier3Discount Float @default(0.7) // 3人团7折
tier3Points Int @default(200) // 团长200积分
tier5People Int @default(5)
tier5Discount Float @default(0.5) // 5人团5折
tier5Points Int @default(300) // 团长300积分
// 时间配置
duration Int @default(24) // 小时
dailyLimit Int? // 每日限量
// 秒杀配置
flashSaleEnabled Boolean @default(false)
flashSalePrice Float?
flashSaleStock Int?
flashSaleTime String? // "10:00"
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model GroupBuy {
id String @id @default(cuid())
productId String
leaderId String
// 阶梯信息
targetPeople Int // 目标人数
currentPeople Int @default(1)
achievedTier String? // 达到的阶梯
// 价格信息
originalPrice Float
groupPrice Float
finalPrice Float? // 最终成交价
// 时间信息
startTime DateTime @default(now())
endTime DateTime
successTime DateTime?
// 状态
status String @default("active") // active, success, failed, expired
// 溯源码
traceCode String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model GroupMember {
id String @id @default(cuid())
groupBuyId String
userId String
inviterId String? // 邀请人ID
joinTime DateTime @default(now())
isLeader Boolean @default(false)
// 避免重复参团
@@unique([groupBuyId, userId])
}
model Order {
id String @id @default(cuid())
orderNo String @unique
userId String
productId String
groupBuyId String?
// 价格信息
originalPrice Float
finalPrice Float
discountAmount Float @default(0)
// 订单信息
quantity Int @default(1)
status String @default("pending") // pending, paid, shipped, delivered, cancelled
paymentMethod String?
paymentTime DateTime?
// 物流信息
trackingNumber String?
logisticsInfo String? // JSON
// 溯源信息
traceCode String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Commission {
id String @id @default(cuid())
orderId String
distributorId String
// 佣金信息
type String // direct, indirect
amount Float
rate Float // 佣金比例
// 状态
status String @default("pending") // pending, settled, cancelled
settledTime DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Subscription {
id String @id @default(cuid())
userId String @unique
// 订阅配置
plan String // monthly, quarterly
status String @default("active") // active, paused, cancelled
// 配送配置
deliveryFrequency String @default("monthly") // monthly, semimonthly
deliveryDay Int @default(5) // 每月几号
excludedScents String // JSON array of excluded scents
// 盲盒配置
unlockedScents String // JSON array of unlocked scents
// 订阅时间
startTime DateTime @default(now())
endTime DateTime?
nextDelivery DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model SubscriptionConfig {
id String @id @default(cuid())
productId String @unique
// 订阅价格
monthlyPrice Float
quarterlyPrice Float
// 会员折扣
exploreDiscount Float @default(0.95) // 95折
tastingDiscount Float @default(0.85) // 85折
perfumerDiscount Float? // 调香师专属
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Point {
id String @id @default(cuid())
userId String
// 积分信息
amount Int
type String // earn, spend
source String // purchase, group_buy, distribution, ugc, etc.
description String?
// 关联信息
relatedId String? // 关联订单ID等
relatedType String? // order, group_buy, etc.
createdAt DateTime @default(now())
}
model UgcContent {
id String @id @default(cuid())
userId String
// 内容信息
type String // review, tutorial, story
title String
content String
images String // JSON array
tags String // JSON array
// 状态
status String @default("pending") // pending, approved, rejected
// 互动数据
likes Int @default(0)
views Int @default(0)
// 奖励
pointsAwarded Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}