Files
MBTI_wang/api/database/add_invite_codes.sql
2026-05-11 09:39:32 +08:00

21 lines
1.4 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 邀请码 → 推广员inviterId供小程序填码绑定分销关系
-- 执行前请将表名前缀与 api/config/database.php 中 prefix 对齐ThinkPHP Db::name('invite_codes') → {prefix}invite_codes
CREATE TABLE IF NOT EXISTS `mbti_invite_codes` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`code` varchar(64) NULL DEFAULT NULL COMMENT '兼容旧字段,可与 code_numeric 同步',
`code_numeric` varchar(20) NULL DEFAULT NULL COMMENT '数字邀请码,如 6 位 100000-999999',
`code_legacy` varchar(64) NULL DEFAULT NULL COMMENT '老版字母数字邀请码,与数字码同一 inviter 可并存',
`inviterId` int unsigned NOT NULL COMMENT '推广员 wechat_users.id',
`enterpriseId` int unsigned NULL DEFAULT NULL COMMENT '企业上下文,与个人版并行时可空',
`status` varchar(20) NOT NULL DEFAULT 'active' COMMENT 'active|disabled',
`expiresAt` int unsigned NULL DEFAULT NULL COMMENT '过期unix时间戳NULL=不限',
`remark` varchar(255) NULL DEFAULT NULL COMMENT '备注',
`createdAt` int unsigned NULL DEFAULT NULL,
`updatedAt` int unsigned NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_code_numeric` (`code_numeric`),
UNIQUE KEY `uk_code_legacy` (`code_legacy`),
KEY `idx_inviterId` (`inviterId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='小程序填写邀请码解析用';