point_tables.sql 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. -- Point模块数据库表结构
  2. -- 专注于整数型积分逻辑处理
  3. -- 积分类型表
  4. CREATE TABLE `kku_point_currency` (
  5. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增',
  6. `identification` varchar(50) NOT NULL DEFAULT '' COMMENT '积分标识',
  7. `type` int(11) NOT NULL DEFAULT '0' COMMENT '积分类型,关联POINT_CURRENCY_TYPE枚举',
  8. `icon` varchar(100) NOT NULL DEFAULT '' COMMENT '积分图标',
  9. `name` varchar(100) NOT NULL DEFAULT '' COMMENT '积分名称',
  10. `display_attributes` text COMMENT '显示属性,如图标、颜色等',
  11. `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  12. `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  13. PRIMARY KEY (`id`),
  14. UNIQUE KEY `uk_identification` (`identification`),
  15. UNIQUE KEY `uk_type` (`type`),
  16. KEY `idx_create_time` (`create_time`)
  17. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分类型表';
  18. -- 积分配置表
  19. CREATE TABLE `kku_point_config` (
  20. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增',
  21. `name` varchar(100) NOT NULL DEFAULT '' COMMENT '积分名称',
  22. `currency_id` int(11) NOT NULL DEFAULT '0' COMMENT '关联的积分类型ID,外键关联kku_point_currency表',
  23. `type` int(11) NOT NULL DEFAULT '0' COMMENT '积分账户类型,关联POINT_TYPE枚举',
  24. `display_attributes` text COMMENT '显示属性,如图标、颜色等',
  25. `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  26. `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  27. PRIMARY KEY (`id`),
  28. UNIQUE KEY `uk_type` (`type`),
  29. KEY `idx_currency_id` (`currency_id`),
  30. KEY `idx_create_time` (`create_time`)
  31. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分配置表';
  32. -- 用户积分表
  33. CREATE TABLE `kku_point` (
  34. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增',
  35. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
  36. `point_id` int(11) NOT NULL DEFAULT '0' COMMENT '积分类型ID',
  37. `balance` bigint(20) NOT NULL DEFAULT '0' COMMENT '积分余额(整数)',
  38. `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  39. `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  40. PRIMARY KEY (`id`),
  41. UNIQUE KEY `uk_user_point` (`user_id`, `point_id`),
  42. KEY `idx_user_id` (`user_id`),
  43. KEY `idx_point_id` (`point_id`),
  44. KEY `idx_balance` (`balance`),
  45. KEY `idx_update_time` (`update_time`)
  46. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户积分表';
  47. -- 积分日志表
  48. CREATE TABLE `kku_point_logs` (
  49. `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增',
  50. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
  51. `point_id` int(11) NOT NULL DEFAULT '0' COMMENT '积分类型ID',
  52. `amount` bigint(20) NOT NULL DEFAULT '0' COMMENT '操作积分数量,正值为收入,负值为支出',
  53. `operate_id` varchar(100) NOT NULL DEFAULT '' COMMENT '上游操作ID',
  54. `operate_type` int(11) NOT NULL DEFAULT '0' COMMENT '上游操作类型',
  55. `remark` varchar(500) NOT NULL DEFAULT '' COMMENT '备注',
  56. `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  57. `create_ip` varchar(50) NOT NULL DEFAULT '' COMMENT '创建IP',
  58. `later_balance` bigint(20) NOT NULL DEFAULT '0' COMMENT '操作后余额',
  59. `before_balance` bigint(20) NOT NULL DEFAULT '0' COMMENT '操作前余额',
  60. `date_key` int(11) NOT NULL DEFAULT '0' COMMENT '日期key(用于分表)',
  61. `hash` varchar(100) NOT NULL DEFAULT '' COMMENT '防篡改哈希值',
  62. `prev_hash` varchar(100) NOT NULL DEFAULT '' COMMENT '上一条记录的哈希值',
  63. PRIMARY KEY (`id`),
  64. KEY `idx_user_id` (`user_id`),
  65. KEY `idx_point_id` (`point_id`),
  66. KEY `idx_operate_type` (`operate_type`),
  67. KEY `idx_create_time` (`create_time`),
  68. KEY `idx_date_key` (`date_key`),
  69. KEY `idx_user_point_time` (`user_id`, `point_id`, `create_time`)
  70. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分日志表';
  71. -- 积分管理表
  72. CREATE TABLE `kku_point_admin` (
  73. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增',
  74. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
  75. `point_id` int(11) NOT NULL DEFAULT '0' COMMENT '积分类型ID',
  76. `admin_id` int(11) NOT NULL DEFAULT '0' COMMENT '管理员ID',
  77. `total_points` bigint(20) NOT NULL DEFAULT '0' COMMENT '操作积分数量',
  78. `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态:0-待处理,1-已完成,2-已失败',
  79. `remark` varchar(500) NOT NULL DEFAULT '' COMMENT '备注',
  80. `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  81. `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  82. PRIMARY KEY (`id`),
  83. KEY `idx_user_id` (`user_id`),
  84. KEY `idx_point_id` (`point_id`),
  85. KEY `idx_admin_id` (`admin_id`),
  86. KEY `idx_status` (`status`),
  87. KEY `idx_create_time` (`create_time`)
  88. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分管理表';
  89. -- 积分流转记录表
  90. CREATE TABLE `kku_point_circulation` (
  91. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增',
  92. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
  93. `from_point_id` int(11) NOT NULL DEFAULT '0' COMMENT '源积分类型ID',
  94. `to_point_id` int(11) NOT NULL DEFAULT '0' COMMENT '目标积分类型ID',
  95. `amount` bigint(20) NOT NULL DEFAULT '0' COMMENT '流转积分数量',
  96. `re_id` int(11) NOT NULL DEFAULT '0' COMMENT '关联ID',
  97. `re_type` varchar(50) NOT NULL DEFAULT '' COMMENT '关联类型',
  98. `remark` varchar(500) NOT NULL DEFAULT '' COMMENT '备注',
  99. `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态:0-待处理,1-已完成,2-已失败',
  100. `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  101. `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  102. PRIMARY KEY (`id`),
  103. KEY `idx_user_id` (`user_id`),
  104. KEY `idx_from_point_id` (`from_point_id`),
  105. KEY `idx_to_point_id` (`to_point_id`),
  106. KEY `idx_status` (`status`),
  107. KEY `idx_create_time` (`create_time`),
  108. KEY `idx_re_id_type` (`re_id`, `re_type`)
  109. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分流转记录表';
  110. -- 积分转账记录表
  111. CREATE TABLE `kku_point_transfer` (
  112. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增',
  113. `from_user_id` int(11) NOT NULL DEFAULT '0' COMMENT '转出用户ID',
  114. `to_user_id` int(11) NOT NULL DEFAULT '0' COMMENT '转入用户ID',
  115. `point_id` int(11) NOT NULL DEFAULT '0' COMMENT '积分类型ID',
  116. `amount` bigint(20) NOT NULL DEFAULT '0' COMMENT '转账积分数量',
  117. `remark` varchar(500) NOT NULL DEFAULT '' COMMENT '备注',
  118. `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态:0-待处理,1-已完成,2-已失败',
  119. `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  120. `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  121. PRIMARY KEY (`id`),
  122. KEY `idx_from_user_id` (`from_user_id`),
  123. KEY `idx_to_user_id` (`to_user_id`),
  124. KEY `idx_point_id` (`point_id`),
  125. KEY `idx_status` (`status`),
  126. KEY `idx_create_time` (`create_time`)
  127. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分转账记录表';
  128. -- 积分订单表
  129. CREATE TABLE `kku_point_order` (
  130. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增',
  131. `order_no` varchar(50) NOT NULL DEFAULT '' COMMENT '订单号',
  132. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
  133. `point_id` int(11) NOT NULL DEFAULT '0' COMMENT '积分类型ID',
  134. `amount` bigint(20) NOT NULL DEFAULT '0' COMMENT '积分数量',
  135. `order_type` varchar(50) NOT NULL DEFAULT '' COMMENT '订单类型',
  136. `title` varchar(200) NOT NULL DEFAULT '' COMMENT '订单标题',
  137. `description` varchar(500) NOT NULL DEFAULT '' COMMENT '订单描述',
  138. `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '订单状态',
  139. `extra_data` text COMMENT '额外数据(JSON格式)',
  140. `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  141. `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  142. PRIMARY KEY (`id`),
  143. UNIQUE KEY `uk_order_no` (`order_no`),
  144. KEY `idx_user_id` (`user_id`),
  145. KEY `idx_point_id` (`point_id`),
  146. KEY `idx_order_type` (`order_type`),
  147. KEY `idx_status` (`status`),
  148. KEY `idx_create_time` (`create_time`)
  149. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分订单表';
  150. -- 插入初始数据
  151. -- 积分类型数据
  152. INSERT INTO `kku_point_currency` (`id`, `identification`, `type`, `icon`, `name`, `display_attributes`, `create_time`, `update_time`) VALUES
  153. (1, 'EXP', 1, '⭐', '经验积分', '{"icon":"⭐","color":"#1890ff","background":"#f0f9ff"}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  154. (2, 'ACHIEVEMENT', 2, '🏆', '成就积分', '{"icon":"🏆","color":"#52c41a","background":"#f6ffed"}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  155. (3, 'ACTIVITY', 3, '🎯', '活动积分', '{"icon":"🎯","color":"#fa8c16","background":"#fff7e6"}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  156. (4, 'CHECKIN', 4, '📅', '签到积分', '{"icon":"📅","color":"#722ed1","background":"#f9f0ff"}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  157. (5, 'REFERRAL', 5, '👥', '推荐积分', '{"icon":"👥","color":"#eb2f96","background":"#fff0f6"}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
  158. -- 积分配置数据
  159. INSERT INTO `kku_point_config` (`id`, `name`, `currency_id`, `type`, `display_attributes`, `create_time`, `update_time`) VALUES
  160. (1, '经验积分账户', 1, 1, '{"icon":"⭐","color":"#1890ff","show_in_list":true}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  161. (2, '成就积分账户', 2, 2, '{"icon":"🏆","color":"#52c41a","show_in_list":true}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  162. (3, '活动积分账户', 3, 3, '{"icon":"🎯","color":"#fa8c16","show_in_list":true}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  163. (4, '签到积分账户', 4, 4, '{"icon":"📅","color":"#722ed1","show_in_list":true}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  164. (5, '推荐积分账户', 5, 5, '{"icon":"👥","color":"#eb2f96","show_in_list":true}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP());