-- 实名认证相关表结构变更
-- 数据库：pap_cytx

USE `pap_cytx`;

-- ========================================
-- patient 表新增实名认证字段
-- ========================================
ALTER TABLE `patient`
  ADD COLUMN `auth_status` tinyint(1) DEFAULT 0 COMMENT '认证状态: 0未认证 1已认证' AFTER `status`,
  ADD COLUMN `id_card_type` tinyint DEFAULT 1 COMMENT '证件类型: 1身份证 2无证件儿童 3临时身份证' AFTER `id_card`,
  ADD COLUMN `id_card_front` varchar(500) DEFAULT '' COMMENT '证件正面照URL' AFTER `id_card_type`,
  ADD COLUMN `id_card_back` varchar(500) DEFAULT '' COMMENT '证件反面照URL' AFTER `id_card_front`,
  ADD COLUMN `photo` varchar(500) DEFAULT '' COMMENT '免冠照片URL(无证件儿童)' AFTER `id_card_back`,
  ADD COLUMN `issuing_authority` varchar(100) DEFAULT '' COMMENT '发证机关' AFTER `birth_date`,
  ADD COLUMN `valid_period` varchar(50) DEFAULT '' COMMENT '有效期限' AFTER `issuing_authority`,
  ADD COLUMN `auth_time` datetime DEFAULT NULL COMMENT '认证时间' AFTER `auth_status`;

-- ========================================
-- 短信日志表
-- ========================================
CREATE TABLE IF NOT EXISTS `sms_log` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `mobile` varchar(20) NOT NULL COMMENT '手机号',
  `template_id` varchar(50) DEFAULT '' COMMENT '模板ID',
  `template_params` varchar(500) DEFAULT '' COMMENT '模板参数JSON',
  `sms_type` tinyint DEFAULT 1 COMMENT '类型: 1验证码',
  `biz_type` varchar(50) DEFAULT '' COMMENT '业务类型: real_name_auth/bind_mobile',
  `code` varchar(10) DEFAULT '' COMMENT '验证码',
  `expire_time` datetime DEFAULT NULL COMMENT '过期时间',
  `status` tinyint DEFAULT 0 COMMENT '状态: 0待发送 1已发送 2发送失败',
  `fail_reason` varchar(500) DEFAULT NULL COMMENT '失败原因',
  `provider_msg_id` varchar(100) DEFAULT NULL COMMENT '运营商消息ID',
  `ip` varchar(50) DEFAULT '' COMMENT '请求IP',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_mobile` (`mobile`),
  KEY `idx_biz_type` (`biz_type`),
  KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='短信日志表';
