brokerage.sql 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. -- 增加配置表
  2. create table trade_config
  3. (
  4. id bigint auto_increment comment '自增主键' primary key,
  5. brokerage_enabled bit default 1 not null comment '是否启用分佣',
  6. brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:1-人人分销 2-指定分销',
  7. brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖',
  8. brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组',
  9. brokerage_first_percent int default 0 not null comment '一级返佣比例',
  10. brokerage_second_percent int default 0 not null comment '二级返佣比例',
  11. brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额',
  12. brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)',
  13. brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)',
  14. brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝',
  15. creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者',
  16. create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
  17. updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者',
  18. update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
  19. deleted bit default b'0' not null comment '是否删除',
  20. tenant_id bigint default 0 not null comment '租户编号'
  21. ) comment '交易中心配置';
  22. -- 增加分销用户扩展表
  23. create table trade_brokerage_user
  24. (
  25. id bigint auto_increment comment '用户编号' primary key,
  26. bind_user_id bigint null comment '推广员编号',
  27. bind_user_time datetime null comment '推广员绑定时间',
  28. brokerage_enabled bit default 1 not null comment '是否成为推广员',
  29. brokerage_time datetime null comment '成为分销员时间',
  30. price int default 0 not null comment '可用佣金',
  31. frozen_price int default 0 not null comment '冻结佣金',
  32. creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者',
  33. create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
  34. updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者',
  35. update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
  36. deleted bit default b'0' not null comment '是否删除',
  37. tenant_id bigint default 0 not null comment '租户编号'
  38. ) comment '分销用户';
  39. create index idx_invite_user_id on trade_brokerage_user (bind_user_id) comment '推广员编号';
  40. create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是否成为推广员';
  41. create table trade_brokerage_record
  42. (
  43. id int auto_increment comment '编号'
  44. primary key,
  45. user_id bigint not null comment '用户编号',
  46. biz_id varchar(64) default '' not null comment '业务编号',
  47. biz_type tinyint default 0 not null comment '业务类型:1-订单,2-提现',
  48. title varchar(64) default '' not null comment '标题',
  49. price int default 0 not null comment '金额',
  50. total_price int default 0 not null comment '当前总佣金',
  51. description varchar(500) default '' not null comment '说明',
  52. status tinyint default 0 not null comment '状态:0-待结算,1-已结算,2-已取消',
  53. frozen_days int default 0 not null comment '冻结时间(天)',
  54. unfreeze_time datetime null comment '解冻时间',
  55. source_user_type tinyint not null comment '来源用户类型:1-一级推广用户,2-二级推广用户',
  56. source_user_id bigint not null comment '来源用户编号',
  57. creator varchar(64) collate utf8mb4_general_ci default '' null comment '创建者',
  58. create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
  59. updater varchar(64) collate utf8mb4_general_ci default '' null comment '更新者',
  60. update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
  61. deleted bit default b'0' not null comment '是否删除',
  62. tenant_id bigint default 0 not null comment '租户编号'
  63. )
  64. comment '佣金记录';
  65. create index idx_user_id on trade_brokerage_record (user_id) comment '用户编号';
  66. create index idx_biz on trade_brokerage_record (biz_type, biz_id) comment '业务';
  67. create index idx_status on trade_brokerage_record (status) comment '状态';
  68. create table trade_brokerage_withdraw
  69. (
  70. id int auto_increment comment '编号'
  71. primary key,
  72. user_id bigint not null comment '用户编号',
  73. price int default 0 not null comment '提现金额',
  74. fee_price int default 0 not null comment '提现手续费',
  75. total_price int default 0 not null comment '当前总佣金',
  76. type tinyint default 0 not null comment '提现类型:1-钱包;2-银行卡;3-微信;4-支付宝',
  77. name varchar(64) null comment '真实姓名',
  78. account_no varchar(64) null comment '账号',
  79. bank_name varchar(100) null comment '银行名称',
  80. bank_address varchar(200) null comment '开户地址',
  81. account_qr_code_url varchar(512) null comment '收款码',
  82. status tinyint(2) default 0 not null comment '状态:0-审核中,10-审核通过 20-审核不通过;预留:11 - 提现成功;21-提现失败',
  83. audit_reason varchar(128) null comment '审核驳回原因',
  84. audit_time datetime null comment '审核时间',
  85. remark varchar(500) null comment '备注',
  86. creator varchar(64) collate utf8mb4_general_ci default '' null comment '创建者',
  87. create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
  88. updater varchar(64) collate utf8mb4_general_ci default '' null comment '更新者',
  89. update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
  90. deleted bit default b'0' not null comment '是否删除',
  91. tenant_id bigint default 0 not null comment '租户编号'
  92. )
  93. comment '佣金提现';
  94. create index idx_user_id on trade_brokerage_withdraw (user_id) comment '用户编号';
  95. create index idx_audit_status on trade_brokerage_withdraw (status) comment '状态';
  96. -- 增加字典
  97. insert into system_dict_type(type, name)
  98. values ('brokerage_enabled_condition', '分佣模式');
  99. insert into system_dict_data(dict_type, label, value, sort, remark)
  100. values ('brokerage_enabled_condition', '人人分销', 1, 1, '所有用户都可以分销'),
  101. ('brokerage_enabled_condition', '指定分销', 2, 2, '仅可后台手动设置推广员');
  102. insert into system_dict_type(type, name)
  103. values ('brokerage_bind_mode', '分销关系绑定模式');
  104. insert into system_dict_data(dict_type, label, value, sort, remark)
  105. values ('brokerage_bind_mode', '没有推广人', 1, 1, '只要用户没有推广人,随时都可以绑定推广关系'),
  106. ('brokerage_bind_mode', '新用户', 2, 2, '仅新用户注册时才能绑定推广关系'),
  107. ('brokerage_bind_mode', '扫码覆盖', 3, 3, '如果用户已经有推广人,推广人会被变更');
  108. insert into system_dict_type(type, name)
  109. values ('brokerage_withdraw_type', '佣金提现类型');
  110. insert into system_dict_data(dict_type, label, value, sort)
  111. values ('brokerage_withdraw_type', '钱包', 1, 1),
  112. ('brokerage_withdraw_type', '银行卡', 2, 2),
  113. ('brokerage_withdraw_type', '微信', 3, 3),
  114. ('brokerage_withdraw_type', '支付宝', 4, 4);
  115. insert into system_dict_type(type, name)
  116. values ('brokerage_record_biz_type', '佣金记录业务类型');
  117. insert into system_dict_data(dict_type, label, value, sort)
  118. values ('brokerage_record_biz_type', '订单返佣', 1, 1),
  119. ('brokerage_record_biz_type', '申请提现', 2, 2);
  120. insert into system_dict_type(type, name)
  121. values ('brokerage_record_status', '佣金记录状态');
  122. insert into system_dict_data(dict_type, label, value, sort)
  123. values ('brokerage_record_status', '待结算', 0, 0),
  124. ('brokerage_record_status', '已结算', 1, 1),
  125. ('brokerage_record_status', '已取消', 2, 2);
  126. insert into system_dict_type(type, name)
  127. values ('brokerage_withdraw_status', '佣金提现状态');
  128. insert into system_dict_data(dict_type, label, value, sort)
  129. values ('brokerage_withdraw_status', '审核中', 0, 0),
  130. ('brokerage_withdraw_status', '审核通过', 10, 10),
  131. ('brokerage_withdraw_status', '提现成功', 11, 11),
  132. ('brokerage_withdraw_status', '审核不通过', 20, 20),
  133. ('brokerage_withdraw_status', '提现失败', 21, 21);
  134. insert into system_dict_type(type, name)
  135. values ('brokerage_bank_name', '佣金提现银行');
  136. insert into system_dict_data(dict_type, label, value, sort)
  137. values ('brokerage_bank_name', '工商银行', 0, 0),
  138. ('brokerage_bank_name', '建设银行', 1, 1),
  139. ('brokerage_bank_name', '农业银行', 2, 2),
  140. ('brokerage_bank_name', '中国银行', 3, 3),
  141. ('brokerage_bank_name', '交通银行', 4, 4),
  142. ('brokerage_bank_name', '招商银行', 5, 5);
  143. -- 交易中心配置:菜单 SQL
  144. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
  145. VALUES ('交易中心配置', '', 2, 0, 2072, 'config', 'ep:setting', 'trade/config/index', 0, 'TradeConfig');
  146. -- 按钮父菜单ID
  147. -- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
  148. SELECT @parentId := LAST_INSERT_ID();
  149. -- 按钮 SQL
  150. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  151. VALUES ('交易中心配置查询', 'trade:config:query', 3, 1, @parentId, '', '', '', 0);
  152. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  153. VALUES ('交易中心配置保存', 'trade:config:save', 3, 2, @parentId, '', '', '', 0);
  154. -- 增加菜单:分销
  155. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
  156. VALUES ('分销', '', 1, 5, 2072, 'brokerage', 'fa-solid:project-diagram', '', 0, '');
  157. -- 按钮父菜单ID
  158. SELECT @brokerageMenuId := LAST_INSERT_ID();
  159. -- 增加菜单:分销员
  160. -- 菜单 SQL
  161. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
  162. VALUES ('分销用户', '', 2, 0, @brokerageMenuId, 'brokerage-user', 'fa-solid:user-tie', 'trade/brokerage/user/index', 0,
  163. 'TradeBrokerageUser');
  164. -- 按钮父菜单ID
  165. -- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
  166. SELECT @parentId := LAST_INSERT_ID();
  167. -- 按钮 SQL
  168. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  169. VALUES ('分销用户查询', 'trade:brokerage-user:query', 3, 1, @parentId, '', '', '', 0);
  170. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  171. VALUES ('分销用户推广人查询', 'trade:brokerage-user:user-query', 3, 2, @parentId, '', '', '', 0);
  172. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  173. VALUES ('分销用户推广订单查询', 'trade:brokerage-user:order-query', 3, 3, @parentId, '', '', '', 0);
  174. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  175. VALUES ('分销用户修改推广资格', 'trade:brokerage-user:update-brokerage-enable', 3, 4, @parentId, '', '', '', 0);
  176. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  177. VALUES ('分销用户修改推广员', 'trade:brokerage-user:update-bind-user', 3, 5, @parentId, '', '', '', 0);
  178. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  179. VALUES ('分销用户清除推广员', 'trade:brokerage-user:clear-bind-user', 3, 6, @parentId, '', '', '', 0);
  180. -- 增加菜单:佣金记录
  181. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
  182. VALUES ('佣金记录', '', 2, 1, @brokerageMenuId, 'brokerage-record', 'fa:money', 'trade/brokerage/record/index', 0,
  183. 'TradeBrokerageRecord');
  184. -- 按钮父菜单ID
  185. -- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
  186. SELECT @parentId := LAST_INSERT_ID();
  187. -- 按钮 SQL
  188. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  189. VALUES ('佣金记录查询', 'trade:brokerage-record:query', 3, 1, @parentId, '', '', '', 0);
  190. -- 增加菜单:佣金提现
  191. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
  192. VALUES ('佣金提现', '', 2, 2, @brokerageMenuId, 'brokerage-withdraw', 'fa:credit-card',
  193. 'trade/brokerage/withdraw/index', 0, 'TradeBrokerageWithdraw');
  194. -- 按钮父菜单ID
  195. -- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
  196. SELECT @parentId := LAST_INSERT_ID();
  197. -- 按钮 SQL
  198. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  199. VALUES ('佣金提现查询', 'trade:brokerage-withdraw:query', 3, 1, @parentId, '', '', '', 0);
  200. INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  201. VALUES ('佣金提现审核', 'trade:brokerage-withdraw:audit', 3, 2, @parentId, '', '', '', 0);