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

-- 为已有用户生成邀请码（6位随机字符）
UPDATE nf_user 
SET invite_code = CONCAT(
    SUBSTRING('ABCDEFGHJKLMNPQRSTUVWXYZ23456789', FLOOR(1 + RAND() * 32), 1),
    SUBSTRING('ABCDEFGHJKLMNPQRSTUVWXYZ23456789', FLOOR(1 + RAND() * 32), 1),
    SUBSTRING('ABCDEFGHJKLMNPQRSTUVWXYZ23456789', FLOOR(1 + RAND() * 32), 1),
    SUBSTRING('ABCDEFGHJKLMNPQRSTUVWXYZ23456789', FLOOR(1 + RAND() * 32), 1),
    SUBSTRING('ABCDEFGHJKLMNPQRSTUVWXYZ23456789', FLOOR(1 + RAND() * 32), 1),
    SUBSTRING('ABCDEFGHJKLMNPQRSTUVWXYZ23456789', FLOOR(1 + RAND() * 32), 1)
)
WHERE invite_code IS NULL;
