ALTER TABLE za_user ADD COLUMN real_name VARCHAR(255)  NULL  COMMENT '真实姓名';
ALTER TABLE za_user ADD COLUMN id_card_number VARCHAR(255)  NULL  COMMENT '身份证号';


DROP TABLE IF EXISTS `za_role`;
CREATE TABLE `za_role`  (
   `id` int NOT NULL AUTO_INCREMENT,
   `role_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色编码',
   `role_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色名称',
   `deleted` bit(1) NOT NULL default 0 COMMENT '逻辑删除标记(0-正常,1-已删除)',
   `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `create_by` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '创建人',
   `update_time`datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
   `update_by` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '修改人',
   `tenant_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT 'Default'  COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_roal_name`(`role_name` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_german2_ci ROW_FORMAT = DYNAMIC;
INSERT INTO `seer_teach`.`za_role` (`id`, `role_code`, `role_name`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`, `tenant_id`) VALUES (1, 'ADMIN', '管理员', b'0', '2025-07-22 01:56:05', '2025-07-22 01:56:05', 'system', 'system', 'Default');
INSERT INTO `seer_teach`.`za_role` (`id`, `role_code`, `role_name`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`, `tenant_id`) VALUES (2, 'PARENT', '家长', b'0', '2025-07-22 01:56:05', '2025-07-22 01:56:05', 'system', 'system', 'Default');
INSERT INTO `seer_teach`.`za_role` (`id`, `role_code`, `role_name`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`, `tenant_id`) VALUES (3, 'CHILDREN', '孩子', b'0', '2025-07-22 01:56:05', '2025-07-22 01:56:05', 'system', 'system', 'Default');
INSERT INTO `seer_teach`.`za_role` (`id`, `role_code`, `role_name`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`, `tenant_id`) VALUES (4, 'DISTRIBUTOR', '经销商', b'0', '2025-08-10 06:47:01', '2025-08-10 06:47:01', 'system', 'system', 'Default');
INSERT INTO `seer_teach`.`za_role` (`id`, `role_code`, `role_name`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`, `tenant_id`) VALUES (5, 'WAREHOUSE_MANAGER', '仓管', b'0', '2025-08-08 16:56:12', '2025-08-08 08:56:12', 'system', 'system', 'Default');
INSERT INTO `seer_teach`.`za_role` (`id`, `role_code`, `role_name`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`, `tenant_id`) VALUES (6, 'GUEST', '访客', b'0', '2025-07-22 01:56:05', '2025-07-22 01:56:05', 'system', 'system', 'Default');


DROP TABLE IF EXISTS `za_user_auth`;
CREATE TABLE `za_user_auth` (
  `id` INT NOT NULL AUTO_INCREMENT COMMENT '认证记录ID',
  `user_id` INT NOT NULL COMMENT '关联的用户ID',
  `provider` VARCHAR(20) NOT NULL COMMENT '提供商: wechat,alipay,apple,phone',
  `auth_type` VARCHAR(32) NOT NULL COMMENT '认证类型: wechat_mini(微信小程序),wechat_mp(公众号),alipay_mini(支付宝小程序),phone_sms(短信验证)',
  `open_id` VARCHAR(128) NULL COMMENT '平台用户唯一ID',
  `union_id` VARCHAR(128) NULL COMMENT '跨平台统一ID(如微信union_id)',
  `app_id` VARCHAR(128) NULL COMMENT 'App ID',
  `access_token` VARCHAR(1024) NULL COMMENT '访问令牌(加密存储)',
  `refresh_token` VARCHAR(1024) NULL COMMENT '刷新令牌(加密存储)',
  `token_expires_at` DATETIME NULL COMMENT '令牌过期时间',
  `credential_json` JSON NULL COMMENT '扩展凭证(如小程序session_key)',
  `profile_json` JSON NULL COMMENT '用户资料原始JSON',
  `is_bound` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否绑定: 1=是, 0=否（解绑后保留记录）',
  `is_verified` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否已验证: 1=是, 0=否（如手机号未验证）',
  `status` TINYINT NOT NULL DEFAULT 1 COMMENT '状态: 1=正常, 0=禁用, -1=已删除',
  `login_count` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '登录次数统计',
  `last_login_at` DATETIME NULL COMMENT '最后登录时间',
  `deleted` bit(1) NOT NULL default 0 COMMENT '逻辑删除标记(0-正常,1-已删除)',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `create_by` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '创建人',
  `update_time`datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `update_by` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '修改人',
  `tenant_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT 'Default'  COMMENT '租户id',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_union_id` (`union_id`) COMMENT '联合ID索引',
  KEY `idx_user_status` (`user_id`, `status`) COMMENT '用户状态索引'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_german2_ci COMMENT='用户第三方认证表（状态增强版）';