ps_schema.sql 16 KB

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