-- 微信用户表
CREATE TABLE IF NOT EXISTS `wechat_user` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `open_id` varchar(64) NOT NULL COMMENT '微信openid',
  `union_id` varchar(64) DEFAULT NULL COMMENT '微信unionid',
  `app_remark` varchar(50) NOT NULL COMMENT '应用标识(对应sys_wechat_app.remark)',
  `nickname` varchar(100) DEFAULT '' COMMENT '昵称',
  `avatar` varchar(500) DEFAULT '' COMMENT '头像URL',
  `phone` varchar(20) DEFAULT '' COMMENT '手机号(微信授权)',
  `patient_id` int unsigned DEFAULT NULL COMMENT '关联患者ID',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态: 1启用 0停用',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_openid_app` (`open_id`, `app_remark`),
  KEY `idx_patient_id` (`patient_id`),
  KEY `idx_phone` (`phone`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信用户表';
