alter table cai_account
    add column `points` bigint(20) default 0 not null comment '积分';
ALTER TABLE cai_goods
    ADD COLUMN `give_point` bigint(20) default 0 not null comment '充值赠送积分';
ALTER TABLE cai_recharge_order
    ADD COLUMN `distribution` tinyint default 0 not null comment '是否參與分銷';


ALTER TABLE cai_user_info
    ADD COLUMN point_rate decimal(7, 2) default 0.00 not null comment '积分分销比例';
ALTER TABLE cai_recharge_order
    ADD COLUMN `give_point` bigint(20) default 0 not null comment '充值赠送积分';

CREATE TABLE `cai_point_record_log`
(
    `id`              bigint unsigned NOT NULL AUTO_INCREMENT,
    `points`          bigint(20)               DEFAULT 0 COMMENT '积分',
    `source_user_id`  bigint(20) COMMENT '消费方用户',
    `source_usercode` varchar(20) COMMENT '消费方用户',
    `source_phone`    varchar(50) COMMENT '消费方用户',
    `one_user_id`     bigint(20) COMMENT '分销方',
    `one_usercode`    varchar(20) COMMENT '分销方',
    `one_phone`       varchar(50) COMMENT '分销方',
    `one_rate`        decimal(8, 2) COMMENT '分销方提成比例',
    `one_points`      bigint(20) COMMENT '分销方积分',
    `status`          tinyint                  default 0 comment '状态  -1-无须分销 0-待分销 1-已分销',
    `source_type`     varchar(20) comment '来源',
    `source_id`       varchar(20) comment '来源ID',
    `remark`          varchar(255) comment '备注',
    `create_time`     datetime        NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_date` (`source_user_id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 1
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci
  ROW_FORMAT = DYNAMIC COMMENT ='用户积分分销';


-- 菜单 SQL
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible,
                      status, perms, icon, create_by, create_time, update_by, update_time, remark)
values (1996050872055914497, '用户积分分销', '1741377069687037954', '1', 'pointRecordLog', 'cai/pointRecordLog/index',
        1, 0, 'C', '0', '0', 'cai:pointRecordLog:list', '#', 'admin', sysdate(), '', null, '用户积分分销菜单');

-- 按钮 SQL
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible,
                      status, perms, icon, create_by, create_time, update_by, update_time, remark)
values (1996050872055914498, '用户积分分销查询', 1996050872055914497, '1', '#', '', 1, 0, 'F', '0', '0',
        'cai:pointRecordLog:query', '#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible,
                      status, perms, icon, create_by, create_time, update_by, update_time, remark)
values (1996050872055914500, '用户积分分销修改', 1996050872055914497, '3', '#', '', 1, 0, 'F', '0', '0',
        'cai:pointRecordLog:edit', '#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible,
                      status, perms, icon, create_by, create_time, update_by, update_time, remark)
values (1996050872055914501, '用户积分分销删除', 1996050872055914497, '4', '#', '', 1, 0, 'F', '0', '0',
        'cai:pointRecordLog:remove', '#', 'admin', sysdate(), '', null, '');
