/*
 Navicat Premium Dump SQL

 Source Server         : 116.62.4.26
 Source Server Type    : MySQL
 Source Server Version : 50740 (5.7.40-log)
 Source Host           : 116.62.4.26:3306
 Source Schema         : 1818ai

 Target Server Type    : MySQL
 Target Server Version : 50740 (5.7.40-log)
 File Encoding         : 65001

 Date: 06/12/2025 15:20:26
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for admin_user
-- ----------------------------
DROP TABLE IF EXISTS `admin_user`;
CREATE TABLE `admin_user`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `username` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '管理员用户名',
  `password_hash` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '哈希后的密码',
  `role` tinyint(4) NOT NULL 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 '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `username`(`username`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for ai_task
-- ----------------------------
DROP TABLE IF EXISTS `ai_task`;
CREATE TABLE `ai_task`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `task_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务编号 (系统生成的唯一ID)',
  `user_id` bigint(20) NOT NULL COMMENT '关联的用户ID',
  `model_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '请求的模型名称 (如: sora_image)',
  `task_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务类型 (image/video)',
  `provider_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'AI服务提供商类型',
  `provider_task_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '服务商返回的任务ID',
  `provider_response` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '服务商原始响应（JSON）',
  `prompt` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户提交的提示词',
  `image_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '参考图片URL（用于图生视频）',
  `image_base64` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '参考图片Base64编码（用于图生视频）',
  `input_images` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '输入图片列表（JSON格式，用于图生视频）',
  `aspect_ratio` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '图片比例（如: 2:3, 3:2, 1:1，仅图片生成使用）',
  `duration` int(11) NULL DEFAULT NULL COMMENT '视频时长（秒，仅视频生成使用）',
  `status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'created' COMMENT '任务状态 (created, queued, processing, completed, failed, cancelled)',
  `progress` int(11) NULL DEFAULT 0 COMMENT '生成进度百分比 (0-100)',
  `progress_message` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '当前进度文本描述',
  `points_frozen` int(11) NOT NULL COMMENT '本次任务冻结的积分',
  `points_consumed` int(11) NULL DEFAULT 0 COMMENT '任务成功后实际消耗的积分',
  `result_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '生成结果的URL',
  `error_message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '任务失败时的错误信息',
  `queue_time` datetime NULL DEFAULT NULL COMMENT '进入队列的时间',
  `start_time` datetime NULL DEFAULT NULL COMMENT '开始处理的时间',
  `complete_time` datetime NULL DEFAULT NULL COMMENT '任务完成或失败的时间',
  `expire_time` datetime NULL DEFAULT NULL COMMENT '结果URL的过期时间 (根据第三方API策略设定)',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '任务创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  `provider_pid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '服务商返回的PID，用于速创Sora2的续作ID',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `task_no`(`task_no`) USING BTREE,
  UNIQUE INDEX `uk_task_no`(`task_no`) USING BTREE,
  INDEX `idx_user_status`(`user_id`, `status`) USING BTREE,
  INDEX `idx_status_time`(`status`, `create_time`) USING BTREE,
  INDEX `idx_provider_task_id`(`provider_task_id`) USING BTREE,
  INDEX `idx_provider_type_status`(`provider_type`, `status`) USING BTREE,
  INDEX `idx_task_type`(`task_type`) USING BTREE,
  CONSTRAINT `ai_task_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1876 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'AI生成任务表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for api_key
-- ----------------------------
DROP TABLE IF EXISTS `api_key`;
CREATE TABLE `api_key`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '用户ID',
  `key_value` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'API密钥值',
  `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否启用',
  `last_used_at` datetime NULL DEFAULT NULL COMMENT '最后使用时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `key_value`(`key_value`) USING BTREE,
  UNIQUE INDEX `uk_api_key_user`(`user_id`) USING BTREE,
  INDEX `idx_api_key_value`(`key_value`) USING BTREE,
  INDEX `idx_api_key_active`(`is_active`) USING BTREE,
  CONSTRAINT `api_key_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 76 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for banner
-- ----------------------------
DROP TABLE IF EXISTS `banner`;
CREATE TABLE `banner`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `image` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '图片URL',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '标题',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '描述',
  `button_text` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '按钮文字',
  `link_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'internal' COMMENT '链接类型 (internal: 内部路由跳转, external: 外部链接跳转)',
  `link` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '跳转链接',
  `sort_order` int(11) NOT NULL DEFAULT 0 COMMENT '排序字段',
  `is_enabled` tinyint(1) 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 '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_banner_enabled`(`is_enabled`) USING BTREE,
  INDEX `idx_banner_sort`(`sort_order`) USING BTREE,
  INDEX `idx_banner_create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for category
-- ----------------------------
DROP TABLE IF EXISTS `category`;
CREATE TABLE `category`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '类目名称',
  `type` tinyint(4) NOT NULL COMMENT '类目类型(1课程分类/2工作流分类)',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '类目描述',
  `sort_order` int(11) NOT NULL DEFAULT 0 COMMENT '排序字段',
  `is_enabled` tinyint(1) 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 '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_category_name_type`(`name`, `type`) USING BTREE,
  INDEX `idx_category_type`(`type`) USING BTREE,
  INDEX `idx_category_enabled`(`is_enabled`) USING BTREE,
  INDEX `idx_category_sort`(`sort_order`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 18 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '类目表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for content_revenue
-- ----------------------------
DROP TABLE IF EXISTS `content_revenue`;
CREATE TABLE `content_revenue`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '内容创作者ID',
  `content_type` tinyint(4) NOT NULL COMMENT '内容类型 (1工作流/2视频)',
  `content_id` bigint(20) NOT NULL COMMENT '内容ID',
  `revenue_source` tinyint(4) NOT NULL COMMENT '收益来源 (1购买/2复制/3观看)',
  `source_value` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '来源基础价值',
  `quantity` int(11) NOT NULL DEFAULT 0 COMMENT '数量',
  `commission_rate` decimal(5, 4) NOT NULL DEFAULT 0.0000 COMMENT '分成比例',
  `revenue_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '创作者实际收益金额',
  `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '收益状态 (0待结算/1已结算)',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '收益产生时间',
  `settled_at` datetime NULL DEFAULT NULL COMMENT '结算时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_user_id`(`user_id`) USING BTREE,
  INDEX `idx_content`(`content_type`, `content_id`) USING BTREE,
  INDEX `idx_create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for content_revenue_stage
-- ----------------------------
DROP TABLE IF EXISTS `content_revenue_stage`;
CREATE TABLE `content_revenue_stage`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `content_type` tinyint(4) NOT NULL COMMENT '内容类型 (1工作流/2视频)',
  `content_id` bigint(20) NOT NULL COMMENT '内容ID',
  `user_id` bigint(20) NOT NULL COMMENT '创作者ID',
  `stage_level` int(11) NOT NULL COMMENT '阶段等级 (1,2,3...)',
  `stage_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '阶段名称',
  `target_count` int(11) NOT NULL COMMENT '目标数量 (复制次数/观看次数)',
  `reward_amount` decimal(10, 2) NOT NULL COMMENT '奖励金额',
  `current_count` int(11) NOT NULL DEFAULT 0 COMMENT '当前数量',
  `is_achieved` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已达到 (0未达到/1已达到)',
  `achieved_at` datetime NULL DEFAULT NULL COMMENT '达到时间',
  `is_withdrawn` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已提现 (0未提现/1已提现)',
  `withdrawn_at` datetime NULL DEFAULT NULL COMMENT '提现时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_content_stage`(`content_type`, `content_id`, `stage_level`) USING BTREE,
  INDEX `idx_user_id`(`user_id`) USING BTREE,
  INDEX `idx_content`(`content_type`, `content_id`) USING BTREE,
  INDEX `idx_achieved`(`is_achieved`) USING BTREE,
  INDEX `idx_withdrawn`(`is_withdrawn`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 58 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for course
-- ----------------------------
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '课程标题',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '课程的富文本描述',
  `cover_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '封面图URL',
  `detail_gallery` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '详情图集（JSON格式存储多张图片URL）',
  `price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '价格',
  `level` tinyint(4) NOT NULL DEFAULT 0 COMMENT '访问课程所需的最低用户级别',
  `audit_status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '审核状态(0待审核/1通过/2拒绝)',
  `category` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '课程分类',
  `category_id` bigint(20) NULL DEFAULT NULL COMMENT '关联类目ID',
  `reject_reason` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '拒绝原因',
  `review_time` datetime NULL DEFAULT NULL COMMENT '审核时间',
  `user_id` bigint(20) NULL DEFAULT NULL COMMENT '创建者ID',
  `is_free` tinyint(1) NOT NULL DEFAULT 0 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 '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_course_category_id`(`category_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 37 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for course_chapter
-- ----------------------------
DROP TABLE IF EXISTS `course_chapter`;
CREATE TABLE `course_chapter`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `course_id` bigint(20) NOT NULL COMMENT '所属课程ID',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '章节标题',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '章节描述',
  `order_num` int(11) NOT NULL DEFAULT 0 COMMENT '章节排序编号',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 40 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for course_favorite
-- ----------------------------
DROP TABLE IF EXISTS `course_favorite`;
CREATE TABLE `course_favorite`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '收藏用户ID',
  `course_id` bigint(20) NOT NULL COMMENT '被收藏的课程ID',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '收藏时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_user_course_favorite`(`user_id`, `course_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for course_like
-- ----------------------------
DROP TABLE IF EXISTS `course_like`;
CREATE TABLE `course_like`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '点赞用户ID',
  `course_id` bigint(20) NOT NULL COMMENT '被点赞的课程ID',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '点赞时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_user_course_like`(`user_id`, `course_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for course_video
-- ----------------------------
DROP TABLE IF EXISTS `course_video`;
CREATE TABLE `course_video`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `chapter_id` bigint(20) NOT NULL COMMENT '所属章节ID',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '视频标题',
  `video_id` bigint(20) NULL DEFAULT NULL COMMENT '阿里云视频点播ID',
  `duration_sec` int(11) NULL DEFAULT 0 COMMENT '视频时长（秒）',
  `order_num` int(11) NOT NULL DEFAULT 0 COMMENT '视频在章节内的排序编号',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 40 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for fan_promotion_commission
-- ----------------------------
DROP TABLE IF EXISTS `fan_promotion_commission`;
CREATE TABLE `fan_promotion_commission`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `promoter_id` bigint(20) NOT NULL COMMENT '推广人ID',
  `fan_id` bigint(20) NOT NULL COMMENT '粉丝用户ID',
  `order_id` bigint(20) NOT NULL COMMENT '关联的订单ID',
  `order_amount` decimal(10, 2) NOT NULL COMMENT '粉丝订单金额',
  `commission_rate` decimal(5, 4) NOT NULL COMMENT '提成比例',
  `commission_level` tinyint(4) NOT NULL COMMENT '提成发生时推广人的等级',
  `commission_amount` decimal(10, 2) NOT NULL COMMENT '推广人实际提成金额',
  `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '提成状态 (0待结算/1已结算)',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '提成产生时间',
  `settled_at` datetime NULL DEFAULT NULL COMMENT '结算时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_promoter_fan`(`promoter_id`, `fan_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for gift_code
-- ----------------------------
DROP TABLE IF EXISTS `gift_code`;
CREATE TABLE `gift_code`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '礼品码，唯一',
  `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '礼品码名称',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '礼品码描述',
  `type` tinyint(4) NOT NULL COMMENT '礼品码类型 (1-积分卡/2-会员卡)',
  `points` int(11) NULL DEFAULT NULL COMMENT '积分数量（积分卡类型）',
  `points_expire_days` int(11) NULL DEFAULT NULL COMMENT '积分有效期天数（积分卡类型）',
  `target_role` tinyint(4) NULL DEFAULT NULL COMMENT '目标角色等级（会员卡类型）',
  `duration_days` int(11) NULL DEFAULT NULL COMMENT '会员有效期天数（会员卡类型）',
  `total_count` int(11) NOT NULL DEFAULT 1 COMMENT '总可用次数',
  `used_count` int(11) NOT NULL DEFAULT 0 COMMENT '已使用次数',
  `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否启用',
  `expire_time` datetime NULL DEFAULT NULL COMMENT '礼品码过期时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `code`(`code`) USING BTREE,
  INDEX `idx_gift_code_code`(`code`) USING BTREE,
  INDEX `idx_gift_code_type`(`type`) USING BTREE,
  INDEX `idx_gift_code_active`(`is_active`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 69 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for gift_code_usage
-- ----------------------------
DROP TABLE IF EXISTS `gift_code_usage`;
CREATE TABLE `gift_code_usage`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `gift_code_id` bigint(20) NOT NULL COMMENT '礼品码ID',
  `user_id` bigint(20) NOT NULL COMMENT '使用用户ID',
  `code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '使用的礼品码',
  `type` tinyint(4) NOT NULL COMMENT '礼品码类型 (1-积分卡/2-会员卡)',
  `points` int(11) NULL DEFAULT NULL COMMENT '积分数量',
  `points_expire_days` int(11) NULL DEFAULT NULL COMMENT '积分有效期天数',
  `target_role` tinyint(4) NULL DEFAULT NULL COMMENT '目标角色等级',
  `duration_days` int(11) NULL DEFAULT NULL COMMENT '会员有效期天数',
  `old_role` tinyint(4) NULL DEFAULT NULL COMMENT '用户原角色',
  `new_role` tinyint(4) NULL DEFAULT NULL COMMENT '用户新角色',
  `old_points` int(11) NULL DEFAULT NULL COMMENT '用户原积分',
  `new_points` int(11) NULL DEFAULT NULL COMMENT '用户新积分',
  `old_points_expires_at` datetime NULL DEFAULT NULL COMMENT '用户原积分过期时间',
  `new_points_expires_at` datetime NULL DEFAULT NULL COMMENT '用户新积分过期时间',
  `old_expires_at` datetime NULL DEFAULT NULL COMMENT '用户原会员到期时间',
  `new_expires_at` datetime NULL DEFAULT NULL COMMENT '用户新会员到期时间',
  `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '使用状态 (1-成功/0-失败)',
  `error_message` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '错误信息',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '使用时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_gift_code_usage_user`(`user_id`) USING BTREE,
  INDEX `idx_gift_code_usage_code`(`gift_code_id`) USING BTREE,
  INDEX `idx_gift_code_usage_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 83 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for membership_plan
-- ----------------------------
DROP TABLE IF EXISTS `membership_plan`;
CREATE TABLE `membership_plan`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '套餐名称',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '套餐的详细描述',
  `price` decimal(10, 2) NOT NULL COMMENT '价格',
  `duration_days` int(11) NOT NULL COMMENT '有效期天数',
  `target_role` tinyint(4) NOT NULL COMMENT '购买后达到的角色等级',
  `discount_percentage` decimal(5, 2) NULL DEFAULT 0.00 COMMENT '优惠百分比率(0-100，如10.50表示10.5%的优惠)',
  `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否上架',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for order
-- ----------------------------
DROP TABLE IF EXISTS `order`;
CREATE TABLE `order`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `order_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '系统生成的唯一订单号',
  `order_type` tinyint(4) NOT NULL DEFAULT 1 COMMENT '订单类型（1-会员订单/2-积分订单）',
  `user_id` bigint(20) NOT NULL COMMENT '购买用户ID',
  `plan_id` bigint(20) NULL DEFAULT NULL COMMENT '购买的套餐ID',
  `points_package_id` bigint(20) NULL DEFAULT NULL COMMENT '积分套餐ID（积分订单）',
  `points_amount` int(11) NULL DEFAULT NULL COMMENT '积分数量（积分订单）',
  `original_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '套餐原价',
  `amount` decimal(10, 2) NOT NULL COMMENT '订单最终金额（实际支付金额）',
  `actual_duration_days` int(11) NULL DEFAULT NULL COMMENT '实际获得的会员天数',
  `discount_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '优惠类型 (NONE/CONTINUOUS_MONTHLY/CONTINUOUS_YEARLY/FIRST_PURCHASE/SPECIAL_OFFER)',
  `discount_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT '优惠金额',
  `discount_description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '优惠描述',
  `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '订单状态 (0待支付/1已完成/2已取消/3支付失败)',
  `payment_method` tinyint(4) NULL DEFAULT NULL COMMENT '支付方式 (1支付宝/2微信支付)',
  `paid_at` datetime NULL DEFAULT NULL COMMENT '支付成功时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `order_no`(`order_no`) USING BTREE,
  INDEX `idx_order_discount_type`(`discount_type`) USING BTREE,
  INDEX `idx_order_user_id_status`(`user_id`, `status`) USING BTREE,
  INDEX `idx_order_type`(`order_type`) USING BTREE,
  INDEX `idx_order_points_package`(`points_package_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 152 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for payment_transaction
-- ----------------------------
DROP TABLE IF EXISTS `payment_transaction`;
CREATE TABLE `payment_transaction`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `order_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '关联的系统订单号',
  `transaction_no` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '第三方支付平台返回的流水号',
  `payment_gateway` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '支付网关',
  `amount` decimal(10, 2) NOT NULL COMMENT '支付金额',
  `status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '第三方支付平台返回的状态',
  `raw_data` json NULL COMMENT '第三方支付平台通知的完整原始数据',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for plaza_work
-- ----------------------------
DROP TABLE IF EXISTS `plaza_work`;
CREATE TABLE `plaza_work`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `work_no` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '作品编号（唯一标识）',
  `user_id` bigint(20) NOT NULL COMMENT '发布者用户ID',
  `task_no` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '关联的任务编号',
  `task_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '任务类型：text_to_image/image_to_image/text_to_video/image_to_video等',
  `model_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '使用的模型名称',
  `prompt` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '生成提示词',
  `result_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '作品结果URL（图片或视频）',
  `image_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '参考图URL（图生图/图生视频任务使用）',
  `aspect_ratio` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '宽高比：1:1/2:3/3:2/9:16/16:9等',
  `title` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '作品标题（可选）',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '作品描述（可选）',
  `tags` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '标签（JSON数组字符串）',
  `view_count` int(11) NULL DEFAULT 0 COMMENT '浏览次数',
  `like_count` int(11) NULL DEFAULT 0 COMMENT '点赞数',
  `share_count` int(11) NULL DEFAULT 0 COMMENT '分享数',
  `comment_count` int(11) NULL DEFAULT 0 COMMENT '评论数（预留）',
  `is_public` tinyint(1) NULL DEFAULT 1 COMMENT '是否公开：0-仅自己可见，1-公开',
  `status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT 'published' COMMENT '状态：draft-草稿，published-已发布，hidden-已隐藏',
  `audit_status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending' COMMENT '审核状态：pending-待审核, approved-已通过, rejected-已拒绝',
  `audit_admin_id` bigint(20) NULL DEFAULT NULL COMMENT '审核管理员ID',
  `audit_time` datetime NULL DEFAULT NULL COMMENT '审核时间',
  `audit_remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '审核备注（拒绝原因等）',
  `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NULL DEFAULT 0 COMMENT '是否删除：0-未删除，1-已删除',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_work_no`(`work_no`) USING BTREE,
  INDEX `idx_user_id`(`user_id`) USING BTREE,
  INDEX `idx_task_no`(`task_no`) USING BTREE,
  INDEX `idx_task_type`(`task_type`) USING BTREE,
  INDEX `idx_create_time`(`create_time`) USING BTREE,
  INDEX `idx_like_count`(`like_count`) USING BTREE,
  INDEX `idx_status_public`(`status`, `is_public`, `is_deleted`) USING BTREE,
  INDEX `idx_type_like_time`(`task_type`, `like_count`, `create_time`) USING BTREE,
  INDEX `idx_status_public_time`(`status`, `is_public`, `create_time`) USING BTREE,
  INDEX `idx_audit_status`(`audit_status`) USING BTREE,
  INDEX `idx_audit_time`(`audit_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 63 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '广场作品表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for plaza_work_audit_log
-- ----------------------------
DROP TABLE IF EXISTS `plaza_work_audit_log`;
CREATE TABLE `plaza_work_audit_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `work_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '作品编号',
  `work_id` bigint(20) NOT NULL COMMENT '作品ID',
  `audit_status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '审核结果：approved-通过, rejected-拒绝',
  `audit_admin_id` bigint(20) NOT NULL COMMENT '审核管理员ID',
  `audit_admin_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '审核管理员名称',
  `audit_remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '审核备注',
  `audit_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '审核时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_work_no`(`work_no`) USING BTREE,
  INDEX `idx_work_id`(`work_id`) USING BTREE,
  INDEX `idx_audit_admin_id`(`audit_admin_id`) USING BTREE,
  INDEX `idx_audit_time`(`audit_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 68 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '广场作品审核记录表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for plaza_work_like
-- ----------------------------
DROP TABLE IF EXISTS `plaza_work_like`;
CREATE TABLE `plaza_work_like`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `work_id` bigint(20) NOT NULL COMMENT '作品ID',
  `user_id` bigint(20) NOT NULL COMMENT '点赞用户ID',
  `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '点赞时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_work_user`(`work_id`, `user_id`) USING BTREE,
  INDEX `idx_user_id`(`user_id`) USING BTREE,
  INDEX `idx_create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 80 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '广场作品点赞表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for plaza_work_report
-- ----------------------------
DROP TABLE IF EXISTS `plaza_work_report`;
CREATE TABLE `plaza_work_report`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `report_no` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '投诉编号（唯一标识）',
  `work_id` bigint(20) NOT NULL COMMENT '被投诉的作品ID',
  `work_no` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '被投诉的作品编号',
  `reporter_id` bigint(20) NOT NULL COMMENT '投诉人用户ID',
  `report_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '投诉类型：political-政治敏感，pornographic-色情低俗，violent-暴力血腥，dangerous-危险行为，uncomfortable-引人不适，other-其他',
  `report_reason` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '投诉原因描述（可选）',
  `report_status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT 'pending' COMMENT '投诉状态：pending-待审核，approved-投诉成立，rejected-投诉不成立',
  `audit_admin_id` bigint(20) NULL DEFAULT NULL COMMENT '审核管理员ID',
  `audit_admin_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '审核管理员名称',
  `audit_remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '审核备注（处理说明）',
  `audit_time` datetime NULL DEFAULT NULL COMMENT '审核时间',
  `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '投诉时间',
  `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NULL DEFAULT 0 COMMENT '是否删除：0-未删除，1-已删除',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_report_no`(`report_no`) USING BTREE,
  INDEX `idx_work_id`(`work_id`) USING BTREE,
  INDEX `idx_work_no`(`work_no`) USING BTREE,
  INDEX `idx_reporter_id`(`reporter_id`) USING BTREE,
  INDEX `idx_report_type`(`report_type`) USING BTREE,
  INDEX `idx_report_status`(`report_status`) USING BTREE,
  INDEX `idx_audit_admin_id`(`audit_admin_id`) USING BTREE,
  INDEX `idx_create_time`(`create_time`) USING BTREE,
  INDEX `idx_work_reporter`(`work_id`, `reporter_id`, `is_deleted`) USING BTREE,
  INDEX `idx_status_time`(`report_status`, `create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '广场作品投诉表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for plaza_work_report_limit
-- ----------------------------
DROP TABLE IF EXISTS `plaza_work_report_limit`;
CREATE TABLE `plaza_work_report_limit`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `user_id` bigint(20) NOT NULL COMMENT '用户ID',
  `report_count` int(11) NULL DEFAULT 0 COMMENT '今日投诉次数',
  `last_report_time` datetime NULL DEFAULT NULL COMMENT '最后投诉时间',
  `reset_date` date NOT NULL COMMENT '重置日期（用于每日重置计数）',
  `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_user_id`(`user_id`) USING BTREE,
  INDEX `idx_reset_date`(`reset_date`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '广场作品投诉限制表（防止恶意投诉）' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for plaza_work_view
-- ----------------------------
DROP TABLE IF EXISTS `plaza_work_view`;
CREATE TABLE `plaza_work_view`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `work_id` bigint(20) NOT NULL COMMENT '作品ID',
  `user_id` bigint(20) NULL DEFAULT NULL COMMENT '浏览用户ID（可为空，支持匿名浏览）',
  `ip_address` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'IP地址',
  `user_agent` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '用户代理',
  `view_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '浏览时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_work_id`(`work_id`) USING BTREE,
  INDEX `idx_user_id`(`user_id`) USING BTREE,
  INDEX `idx_view_time`(`view_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '广场作品浏览记录表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for points_config
-- ----------------------------
DROP TABLE IF EXISTS `points_config`;
CREATE TABLE `points_config`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `model_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '模型名称 (如: sora_image)',
  `model_category` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'text' COMMENT '模型类别：text(文本), image(图片), video(视频), audio(音频)',
  `points_cost` int(11) NOT NULL COMMENT '调用一次消耗的积分',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '模型描述',
  `is_enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否启用 (0:禁用, 1:启用)',
  `provider_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'openai' COMMENT 'AI服务提供商类型：openai, ',
  `provider_config` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '服务商特定配置（JSON格式）',
  `task_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '任务类型：text_to_image(文生图)/image_to_image(图生图)/text_to_video(文生视频)/image_to_video(图生视频)/llm(大语言模型)/text_to_audio(文生音频)/image_to_text(图生文)/other(其他)',
  `sort_order` int(11) NULL DEFAULT 0 COMMENT '排序顺序（用于前端展示）',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `model_name`(`model_name`) USING BTREE,
  INDEX `idx_points_config_task_type`(`task_type`) USING BTREE,
  INDEX `idx_points_config_provider_task`(`provider_type`, `task_type`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 116 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '积分消费配置表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for points_consumption_log
-- ----------------------------
DROP TABLE IF EXISTS `points_consumption_log`;
CREATE TABLE `points_consumption_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '关联的用户ID',
  `task_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '关联的AI任务编号',
  `change_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '变动类型 (recharge:充值, consume:消费, refund:退款, expire:过期, admin_adjust:管理员调整)',
  `change_amount` int(11) NOT NULL COMMENT '变动积分数量 (正数表示增加，负数表示减少)',
  `balance_before` int(11) NOT NULL COMMENT '变动前积分余额',
  `balance_after` int(11) NOT NULL COMMENT '变动后积分余额',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '变动描述',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '记录创建时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_user_id_type`(`user_id`, `change_type`) USING BTREE,
  CONSTRAINT `points_consumption_log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 2534 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '积分消费记录表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for points_package
-- ----------------------------
DROP TABLE IF EXISTS `points_package`;
CREATE TABLE `points_package`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '套餐名称',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '套餐描述',
  `points` int(11) NOT NULL COMMENT '基础积分数量',
  `bonus_points` int(11) NOT NULL DEFAULT 0 COMMENT '赠送积分数量',
  `total_points` int(11) NOT NULL COMMENT '总积分（基础+赠送）',
  `price` decimal(10, 2) NOT NULL COMMENT '价格（元）',
  `original_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '原价（用于显示优惠）',
  `points_expire_days` int(11) NOT NULL DEFAULT 365 COMMENT '积分有效期（天）',
  `discount_label` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '优惠标签（如：首充特惠、限时优惠）',
  `sort_order` int(11) NOT NULL DEFAULT 0 COMMENT '排序（数字越小越靠前）',
  `is_hot` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否热门推荐',
  `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否上架',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_points_package_active`(`is_active`) USING BTREE,
  INDEX `idx_points_package_sort`(`sort_order`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 13 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '积分套餐表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for promotion_level_config
-- ----------------------------
DROP TABLE IF EXISTS `promotion_level_config`;
CREATE TABLE `promotion_level_config`  (
  `id` tinyint(4) NOT NULL AUTO_INCREMENT COMMENT '等级ID',
  `level_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '等级名称',
  `min_paid_fans` int(11) NOT NULL COMMENT '达到该等级所需的最低付费粉丝数量',
  `commission_rate` decimal(5, 4) NOT NULL COMMENT '该等级对应的基础提成比例',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for promotion_poster
-- ----------------------------
DROP TABLE IF EXISTS `promotion_poster`;
CREATE TABLE `promotion_poster`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '海报标题',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '海报描述',
  `image_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '海报图片URL',
  `sort_order` int(11) NOT NULL DEFAULT 0 COMMENT '排序字段',
  `is_enabled` tinyint(1) 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 '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_promotion_poster_enabled`(`is_enabled`) USING BTREE,
  INDEX `idx_promotion_poster_sort`(`sort_order`) USING BTREE,
  INDEX `idx_promotion_poster_create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for revenue_config
-- ----------------------------
DROP TABLE IF EXISTS `revenue_config`;
CREATE TABLE `revenue_config`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `config_key` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '配置键',
  `config_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '配置类型（video/workflow/promotion）',
  `target_count` int(11) NULL DEFAULT NULL COMMENT '目标次数（视频播放次数/工作流复制次数）',
  `reward_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT '奖励金额',
  `level` int(11) NULL DEFAULT NULL COMMENT '推广等级',
  `level_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '推广等级名称',
  `min_fans` int(11) NULL DEFAULT NULL COMMENT '最小粉丝数',
  `commission_rate` decimal(5, 4) NULL DEFAULT NULL COMMENT '提成比例',
  `config_value` decimal(10, 4) NULL DEFAULT NULL COMMENT '配置值',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '配置说明',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_revenue_config_type`(`config_type`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for system_config
-- ----------------------------
DROP TABLE IF EXISTS `system_config`;
CREATE TABLE `system_config`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `config_key` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '配置键 (如: ai.queue.max_concurrent)',
  `config_value` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '配置值',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '配置说明',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `config_key`(`config_key`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 13 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '系统配置表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for system_message
-- ----------------------------
DROP TABLE IF EXISTS `system_message`;
CREATE TABLE `system_message`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '接收用户ID',
  `title` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '消息标题',
  `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '消息内容',
  `is_read` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已读',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '手机号，唯一（微信登录用户可为空）',
  `wechat_openid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '微信openid，用于微信登录',
  `username` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户名，唯一',
  `real_username` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '真实用户名',
  `id_number` varchar(18) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '身份证号码',
  `password_jwt` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'JWT加密密码（微信登录用户可为空）',
  `role` tinyint(4) NOT NULL DEFAULT 1 COMMENT '角色（0游客/1普通/2VIP/3SVIP）',
  `membership_expires_at` datetime NULL DEFAULT NULL COMMENT '会员到期时间',
  `avatar_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '头像URL',
  `is_verified` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否实名认证 (0-未认证, 1-已认证)',
  `invite_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '推广码',
  `inviter_id` bigint(20) NULL DEFAULT NULL COMMENT '邀请人ID',
  `promotion_level` tinyint(4) NOT NULL DEFAULT 0 COMMENT '推广等级',
  `points` int(11) NOT NULL DEFAULT 0 COMMENT '积分余额',
  `points_expires_at` datetime NULL DEFAULT NULL COMMENT '积分过期时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '注册时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `username`(`username`) USING BTREE,
  UNIQUE INDEX `phone`(`phone`) USING BTREE,
  UNIQUE INDEX `invite_code`(`invite_code`) USING BTREE,
  UNIQUE INDEX `uk_user_wechat_openid`(`wechat_openid`) USING BTREE,
  INDEX `idx_user_wechat_openid`(`wechat_openid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 17650006271322432 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for user_balance
-- ----------------------------
DROP TABLE IF EXISTS `user_balance`;
CREATE TABLE `user_balance`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '用户ID',
  `balance` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '当前余额',
  `total_income` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '累计总收入',
  `total_withdrawn` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '累计提现总额',
  `frozen_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '冻结金额（提现中）',
  `last_updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_user_balance`(`user_id`) USING BTREE,
  INDEX `idx_user_balance_user_id`(`user_id`) USING BTREE,
  INDEX `idx_user_balance_balance`(`balance`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 78 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for user_balance_log
-- ----------------------------
DROP TABLE IF EXISTS `user_balance_log`;
CREATE TABLE `user_balance_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '用户ID',
  `change_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '变动类型（income/withdraw/freeze/unfreeze）',
  `change_amount` decimal(10, 2) NOT NULL COMMENT '变动金额（正数为增加，负数为减少）',
  `balance_before` decimal(10, 2) NOT NULL COMMENT '变动前余额',
  `balance_after` decimal(10, 2) NOT NULL COMMENT '变动后余额',
  `source_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '来源类型（promotion/workflow/video/withdraw）',
  `source_id` bigint(20) NULL DEFAULT NULL COMMENT '来源ID（订单ID、提现ID等）',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '变动描述',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_user_balance_log_user_id`(`user_id`) USING BTREE,
  INDEX `idx_user_balance_log_change_type`(`change_type`) USING BTREE,
  INDEX `idx_user_balance_log_create_time`(`create_time`) USING BTREE,
  INDEX `idx_user_balance_log_source`(`source_type`, `source_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 78 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for user_video_progress
-- ----------------------------
DROP TABLE IF EXISTS `user_video_progress`;
CREATE TABLE `user_video_progress`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL,
  `course_id` bigint(20) NOT NULL,
  `chapter_id` bigint(20) NOT NULL,
  `video_id` bigint(20) NOT NULL,
  `progress_sec` int(11) NOT NULL DEFAULT 0 COMMENT '已观看秒数',
  `progress_pct` float NOT NULL DEFAULT 0 COMMENT '进度百分比',
  `last_watch_at` datetime NULL DEFAULT NULL COMMENT '最后观看时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for video
-- ----------------------------
DROP TABLE IF EXISTS `video`;
CREATE TABLE `video`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '视频标题',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '视频描述',
  `owner_id` bigint(20) NOT NULL COMMENT '创建者ID',
  `cover_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '封面图片URL',
  `vod_video_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '阿里云VOD视频ID',
  `duration` int(11) NULL DEFAULT NULL COMMENT '视频时长(秒)',
  `view_count` int(11) NOT NULL DEFAULT 0 COMMENT '观看次数',
  `like_count` int(11) NOT NULL DEFAULT 0 COMMENT '点赞数量',
  `is_public` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否公开',
  `audit_status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '审核状态(0待审核/1通过/2拒绝)',
  `category` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '视频分类',
  `reject_reason` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '拒绝原因',
  `review_time` datetime NULL DEFAULT NULL COMMENT '审核时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_owner_id`(`owner_id`) USING BTREE,
  INDEX `idx_category`(`category`) USING BTREE,
  INDEX `idx_audit_status`(`audit_status`) USING BTREE,
  INDEX `idx_vod_video_id`(`vod_video_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 144 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for video_view_stat
-- ----------------------------
DROP TABLE IF EXISTS `video_view_stat`;
CREATE TABLE `video_view_stat`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `video_id` bigint(20) NOT NULL COMMENT '视频ID',
  `owner_id` bigint(20) NOT NULL COMMENT '视频创建者ID',
  `view_user_id` bigint(20) NOT NULL COMMENT '观看用户ID',
  `view_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '观看时间',
  `view_duration` int(11) NULL DEFAULT 0 COMMENT '观看时长（秒）',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_video_owner`(`owner_id`) USING BTREE,
  INDEX `idx_video_id`(`video_id`) USING BTREE,
  INDEX `idx_view_time`(`view_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 156 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wechat_keyword_reply
-- ----------------------------
DROP TABLE IF EXISTS `wechat_keyword_reply`;
CREATE TABLE `wechat_keyword_reply`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '关键词回复ID',
  `keyword` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '关键词',
  `match_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'exact' COMMENT '匹配类型：exact-精确匹配，fuzzy-模糊匹配，regex-正则匹配',
  `template_id` bigint(20) NOT NULL COMMENT '关联的消息模板ID',
  `is_enabled` tinyint(4) NULL DEFAULT 1 COMMENT '是否启用：0-禁用，1-启用',
  `priority` int(11) NULL DEFAULT 0 COMMENT '优先级，数字越大优先级越高',
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_keyword`(`keyword`) USING BTREE,
  INDEX `idx_match_type`(`match_type`) USING BTREE,
  INDEX `idx_template_id`(`template_id`) USING BTREE,
  INDEX `idx_enabled`(`is_enabled`) USING BTREE,
  INDEX `idx_priority`(`priority`) USING BTREE,
  CONSTRAINT `wechat_keyword_reply_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `wechat_message_template` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '微信关键词回复配置表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wechat_menu
-- ----------------------------
DROP TABLE IF EXISTS `wechat_menu`;
CREATE TABLE `wechat_menu`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '菜单ID',
  `parent_id` bigint(20) NULL DEFAULT 0 COMMENT '父菜单ID，0表示顶级菜单',
  `menu_name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '菜单名称，最多16个字符',
  `menu_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '菜单类型：click/view/miniprogram/scancode_push/scancode_waitmsg/pic_sysphoto/pic_photo_or_album/pic_weixin/location_select',
  `menu_key` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '菜单KEY值，click类型必须',
  `menu_url` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '网页链接，view类型必须',
  `media_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '媒体文件ID',
  `appid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '小程序appid，miniprogram类型必须',
  `pagepath` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '小程序页面路径，miniprogram类型必须',
  `sort_order` int(11) NULL DEFAULT 0 COMMENT '排序顺序',
  `is_enabled` tinyint(4) NULL DEFAULT 1 COMMENT '是否启用：0-禁用，1-启用',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '菜单描述',
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_parent_id`(`parent_id`) USING BTREE,
  INDEX `idx_sort_order`(`sort_order`) USING BTREE,
  INDEX `idx_menu_key`(`menu_key`) USING BTREE,
  INDEX `idx_enabled`(`is_enabled`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '微信菜单配置表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wechat_menu_publish_history
-- ----------------------------
DROP TABLE IF EXISTS `wechat_menu_publish_history`;
CREATE TABLE `wechat_menu_publish_history`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '发布历史ID',
  `menu_config` json NOT NULL COMMENT '菜单配置JSON',
  `publish_status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '发布状态：success/failed',
  `error_message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '错误信息',
  `publish_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '发布时间',
  `operator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作人',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_publish_status`(`publish_status`) USING BTREE,
  INDEX `idx_publish_time`(`publish_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '微信菜单发布历史表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wechat_message_template
-- ----------------------------
DROP TABLE IF EXISTS `wechat_message_template`;
CREATE TABLE `wechat_message_template`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '模板ID',
  `template_key` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '模板标识键',
  `template_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '模板名称',
  `template_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '模板类型：text/news/image/voice/video/music',
  `trigger_type` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '触发类型：subscribe/unsubscribe/scan/click/view/keyword',
  `trigger_value` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '触发值（如菜单key、关键词等）',
  `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '文本内容',
  `media_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '媒体文件ID',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '标题（图文消息用）',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '描述（图文消息用）',
  `pic_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '图片链接',
  `url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '跳转链接',
  `music_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '音乐链接',
  `hq_music_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '高质量音乐链接',
  `thumb_media_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '缩略图媒体ID',
  `is_enabled` tinyint(4) NULL DEFAULT 1 COMMENT '是否启用：0-禁用，1-启用',
  `priority` int(11) NULL DEFAULT 0 COMMENT '优先级，数字越大优先级越高',
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `template_key`(`template_key`) USING BTREE,
  INDEX `idx_template_key`(`template_key`) USING BTREE,
  INDEX `idx_trigger_type`(`trigger_type`) USING BTREE,
  INDEX `idx_trigger_value`(`trigger_value`) USING BTREE,
  INDEX `idx_enabled`(`is_enabled`) USING BTREE,
  INDEX `idx_priority`(`priority`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '微信消息模板配置表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wechat_news_article
-- ----------------------------
DROP TABLE IF EXISTS `wechat_news_article`;
CREATE TABLE `wechat_news_article`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '文章ID',
  `template_id` bigint(20) NOT NULL COMMENT '关联的消息模板ID',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文章标题',
  `author` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '作者',
  `digest` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '摘要',
  `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '文章内容',
  `content_source_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '原文链接',
  `thumb_media_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '缩略图媒体ID',
  `show_cover_pic` tinyint(4) NULL DEFAULT 0 COMMENT '是否显示封面：0-不显示，1-显示',
  `url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '点击跳转链接',
  `thumb_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '缩略图URL',
  `need_open_comment` tinyint(4) NULL DEFAULT 0 COMMENT '是否打开评论：0-不打开，1-打开',
  `only_fans_can_comment` tinyint(4) NULL DEFAULT 0 COMMENT '是否粉丝才可评论：0-所有人，1-仅粉丝',
  `sort_order` int(11) NULL DEFAULT 0 COMMENT '排序顺序',
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_template_id`(`template_id`) USING BTREE,
  INDEX `idx_sort_order`(`sort_order`) USING BTREE,
  CONSTRAINT `wechat_news_article_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `wechat_message_template` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '微信图文消息文章表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wechat_qr_code
-- ----------------------------
DROP TABLE IF EXISTS `wechat_qr_code`;
CREATE TABLE `wechat_qr_code`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `qr_code_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '二维码图片URL',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '二维码描述',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_wechat_qr_create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for withdraw_request
-- ----------------------------
DROP TABLE IF EXISTS `withdraw_request`;
CREATE TABLE `withdraw_request`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '用户ID',
  `amount` decimal(10, 2) NOT NULL COMMENT '提现金额',
  `withdraw_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '提现类型（promotion/workflow/video）',
  `content_id` bigint(20) NULL DEFAULT NULL COMMENT '作品ID（工作流或视频提现时）',
  `account_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '收款账户类型（alipay/wechat/bank）',
  `account` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '收款账户（支付宝账号/微信ID/银行卡号）',
  `account_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '收款人姓名',
  `bank_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '开户行名称（银行卡提现时必填）',
  `bank_branch` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '支行名称（银行卡提现时可选）',
  `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '状态（0待审核/1通过/2拒绝）',
  `reason` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '拒绝原因',
  `reviewer_id` bigint(20) NULL DEFAULT NULL COMMENT '审核人ID',
  `transaction_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '第三方交易流水号',
  `fee_amount` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '手续费金额',
  `actual_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT '实际到账金额',
  `processed_at` datetime NULL DEFAULT NULL COMMENT '处理完成时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '申请时间',
  `reviewed_at` datetime NULL DEFAULT NULL COMMENT '审核时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_withdraw_user_id`(`user_id`) USING BTREE,
  INDEX `idx_withdraw_status`(`status`) USING BTREE,
  INDEX `idx_withdraw_create_time`(`create_time`) USING BTREE,
  INDEX `idx_withdraw_type`(`withdraw_type`) USING BTREE,
  INDEX `idx_withdraw_content_id`(`content_id`) USING BTREE,
  INDEX `idx_withdraw_reviewer`(`reviewer_id`) USING BTREE,
  INDEX `idx_withdraw_transaction_no`(`transaction_no`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for workflow
-- ----------------------------
DROP TABLE IF EXISTS `workflow`;
CREATE TABLE `workflow`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '工作流名称',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '工作流的详细描述',
  `owner_id` bigint(20) NOT NULL COMMENT '创建者ID',
  `cover_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '封面图片URL',
  `detail_gallery` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '详情图集（JSON格式存储多张图片URL）',
  `video_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '关联预览视频ID（阿里云VOD视频ID）',
  `data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '存储工作流核心逻辑的JSON字符串',
  `data_file_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '工作流依赖文件地址（文件上传时的URL）',
  `like_count` int(11) NOT NULL DEFAULT 0 COMMENT '点赞数量',
  `is_public` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否公开',
  `full_access_role` tinyint(4) NOT NULL DEFAULT 1 COMMENT '查看完整data所需最低角色',
  `copy_access_role` tinyint(4) NOT NULL DEFAULT 1 COMMENT '复制所需最低角色',
  `price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '价格',
  `audit_status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '审核状态(0待审核/1通过/2拒绝)',
  `category` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '工作流分类',
  `category_id` bigint(20) NULL DEFAULT NULL COMMENT '关联类目ID',
  `rating` int(11) NULL DEFAULT NULL COMMENT '评分(1-5)',
  `reject_reason` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '拒绝原因',
  `review_time` datetime NULL DEFAULT NULL COMMENT '审核时间',
  `is_free` tinyint(1) NOT NULL DEFAULT 0 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 '更新时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_workflow_category_id`(`category_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 105 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for workflow_copy_stat
-- ----------------------------
DROP TABLE IF EXISTS `workflow_copy_stat`;
CREATE TABLE `workflow_copy_stat`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `workflow_id` bigint(20) NOT NULL COMMENT '工作流ID',
  `owner_id` bigint(20) NOT NULL COMMENT '工作流创建者ID',
  `copy_user_id` bigint(20) NOT NULL COMMENT '复制用户ID',
  `copy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '复制时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_workflow_owner`(`owner_id`) USING BTREE,
  INDEX `idx_workflow_id`(`workflow_id`) USING BTREE,
  INDEX `idx_copy_time`(`copy_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1620 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for workflow_like
-- ----------------------------
DROP TABLE IF EXISTS `workflow_like`;
CREATE TABLE `workflow_like`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint(20) NOT NULL COMMENT '点赞用户ID',
  `workflow_id` bigint(20) NOT NULL COMMENT '被点赞的工作流ID',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '点赞时间',
  `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_user_workflow`(`user_id`, `workflow_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 30 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- View structure for v_plaza_latest_works
-- ----------------------------
DROP VIEW IF EXISTS `v_plaza_latest_works`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_plaza_latest_works` AS select `pw`.`id` AS `id`,`pw`.`work_no` AS `work_no`,`pw`.`user_id` AS `user_id`,`pw`.`task_no` AS `task_no`,`pw`.`task_type` AS `task_type`,`pw`.`model_name` AS `model_name`,`pw`.`prompt` AS `prompt`,`pw`.`result_url` AS `result_url`,`pw`.`image_url` AS `image_url`,`pw`.`aspect_ratio` AS `aspect_ratio`,`pw`.`title` AS `title`,`pw`.`description` AS `description`,`pw`.`tags` AS `tags`,`pw`.`view_count` AS `view_count`,`pw`.`like_count` AS `like_count`,`pw`.`share_count` AS `share_count`,`pw`.`comment_count` AS `comment_count`,`pw`.`is_public` AS `is_public`,`pw`.`status` AS `status`,`pw`.`audit_status` AS `audit_status`,`pw`.`audit_admin_id` AS `audit_admin_id`,`pw`.`audit_time` AS `audit_time`,`pw`.`audit_remark` AS `audit_remark`,`pw`.`create_time` AS `create_time`,`pw`.`update_time` AS `update_time`,`pw`.`is_deleted` AS `is_deleted` from `plaza_work` `pw` where ((`pw`.`status` = 'published') and (`pw`.`audit_status` = 'approved') and (`pw`.`is_deleted` = 0)) order by `pw`.`create_time` desc;

-- ----------------------------
-- View structure for v_plaza_pending_works
-- ----------------------------
DROP VIEW IF EXISTS `v_plaza_pending_works`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_plaza_pending_works` AS select `pw`.`id` AS `id`,`pw`.`work_no` AS `work_no`,`pw`.`user_id` AS `user_id`,`pw`.`task_no` AS `task_no`,`pw`.`task_type` AS `task_type`,`pw`.`model_name` AS `model_name`,`pw`.`prompt` AS `prompt`,`pw`.`result_url` AS `result_url`,`pw`.`image_url` AS `image_url`,`pw`.`aspect_ratio` AS `aspect_ratio`,`pw`.`title` AS `title`,`pw`.`description` AS `description`,`pw`.`tags` AS `tags`,`pw`.`view_count` AS `view_count`,`pw`.`like_count` AS `like_count`,`pw`.`share_count` AS `share_count`,`pw`.`comment_count` AS `comment_count`,`pw`.`is_public` AS `is_public`,`pw`.`status` AS `status`,`pw`.`audit_status` AS `audit_status`,`pw`.`audit_admin_id` AS `audit_admin_id`,`pw`.`audit_time` AS `audit_time`,`pw`.`audit_remark` AS `audit_remark`,`pw`.`create_time` AS `create_time`,`pw`.`update_time` AS `update_time`,`pw`.`is_deleted` AS `is_deleted`,`u`.`username` AS `author_name`,`u`.`phone` AS `author_phone` from (`plaza_work` `pw` left join `user` `u` on((`pw`.`user_id` = `u`.`id`))) where ((`pw`.`audit_status` = 'pending') and (`pw`.`is_deleted` = 0)) order by `pw`.`create_time`;

-- ----------------------------
-- View structure for v_points_recharge_stats
-- ----------------------------
DROP VIEW IF EXISTS `v_points_recharge_stats`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_points_recharge_stats` AS select cast(`o`.`create_time` as date) AS `recharge_date`,count(`o`.`id`) AS `order_count`,sum(`o`.`amount`) AS `total_amount`,sum(`o`.`points_amount`) AS `total_points`,avg(`o`.`amount`) AS `avg_amount` from `order` `o` where ((`o`.`order_type` = 2) and (`o`.`status` = 1) and (`o`.`is_deleted` = 0)) group by cast(`o`.`create_time` as date) order by `recharge_date` desc;

SET FOREIGN_KEY_CHECKS = 1;
