/*
 直播系统数据库增量更新
 
 用于更新已执行过zhibo_live_tables.sql的数据库
 
 Date: 2025-12-30
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- 更新eb_banner表结构
ALTER TABLE `eb_banner` 
  ADD COLUMN IF NOT EXISTS `jump_type` varchar(32) NULL DEFAULT '' COMMENT '跳转类型' AFTER `image`,
  ADD COLUMN IF NOT EXISTS `url` varchar(255) NULL DEFAULT '' COMMENT '跳转链接' AFTER `jump_type`,
  ADD COLUMN IF NOT EXISTS `remark` varchar(255) NULL DEFAULT '' COMMENT '备注' AFTER `status`;

-- 创建系统版本表
CREATE TABLE IF NOT EXISTS `eb_system_version` (
  `id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `version_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '版本名称',
  `version_number` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '版本号',
  `channel` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'android' COMMENT '渠道 android/ios',
  `is_valid` tinyint NOT NULL DEFAULT 1 COMMENT '是否有效 0=否 1=是',
  `is_force_update` tinyint NOT NULL DEFAULT 0 COMMENT '是否强制更新 0=否 1=是',
  `download_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '下载地址',
  `jump_link` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '跳转链接',
  `update_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '更新内容',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_channel` (`channel`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '系统版本表' ROW_FORMAT = DYNAMIC;

-- 创建抽奖配置表
CREATE TABLE IF NOT EXISTS `eb_lottery_config` (
  `id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `config_key` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '配置键',
  `config_value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '配置值',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '描述',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_config_key` (`config_key`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '抽奖配置表' ROW_FORMAT = DYNAMIC;

-- 插入默认抽奖配置
INSERT IGNORE INTO `eb_lottery_config` (`config_key`, `config_value`, `description`) VALUES 
('lottery_cost_diamond', '10', '抽奖消耗钻石数');

-- 创建平台活动表(旧)
CREATE TABLE IF NOT EXISTS `eb_platform_activity` (
  `id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '活动标题',
  `cover` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '封面图',
  `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '活动内容',
  `status` tinyint NOT NULL DEFAULT 1 COMMENT '状态 0=禁用 1=启用',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '平台活动表(旧)' ROW_FORMAT = DYNAMIC;

-- 创建用户任务记录表
CREATE TABLE IF NOT EXISTS `eb_user_task_record` (
  `id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `uid` int UNSIGNED NOT NULL COMMENT '用户ID',
  `user_nickname` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户昵称',
  `task_id` int UNSIGNED NOT NULL COMMENT '任务ID',
  `task_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '任务名称',
  `reward_type` tinyint NOT NULL DEFAULT 1 COMMENT '奖励类型',
  `reward_value` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '奖励数值',
  `status` tinyint NOT NULL DEFAULT 0 COMMENT '状态 0=进行中 1=已完成 2=已领取',
  `complete_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `receive_time` datetime NULL DEFAULT NULL COMMENT '领取时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_uid` (`uid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户任务记录表' ROW_FORMAT = DYNAMIC;

-- 创建用户签到记录表
CREATE TABLE IF NOT EXISTS `eb_user_signin_record` (
  `id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `uid` int UNSIGNED NOT NULL COMMENT '用户ID',
  `user_nickname` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户昵称',
  `sign_date` date NOT NULL COMMENT '签到日期',
  `continuous_days` int UNSIGNED NOT NULL DEFAULT 1 COMMENT '连续签到天数',
  `reward_type` tinyint NOT NULL DEFAULT 1 COMMENT '奖励类型',
  `reward_value` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '奖励数值',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '签到时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_uid` (`uid`) USING BTREE,
  UNIQUE KEY `uk_uid_date` (`uid`, `sign_date`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户签到记录表' ROW_FORMAT = DYNAMIC;

SET FOREIGN_KEY_CHECKS = 1;
