ps_schema.sql 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. -- 生产流程单云平台 · 工厂租户与核心业务表
  2. -- 表前缀 fa_ ,字符集 utf8mb4
  3. -- ----------------------------
  4. -- 工厂
  5. -- ----------------------------
  6. CREATE TABLE IF NOT EXISTS `fa_ps_factory` (
  7. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  8. `name` varchar(100) NOT NULL DEFAULT '' COMMENT '工厂名称',
  9. `code` varchar(32) NOT NULL DEFAULT '' COMMENT '工厂编码',
  10. `invite_code` varchar(16) NOT NULL DEFAULT '' COMMENT '邀请码',
  11. `logo` varchar(255) NOT NULL DEFAULT '' COMMENT 'Logo',
  12. `contact` varchar(50) NOT NULL DEFAULT '' COMMENT '联系人',
  13. `mobile` varchar(20) NOT NULL DEFAULT '' COMMENT '电话',
  14. `address` varchar(255) NOT NULL DEFAULT '' COMMENT '地址',
  15. `score` int(10) NOT NULL DEFAULT '0' COMMENT '工厂积分',
  16. `owner_user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '负责人会员ID',
  17. `status` enum('normal','hidden','locked') NOT NULL DEFAULT 'normal' COMMENT '状态',
  18. `createtime` bigint(16) DEFAULT NULL COMMENT '创建时间',
  19. `updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间',
  20. PRIMARY KEY (`id`),
  21. UNIQUE KEY `invite_code` (`invite_code`),
  22. KEY `owner_user_id` (`owner_user_id`),
  23. KEY `status` (`status`)
  24. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-工厂';
  25. -- ----------------------------
  26. -- 会员入厂
  27. -- ----------------------------
  28. ALTER TABLE `fa_user`
  29. ADD COLUMN `factory_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '所属工厂' AFTER `group_id`,
  30. ADD COLUMN `factory_role` varchar(20) NOT NULL DEFAULT '' COMMENT 'owner=管理员,operator=操作员' AFTER `factory_id`;
  31. ALTER TABLE `fa_user` ADD INDEX `factory_id` (`factory_id`);
  32. -- ----------------------------
  33. -- 工厂积分流水
  34. -- ----------------------------
  35. CREATE TABLE IF NOT EXISTS `fa_ps_factory_score_log` (
  36. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  37. `factory_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '工厂ID',
  38. `operator_user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '操作人',
  39. `score` int(10) NOT NULL DEFAULT '0' COMMENT '变更积分',
  40. `before` int(10) NOT NULL DEFAULT '0' COMMENT '变更前',
  41. `after` int(10) NOT NULL DEFAULT '0' COMMENT '变更后',
  42. `biz_type` varchar(32) NOT NULL DEFAULT '' COMMENT '业务类型',
  43. `biz_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '业务ID',
  44. `memo` varchar(255) NOT NULL DEFAULT '' COMMENT '备注',
  45. `createtime` bigint(16) DEFAULT NULL COMMENT '创建时间',
  46. PRIMARY KEY (`id`),
  47. KEY `factory_id` (`factory_id`)
  48. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-工厂积分流水';
  49. -- ----------------------------
  50. -- 可绑定字段字典
  51. -- ----------------------------
  52. CREATE TABLE IF NOT EXISTS `fa_ps_field_dict` (
  53. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  54. `group` varchar(32) NOT NULL DEFAULT '' COMMENT 'product/workorder/process/user/print',
  55. `name` varchar(64) NOT NULL DEFAULT '' COMMENT '绑定键,如 product.name',
  56. `title` varchar(64) NOT NULL DEFAULT '' COMMENT '显示名',
  57. `weigh` int(10) NOT NULL DEFAULT '0' COMMENT '权重',
  58. `status` enum('normal','hidden') NOT NULL DEFAULT 'normal',
  59. PRIMARY KEY (`id`),
  60. UNIQUE KEY `name` (`name`)
  61. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-字段字典';
  62. -- ----------------------------
  63. -- 模板
  64. -- ----------------------------
  65. CREATE TABLE IF NOT EXISTS `fa_ps_template` (
  66. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  67. `factory_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '0=官方模板',
  68. `creator_user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建人',
  69. `name` varchar(100) NOT NULL DEFAULT '' COMMENT '模板名称',
  70. `cover` varchar(255) NOT NULL DEFAULT '' COMMENT '封面',
  71. `paper_size` varchar(20) NOT NULL DEFAULT 'A4' COMMENT 'A4/A5/custom',
  72. `page_w` decimal(8,2) NOT NULL DEFAULT '210.00' COMMENT '纸宽毫米',
  73. `page_h` decimal(8,2) NOT NULL DEFAULT '297.00' COMMENT '纸高毫米',
  74. `mark_cover` varchar(255) NOT NULL DEFAULT '' COMMENT '色块标注图',
  75. `source` varchar(20) NOT NULL DEFAULT 'manual' COMMENT 'manual/ai/system/market',
  76. `license_type` varchar(20) NOT NULL DEFAULT 'self' COMMENT 'self/system_copy/market_single/market_buyout',
  77. `locked` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '单次授权确认套打后锁定',
  78. `locked_time` bigint(16) DEFAULT NULL COMMENT '锁定时间',
  79. `source_template_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '复制/购买来源',
  80. `source_version_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '来源版本',
  81. `current_version_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '当前版本',
  82. `is_system` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '官方模板',
  83. `status` enum('normal','hidden') NOT NULL DEFAULT 'normal',
  84. `createtime` bigint(16) DEFAULT NULL,
  85. `updatetime` bigint(16) DEFAULT NULL,
  86. PRIMARY KEY (`id`),
  87. KEY `factory_id` (`factory_id`),
  88. KEY `license_locked` (`factory_id`,`license_type`,`locked`)
  89. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-模板';
  90. CREATE TABLE IF NOT EXISTS `fa_ps_template_version` (
  91. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  92. `template_id` int(10) unsigned NOT NULL DEFAULT '0',
  93. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  94. `version` int(10) unsigned NOT NULL DEFAULT '1',
  95. `schema_json` longtext COMMENT '排版JSON',
  96. `remark` varchar(255) NOT NULL DEFAULT '',
  97. `createtime` bigint(16) DEFAULT NULL,
  98. PRIMARY KEY (`id`),
  99. KEY `template_id` (`template_id`)
  100. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-模板版本';
  101. -- ----------------------------
  102. -- AI 识版任务
  103. -- ----------------------------
  104. CREATE TABLE IF NOT EXISTS `fa_ps_ai_job` (
  105. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  106. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  107. `user_id` int(10) unsigned NOT NULL DEFAULT '0',
  108. `file_url` varchar(255) NOT NULL DEFAULT '',
  109. `file_type` varchar(20) NOT NULL DEFAULT '' COMMENT 'image/pdf',
  110. `status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT 'pending/running/success/fail',
  111. `model` varchar(64) NOT NULL DEFAULT '' COMMENT '实际使用的模型',
  112. `raw_text` longtext COMMENT '模型原文',
  113. `schema_json` longtext COMMENT '解析后的草稿',
  114. `error_msg` varchar(500) NOT NULL DEFAULT '',
  115. `template_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '确认入库后的模板',
  116. `createtime` bigint(16) DEFAULT NULL,
  117. `updatetime` bigint(16) DEFAULT NULL,
  118. PRIMARY KEY (`id`),
  119. KEY `factory_id` (`factory_id`),
  120. KEY `status` (`status`)
  121. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-AI识版任务';
  122. -- ----------------------------
  123. -- 产品 / 工序
  124. -- ----------------------------
  125. CREATE TABLE IF NOT EXISTS `fa_ps_product` (
  126. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  127. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  128. `creator_user_id` int(10) unsigned NOT NULL DEFAULT '0',
  129. `code` varchar(64) NOT NULL DEFAULT '' COMMENT '产品编码',
  130. `name` varchar(100) NOT NULL DEFAULT '' COMMENT '产品名称',
  131. `spec` varchar(100) NOT NULL DEFAULT '' COMMENT '规格',
  132. `unit` varchar(20) NOT NULL DEFAULT '' COMMENT '单位',
  133. `qty` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '总数量',
  134. `sheet_qty` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '每版数量,一版一张流程单',
  135. `remark` varchar(255) NOT NULL DEFAULT '',
  136. `status` enum('normal','hidden') NOT NULL DEFAULT 'normal',
  137. `createtime` bigint(16) DEFAULT NULL,
  138. `updatetime` bigint(16) DEFAULT NULL,
  139. PRIMARY KEY (`id`),
  140. UNIQUE KEY `factory_code` (`factory_id`,`code`)
  141. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-产品';
  142. CREATE TABLE IF NOT EXISTS `fa_ps_product_process` (
  143. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  144. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  145. `product_id` int(10) unsigned NOT NULL DEFAULT '0',
  146. `seq` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '序号',
  147. `name` varchar(100) NOT NULL DEFAULT '' COMMENT '工序名',
  148. `workstation` varchar(64) NOT NULL DEFAULT '' COMMENT '工位',
  149. `standard_time` varchar(32) NOT NULL DEFAULT '' COMMENT '标准工时',
  150. `params` text COMMENT '工艺参数',
  151. `qc_points` text COMMENT '质检要点',
  152. `remark` varchar(255) NOT NULL DEFAULT '',
  153. PRIMARY KEY (`id`),
  154. KEY `product_id` (`product_id`),
  155. KEY `factory_id` (`factory_id`)
  156. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-产品工序';
  157. -- ----------------------------
  158. -- 工单 / 工序
  159. -- ----------------------------
  160. CREATE TABLE IF NOT EXISTS `fa_ps_workorder` (
  161. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  162. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  163. `creator_user_id` int(10) unsigned NOT NULL DEFAULT '0',
  164. `no` varchar(64) NOT NULL DEFAULT '' COMMENT '工单号',
  165. `product_id` int(10) unsigned NOT NULL DEFAULT '0',
  166. `product_name` varchar(100) NOT NULL DEFAULT '' COMMENT '产品名称,可不关联产品档案',
  167. `qty` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '总数量',
  168. `sheet_qty` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '每版数量,一版一张流程单',
  169. `batch_no` varchar(64) NOT NULL DEFAULT '' COMMENT '批次',
  170. `plan_date` date DEFAULT NULL COMMENT '计划日期',
  171. `customer` varchar(100) NOT NULL DEFAULT '' COMMENT '客户',
  172. `remark` varchar(255) NOT NULL DEFAULT '',
  173. `status` varchar(20) NOT NULL DEFAULT 'draft' COMMENT 'draft/doing/done/cancel',
  174. `createtime` bigint(16) DEFAULT NULL,
  175. `updatetime` bigint(16) DEFAULT NULL,
  176. PRIMARY KEY (`id`),
  177. UNIQUE KEY `factory_no` (`factory_id`,`no`),
  178. KEY `product_id` (`product_id`)
  179. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-工单';
  180. CREATE TABLE IF NOT EXISTS `fa_ps_workorder_process` (
  181. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  182. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  183. `workorder_id` int(10) unsigned NOT NULL DEFAULT '0',
  184. `seq` int(10) unsigned NOT NULL DEFAULT '0',
  185. `name` varchar(100) NOT NULL DEFAULT '',
  186. `workstation` varchar(64) NOT NULL DEFAULT '',
  187. `standard_time` varchar(32) NOT NULL DEFAULT '',
  188. `params` text,
  189. `qc_points` text,
  190. `remark` varchar(255) NOT NULL DEFAULT '',
  191. PRIMARY KEY (`id`),
  192. KEY `workorder_id` (`workorder_id`),
  193. KEY `factory_id` (`factory_id`)
  194. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-工单工序';
  195. -- ----------------------------
  196. -- 打印任务 / 快照
  197. -- ----------------------------
  198. CREATE TABLE IF NOT EXISTS `fa_ps_print_job` (
  199. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  200. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  201. `operator_user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '操作员',
  202. `print_no` varchar(40) NOT NULL DEFAULT '' COMMENT '打印流水号',
  203. `biz_type` varchar(20) NOT NULL DEFAULT 'workorder' COMMENT 'product/workorder',
  204. `biz_id` int(10) unsigned NOT NULL DEFAULT '0',
  205. `template_id` int(10) unsigned NOT NULL DEFAULT '0',
  206. `template_version_id` int(10) unsigned NOT NULL DEFAULT '0',
  207. `copies` int(10) unsigned NOT NULL DEFAULT '1',
  208. `lodop_mode` varchar(20) NOT NULL DEFAULT 'preview' COMMENT 'preview/print',
  209. `status` varchar(20) NOT NULL DEFAULT 'previewed' COMMENT 'previewed/printed/canceled',
  210. `createtime` bigint(16) DEFAULT NULL,
  211. PRIMARY KEY (`id`),
  212. UNIQUE KEY `print_no` (`print_no`),
  213. KEY `factory_id` (`factory_id`)
  214. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-打印任务';
  215. CREATE TABLE IF NOT EXISTS `fa_ps_print_snapshot` (
  216. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  217. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  218. `print_job_id` int(10) unsigned NOT NULL DEFAULT '0',
  219. `fill_json` longtext COMMENT '填充后的数据',
  220. `schema_json` longtext COMMENT '当时模板schema',
  221. `lodop_html` longtext COMMENT '下发给Lodop的HTML',
  222. PRIMARY KEY (`id`),
  223. KEY `print_job_id` (`print_job_id`)
  224. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-打印快照';
  225. -- ----------------------------
  226. -- 商城
  227. -- ----------------------------
  228. CREATE TABLE IF NOT EXISTS `fa_ps_market_goods` (
  229. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  230. `factory_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '卖家工厂',
  231. `seller_user_id` int(10) unsigned NOT NULL DEFAULT '0',
  232. `template_id` int(10) unsigned NOT NULL DEFAULT '0',
  233. `template_version_id` int(10) unsigned NOT NULL DEFAULT '0',
  234. `title` varchar(100) NOT NULL DEFAULT '',
  235. `cover` varchar(255) NOT NULL DEFAULT '',
  236. `category` varchar(50) NOT NULL DEFAULT '',
  237. `intro` text,
  238. `price_single` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单次积分价',
  239. `price_buyout` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '买断积分价',
  240. `status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT 'pending/on_sale/rejected/off',
  241. `createtime` bigint(16) DEFAULT NULL,
  242. `updatetime` bigint(16) DEFAULT NULL,
  243. PRIMARY KEY (`id`),
  244. KEY `status` (`status`),
  245. KEY `factory_id` (`factory_id`)
  246. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-模板商品';
  247. CREATE TABLE IF NOT EXISTS `fa_ps_market_order` (
  248. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  249. `order_no` varchar(40) NOT NULL DEFAULT '',
  250. `goods_id` int(10) unsigned NOT NULL DEFAULT '0',
  251. `license_type` varchar(20) NOT NULL DEFAULT 'single' COMMENT 'single/buyout',
  252. `score` int(10) unsigned NOT NULL DEFAULT '0',
  253. `buyer_factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  254. `buyer_user_id` int(10) unsigned NOT NULL DEFAULT '0',
  255. `seller_factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  256. `copy_template_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '买方副本模板',
  257. `status` varchar(20) NOT NULL DEFAULT 'paid',
  258. `createtime` bigint(16) DEFAULT NULL,
  259. PRIMARY KEY (`id`),
  260. UNIQUE KEY `order_no` (`order_no`),
  261. KEY `buyer_factory_id` (`buyer_factory_id`)
  262. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-模板订单';
  263. CREATE TABLE IF NOT EXISTS `fa_ps_market_license` (
  264. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  265. `factory_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '买方工厂',
  266. `order_id` int(10) unsigned NOT NULL DEFAULT '0',
  267. `template_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '买方副本',
  268. `license_type` varchar(20) NOT NULL DEFAULT 'single',
  269. `remain_times` int(10) NOT NULL DEFAULT '1' COMMENT '单次=1,买断=-1',
  270. `locked` tinyint(1) unsigned NOT NULL DEFAULT '0',
  271. `used_time` bigint(16) DEFAULT NULL,
  272. `createtime` bigint(16) DEFAULT NULL,
  273. PRIMARY KEY (`id`),
  274. KEY `factory_id` (`factory_id`),
  275. KEY `template_id` (`template_id`)
  276. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-模板授权';
  277. -- ----------------------------
  278. -- 支付预留(不实现渠道)
  279. -- ----------------------------
  280. CREATE TABLE IF NOT EXISTS `fa_ps_pay_order` (
  281. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  282. `factory_id` int(10) unsigned NOT NULL DEFAULT '0',
  283. `user_id` int(10) unsigned NOT NULL DEFAULT '0',
  284. `pay_no` varchar(40) NOT NULL DEFAULT '',
  285. `channel` varchar(20) NOT NULL DEFAULT '' COMMENT 'wechat/alipay,预留',
  286. `amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  287. `score` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '拟充值积分',
  288. `status` varchar(20) NOT NULL DEFAULT 'created' COMMENT 'created/paid/closed',
  289. `notify_payload` text,
  290. `createtime` bigint(16) DEFAULT NULL,
  291. `updatetime` bigint(16) DEFAULT NULL,
  292. PRIMARY KEY (`id`),
  293. UNIQUE KEY `pay_no` (`pay_no`),
  294. KEY `factory_id` (`factory_id`)
  295. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='流程单-支付单预留';