-- 添加邀请码相关字段到 nf_user 表
-- 执行时间：2026-02-03

USE fastadmin;

-- 添加邀请码字段
ALTER TABLE `nf_user` 
ADD COLUMN `invite_code` VARCHAR(10) DEFAULT NULL COMMENT '邀请码' AFTER `vip_endtime`,
ADD COLUMN `invited_by` VARCHAR(10) DEFAULT NULL COMMENT '被谁邀请（邀请码）' AFTER `invite_code`,
ADD COLUMN `invite_count` INT(11) DEFAULT 0 COMMENT '邀请人数' AFTER `invited_by`,
ADD COLUMN `invite_reward_total` DECIMAL(10,2) DEFAULT 0.00 COMMENT '邀请奖励总额' AFTER `invite_count`;

-- 添加唯一索引
ALTER TABLE `nf_user` 
ADD UNIQUE INDEX `idx_invite_code` (`invite_code`);

-- 添加普通索引
ALTER TABLE `nf_user` 
ADD INDEX `idx_invited_by` (`invited_by`);

-- 验证字段是否添加成功
SELECT 
    COLUMN_NAME, 
    COLUMN_TYPE, 
    IS_NULLABLE, 
    COLUMN_DEFAULT, 
    COLUMN_COMMENT 
FROM 
    INFORMATION_SCHEMA.COLUMNS 
WHERE 
    TABLE_SCHEMA = 'fastadmin' 
    AND TABLE_NAME = 'nf_user' 
    AND COLUMN_NAME IN ('invite_code', 'invited_by', 'invite_count', 'invite_reward_total');
