schema.prisma 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. generator client {
  2. provider = "prisma-client-js"
  3. }
  4. datasource db {
  5. provider = "mysql"
  6. url = env("DATABASE_URL")
  7. }
  8. model User {
  9. id Int @id @default(autoincrement())
  10. phone String? @unique
  11. openid String? @unique
  12. nickname String @default("用户")
  13. avatar String @default("")
  14. memberLevel Int @default(0)
  15. memberExpireAt DateTime?
  16. dailyUsage Int @default(0)
  17. lastUsageDate String @default("")
  18. createdAt DateTime @default(now())
  19. updatedAt DateTime @updatedAt
  20. usedAudioMinutes Int @default(0)
  21. costLimit Float @default(0)
  22. quotaReserved Float @default(0)
  23. subscriptionResetDate DateTime?
  24. comments Comment[]
  25. drafts Draft[]
  26. favorites Favorite[]
  27. notifications Notification[]
  28. orders Order[]
  29. playRecords PlayRecord[]
  30. playlists Playlist[]
  31. signRecords SignRecord[]
  32. subscriptions Subscription[]
  33. tokenBalance TokenBalance?
  34. tokenUsages TokenUsage[]
  35. preferences UserPreference?
  36. shareRecords ShareRecord[]
  37. invitesSent InviteRecord[] @relation("InviterRelation")
  38. invitesReceived InviteRecord[] @relation("InviteeRelation")
  39. @@index([phone])
  40. @@index([openid])
  41. }
  42. model Order {
  43. id Int @id @default(autoincrement())
  44. userId Int
  45. orderNo String @unique
  46. planId Int?
  47. productType String
  48. amount Decimal @db.Decimal(10, 2)
  49. status String @default("pending")
  50. paymentMethod String?
  51. paymentId String?
  52. paidAt DateTime?
  53. createdAt DateTime @default(now())
  54. updatedAt DateTime @updatedAt
  55. plan SubscriptionPlan? @relation(fields: [planId], references: [id])
  56. user User @relation(fields: [userId], references: [id])
  57. tokenUsages TokenUsage[]
  58. @@index([userId, createdAt])
  59. @@index([orderNo])
  60. @@index([status])
  61. @@index([planId], map: "Order_planId_fkey")
  62. }
  63. model PlayRecord {
  64. id Int @id @default(autoincrement())
  65. userId Int
  66. chapterId Int
  67. progress Float @default(0)
  68. duration Float @default(0)
  69. updatedAt DateTime @updatedAt
  70. createdAt DateTime @default(now())
  71. chapter BookChapter @relation(fields: [chapterId], references: [id])
  72. user User @relation(fields: [userId], references: [id])
  73. @@unique([userId, chapterId])
  74. @@index([userId])
  75. @@index([chapterId])
  76. }
  77. model UserPreference {
  78. id Int @id @default(autoincrement())
  79. userId Int @unique
  80. playSpeed Float @default(1)
  81. quality String @default("standard")
  82. theme String @default("light")
  83. defaultVoiceId String? @default("cherry")
  84. defaultVolume Int @default(50)
  85. autoPlayNext Boolean @default(true)
  86. wifiOnlyDownload Boolean @default(false)
  87. updatedAt DateTime @updatedAt
  88. createdAt DateTime @default(now())
  89. user User @relation(fields: [userId], references: [id])
  90. }
  91. model Favorite {
  92. id Int @id @default(autoincrement())
  93. userId Int
  94. bookId Int
  95. createdAt DateTime @default(now())
  96. book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
  97. user User @relation(fields: [userId], references: [id])
  98. @@unique([userId, bookId])
  99. @@index([userId])
  100. @@index([bookId])
  101. }
  102. model Comment {
  103. id Int @id @default(autoincrement())
  104. userId Int
  105. chapterId Int
  106. content String @db.Text
  107. rating Int
  108. createdAt DateTime @default(now())
  109. chapter BookChapter @relation(fields: [chapterId], references: [id])
  110. user User @relation(fields: [userId], references: [id])
  111. @@index([chapterId])
  112. @@index([userId])
  113. }
  114. model Notification {
  115. id String @id @default(uuid())
  116. userId Int
  117. title String
  118. content String @db.Text
  119. isRead Boolean @default(false)
  120. createdAt DateTime @default(now())
  121. user User @relation(fields: [userId], references: [id])
  122. @@index([userId])
  123. }
  124. model Book {
  125. id Int @id @default(autoincrement())
  126. userId Int?
  127. title String
  128. subtitle String?
  129. description String @db.Text
  130. coverUrl String?
  131. targetAudience String @default("通用")
  132. style String @default("专业严谨")
  133. bookScale String @default("1000")
  134. totalChapters Int @default(10)
  135. estimatedWords Int @default(0)
  136. progress Int @default(0)
  137. isPublished Boolean @default(false)
  138. outlineJson String? @db.LongText
  139. foreword String? @db.Text
  140. afterword String? @db.Text
  141. errorMsg String? @db.Text
  142. voiceSpeed Float @default(1.0)
  143. createdAt DateTime @default(now())
  144. updatedAt DateTime @updatedAt
  145. failedStage String? @db.VarChar(30)
  146. genStage String @default("draft")
  147. bookAnalysis String? @db.Text
  148. chapters BookChapter[]
  149. favorites Favorite[]
  150. videoProjects VideoProject[]
  151. @@index([userId])
  152. @@index([createdAt])
  153. }
  154. model BookChapter {
  155. id Int @id @default(autoincrement())
  156. bookId Int
  157. parentId Int @default(0)
  158. level Int @default(1)
  159. number Int
  160. title String
  161. summary String? @db.Text
  162. keyPoints String? @db.Text
  163. estimatedWords Int @default(1000)
  164. content String? @db.LongText
  165. wordCount Int @default(0)
  166. contentError String? @db.Text
  167. generatedAt DateTime?
  168. audioUrl String? @db.Text
  169. audioDuration Int @default(0)
  170. videoUrl String? @db.Text
  171. videoDuration Int?
  172. isPublic Boolean @default(false)
  173. genStage String @default("idle")
  174. lrcLyrics String? @db.Text
  175. contentCheck String? @db.Text
  176. book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
  177. comments Comment[]
  178. playRecords PlayRecord[]
  179. playlistItems PlaylistItem[]
  180. ttsTasks TtsTask[]
  181. videoProjects VideoProject[]
  182. @@unique([bookId, parentId, level, number])
  183. @@index([bookId])
  184. @@index([bookId, parentId])
  185. @@index([bookId, level])
  186. }
  187. model VideoProject {
  188. id Int @id @default(autoincrement())
  189. userId Int?
  190. title String
  191. description String?
  192. coverUrl String?
  193. configJson String? @db.LongText
  194. outputUrl String?
  195. duration Int?
  196. fileSize Int?
  197. bookId Int?
  198. chapterId Int?
  199. status String @default("draft")
  200. progress Int @default(0)
  201. errorMsg String? @db.Text
  202. createdAt DateTime @default(now())
  203. updatedAt DateTime @updatedAt
  204. book Book? @relation(fields: [bookId], references: [id])
  205. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  206. @@index([userId, status])
  207. @@index([createdAt])
  208. @@index([bookId], map: "VideoProject_bookId_fkey")
  209. @@index([chapterId], map: "VideoProject_chapterId_fkey")
  210. }
  211. model SearchHistory {
  212. id Int @id @default(autoincrement())
  213. userId Int
  214. keyword String
  215. createdAt DateTime @default(now())
  216. @@index([userId, createdAt])
  217. @@index([userId])
  218. }
  219. model HotSearch {
  220. id Int @id @default(autoincrement())
  221. keyword String
  222. count Int @default(0)
  223. sort Int @default(0)
  224. createdAt DateTime @default(now())
  225. updatedAt DateTime @updatedAt
  226. @@index([sort])
  227. @@index([count])
  228. }
  229. model SignRecord {
  230. id Int @id @default(autoincrement())
  231. userId Int
  232. createdAt DateTime @default(now())
  233. user User @relation(fields: [userId], references: [id])
  234. @@unique([userId, createdAt])
  235. @@index([userId, createdAt])
  236. }
  237. model SubscriptionPlan {
  238. id Int @id @default(autoincrement())
  239. name String
  240. level Int @default(0)
  241. priceMonthly Decimal @default(0.00) @db.Decimal(10, 2)
  242. priceYearly Decimal @default(0.00) @db.Decimal(10, 2)
  243. description String? @db.Text
  244. features String? @db.Text
  245. isRecommended Boolean @default(false)
  246. isActive Boolean @default(true)
  247. sortOrder Int @default(0)
  248. dailyGenerations Int @default(3)
  249. perGenerationLimit Int @default(2000)
  250. monthlyTokens Int @default(10000)
  251. monthlyMinutes Int @default(30)
  252. yearlyTokens Int?
  253. voiceOptions Int @default(5)
  254. audioQuality String @default("standard")
  255. apiAccess Boolean @default(false)
  256. batchProcessing Boolean @default(false)
  257. teamManagement Boolean @default(false)
  258. overageEnabled Boolean @default(false)
  259. overagePrice Decimal @default(0.000) @db.Decimal(10, 3)
  260. createdAt DateTime @default(now())
  261. updatedAt DateTime @updatedAt
  262. orders Order[]
  263. subscriptions Subscription[]
  264. @@index([level])
  265. @@index([isActive, sortOrder])
  266. }
  267. model Subscription {
  268. id Int @id @default(autoincrement())
  269. userId Int
  270. planId Int
  271. startDate DateTime
  272. endDate DateTime
  273. status String @default("active")
  274. autoRenew Boolean @default(false)
  275. createdAt DateTime @default(now())
  276. updatedAt DateTime @updatedAt
  277. plan SubscriptionPlan @relation(fields: [planId], references: [id])
  278. user User @relation(fields: [userId], references: [id])
  279. @@index([userId, status])
  280. @@index([userId, endDate])
  281. @@index([planId], map: "Subscription_planId_fkey")
  282. }
  283. model TokenUsage {
  284. id Int @id @default(autoincrement())
  285. userId Int
  286. type String
  287. amount Int @default(0)
  288. contentLength Int @default(0)
  289. orderId Int?
  290. description String? @db.Text
  291. createdAt DateTime @default(now())
  292. order Order? @relation(fields: [orderId], references: [id])
  293. user User @relation(fields: [userId], references: [id])
  294. @@index([userId, createdAt])
  295. @@index([userId, type])
  296. @@index([orderId], map: "TokenUsage_orderId_fkey")
  297. }
  298. model TokenBalance {
  299. id Int @id @default(autoincrement())
  300. userId Int @unique
  301. totalTokens Int @default(0)
  302. usedTokens Int @default(0) // 总消耗
  303. packTokens Int @default(0) // 积分包购买的Token总数
  304. usedPackTokens Int @default(0) // 积分包已消耗的Token数
  305. resetDate DateTime?
  306. createdAt DateTime @default(now())
  307. updatedAt DateTime @updatedAt
  308. user User @relation(fields: [userId], references: [id])
  309. @@index([userId])
  310. }
  311. model VideoMaterial {
  312. id Int @id @default(autoincrement())
  313. userId Int?
  314. type String
  315. name String
  316. url String @db.Text
  317. thumbnail String?
  318. tags String? @db.Text
  319. category String?
  320. duration Int?
  321. size Int?
  322. width Int?
  323. height Int?
  324. createdAt DateTime @default(now())
  325. updatedAt DateTime @updatedAt
  326. @@index([userId, type])
  327. @@index([type, category])
  328. }
  329. model AudioRecord {
  330. id Int @id @default(autoincrement())
  331. userId Int?
  332. audioId String @unique
  333. title String @default("未命名音频")
  334. text String? @db.LongText
  335. wordCount Int @default(0)
  336. voiceId String @default("cherry")
  337. voiceParams String?
  338. audioUrl String? @db.Text
  339. audioDuration Int @default(0)
  340. audioSize Int @default(0)
  341. status String @default("processing")
  342. errorMsg String? @db.Text
  343. createdAt DateTime @default(now())
  344. updatedAt DateTime @updatedAt
  345. bookId Int?
  346. provider String? // TTS 供应商: bailian / edge / mock
  347. @@index([userId])
  348. @@index([audioId])
  349. @@index([bookId])
  350. }
  351. model TtsTask {
  352. id Int @id @default(autoincrement())
  353. taskType String @default("tts") @db.VarChar(20) // "tts" | "content"
  354. chapterId Int
  355. bookId Int?
  356. userId Int?
  357. contentHash String @db.VarChar(64)
  358. content String? @db.LongText
  359. status String @default("pending")
  360. audioUrl String? @db.Text
  361. audioDuration Int @default(0)
  362. errorMsg String? @db.Text
  363. retryCount Int @default(0)
  364. maxRetries Int @default(3)
  365. voiceId String @default("default")
  366. voiceSpeed Float @default(1.0)
  367. startedAt DateTime?
  368. completedAt DateTime?
  369. createdAt DateTime @default(now())
  370. updatedAt DateTime @updatedAt
  371. chapter BookChapter @relation(fields: [chapterId], references: [id], onDelete: Cascade)
  372. @@index([taskType, status, createdAt])
  373. @@index([chapterId, contentHash])
  374. @@index([contentHash, chapterId])
  375. }
  376. model AiCallLog {
  377. id Int @id @default(autoincrement())
  378. callType String @db.VarChar(20) // llm_chat | llm_tools | tts_synthesize | tts_create | tts_poll
  379. provider String @db.VarChar(30) // minimax | bailian | volcengine
  380. model String @db.VarChar(50) // MiniMax-M2.7 | cosyvoice-v3-flash | qwen3-tts-instruct-flash
  381. userId Int?
  382. bookId Int?
  383. chapterId Int?
  384. textLen Int @default(0) // 输入文本长度(字符数)
  385. prompt String? @db.LongText // 提示词内容(LLM only)
  386. inputTokens Int @default(0) // 输入 Token 数
  387. outputTokens Int @default(0) // 输出 Token 数
  388. estimatedCost Float @default(0) // 估算成本(元)
  389. duration Int @default(0) // 耗时(ms)
  390. success Boolean @default(true)
  391. errorMsg String? @db.Text
  392. createdAt DateTime @default(now())
  393. @@index([callType, createdAt])
  394. @@index([provider, createdAt])
  395. @@index([userId, createdAt])
  396. @@index([bookId])
  397. @@index([createdAt])
  398. }
  399. model PlatformAccount {
  400. id Int @id @default(autoincrement())
  401. userId Int
  402. platform String
  403. nickname String @default("")
  404. avatar String @default("")
  405. cookies String @db.Text
  406. headers String? @db.Text
  407. isValid Boolean @default(true)
  408. expireTime DateTime?
  409. createdAt DateTime @default(now())
  410. updatedAt DateTime @updatedAt
  411. @@unique([userId, platform])
  412. @@index([userId])
  413. @@index([platform])
  414. }
  415. model PublishTask {
  416. id Int @id @default(autoincrement())
  417. userId Int
  418. videoProjectId Int
  419. platform String
  420. title String @db.Text
  421. description String? @db.Text
  422. tags String? @db.Text
  423. coverUrl String? @db.Text
  424. videoUrl String? @db.Text
  425. status String @default("pending")
  426. errorMsg String? @db.Text
  427. publishedUrl String? @db.Text
  428. createdAt DateTime @default(now())
  429. updatedAt DateTime @updatedAt
  430. @@index([userId, platform])
  431. @@index([status])
  432. }
  433. model Draft {
  434. id Int @id @default(autoincrement())
  435. userId Int
  436. type String
  437. title String? @db.Text
  438. content String? @db.LongText
  439. metadata String? @db.Text
  440. autoSavedAt DateTime?
  441. createdAt DateTime @default(now())
  442. updatedAt DateTime @updatedAt
  443. user User @relation(fields: [userId], references: [id])
  444. @@index([userId, type])
  445. @@index([userId, updatedAt])
  446. }
  447. model Playlist {
  448. id Int @id @default(autoincrement())
  449. userId Int
  450. name String
  451. description String? @db.Text
  452. createdAt DateTime @default(now())
  453. updatedAt DateTime @updatedAt
  454. user User @relation(fields: [userId], references: [id])
  455. items PlaylistItem[]
  456. @@index([userId])
  457. }
  458. model PlaylistItem {
  459. id Int @id @default(autoincrement())
  460. playlistId Int
  461. chapterId Int?
  462. audioId String?
  463. order Int @default(0)
  464. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  465. playlist Playlist @relation(fields: [playlistId], references: [id], onDelete: Cascade)
  466. @@index([playlistId, order])
  467. @@index([chapterId], map: "PlaylistItem_chapterId_fkey")
  468. }
  469. model Feedback {
  470. id String @id @default(uuid())
  471. type String
  472. title String @db.Text
  473. content String @db.Text
  474. contact String @db.Text
  475. screenshotUrls String @db.Text
  476. status String @default("submitted")
  477. createdAt DateTime @default(now())
  478. updatedAt DateTime @updatedAt
  479. @@index([type])
  480. @@index([status])
  481. @@index([createdAt])
  482. }
  483. model ShareRecord {
  484. id Int @id @default(autoincrement())
  485. userId Int
  486. audioId Int
  487. platform String
  488. shareCode String
  489. rewarded Boolean @default(false)
  490. createdAt DateTime @default(now())
  491. user User @relation(fields: [userId], references: [id])
  492. @@index([userId])
  493. @@index([shareCode])
  494. @@index([createdAt])
  495. }
  496. model InviteRecord {
  497. id Int @id @default(autoincrement())
  498. inviterId Int
  499. inviteeId Int @unique
  500. shareCode String?
  501. rewarded Boolean @default(false)
  502. rewardAmount Int @default(10000)
  503. createdAt DateTime @default(now())
  504. inviter User @relation("InviterRelation", fields: [inviterId], references: [id])
  505. invitee User @relation("InviteeRelation", fields: [inviteeId], references: [id])
  506. @@index([inviterId])
  507. @@index([shareCode])
  508. }
  509. model TokenPackPurchase {
  510. id Int @id @default(autoincrement())
  511. userId Int
  512. packMinutes Int
  513. quantity Int
  514. unitPrice Float
  515. totalAmount Float
  516. addedQuota Float
  517. createdAt DateTime @default(now())
  518. }