brokerage.sql 12 KB

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