feat: 支持商品管理

This commit is contained in:
richarjiang
2026-09-16 22:49:47 +08:00
parent 58c6d2092a
commit 95b9f6511c
30 changed files with 2800 additions and 5 deletions

View File

@@ -73,6 +73,7 @@ model User {
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
productOrders ProductOrder[]
bodyMetrics BodyMetric[]
memberNotes MemberNote[]
progressPhotos ProgressPhoto[]
@@ -620,3 +621,73 @@ model GrowthShareCard {
@@index([userId, createdAt])
@@map("growth_share_cards")
}
// Inventory counts sellable units; pending orders reserve units immediately.
enum ProductOrderStatus {
PENDING
PAID
COMPLETED
CANCELLED
}
model Product {
id String @id @default(uuid())
title String @db.VarChar(80)
description String @db.Text
coverUrl String @map("cover_url") @db.VarChar(1000)
price Int
stock Int @default(0)
sold Int @default(0)
isActive Boolean @default(false) @map("is_active")
sortOrder Int @default(0) @map("sort_order")
version Int @default(0)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
orders ProductOrder[]
stockChanges ProductStockChange[]
@@index([isActive, sortOrder])
@@map("products")
}
model ProductOrder {
id String @id @default(uuid())
orderNo String @unique @map("order_no") @db.VarChar(32)
requestId String @map("request_id") @db.VarChar(80)
userId String @map("user_id")
productId String @map("product_id")
title String @db.VarChar(80)
coverUrl String @map("cover_url") @db.VarChar(1000)
unitPrice Int @map("unit_price")
quantity Int
amount Int
contactName String @map("contact_name") @db.VarChar(40)
contactPhone String @map("contact_phone") @db.VarChar(20)
status ProductOrderStatus @default(PENDING)
pickupCode String @map("pickup_code") @db.VarChar(12)
wxTransactionId String? @unique @map("wx_transaction_id")
expiresAt DateTime @map("expires_at")
paidAt DateTime? @map("paid_at")
completedAt DateTime? @map("completed_at")
completedBy String? @map("completed_by")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id])
product Product @relation(fields: [productId], references: [id])
@@unique([userId, requestId])
@@index([status, expiresAt])
@@index([userId, createdAt])
@@index([productId, status])
@@map("product_orders")
}
model ProductStockChange {
id String @id @default(uuid())
productId String @map("product_id")
delta Int
reason String @db.VarChar(200)
operatorId String @map("operator_id")
createdAt DateTime @default(now()) @map("created_at")
product Product @relation(fields: [productId], references: [id])
@@index([productId, createdAt])
@@map("product_stock_changes")
}