brokerage.sql 14 KB

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