
CREATE TABLE IF NOT EXISTS `{{prefix}}vr_seat_templates` (
    `id`           BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '模板ID',
    `name`         VARCHAR(180)    NOT NULL            COMMENT '模板名称',
    `category_id`  BIGINT UNSIGNED NOT NULL            COMMENT '绑定的分类ID',
    `seat_map`     LONGTEXT        NOT NULL            COMMENT '座位地图JSON',
    `spec_base_id_map` LONGTEXT    DEFAULT NULL        COMMENT '座位ID→spec_base_id映射',
    `status`       TINYINT UNSIGNED DEFAULT 1         COMMENT '状态：0禁用 1启用',
    `add_time`     INT UNSIGNED     DEFAULT 0           COMMENT '创建时间',
    `upd_time`     INT UNSIGNED     DEFAULT 0           COMMENT '更新时间',
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_category_id` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='VR票务座位模板';

CREATE TABLE IF NOT EXISTS `{{prefix}}vr_tickets` (
    `id`             BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '票ID',
    `order_id`       BIGINT UNSIGNED NOT NULL               COMMENT '订单ID',
    `order_no`       CHAR(60)        NOT NULL              COMMENT '订单号',
    `goods_id`       BIGINT UNSIGNED NOT NULL               COMMENT '商品ID',
    `goods_snapshot` TEXT            DEFAULT NULL           COMMENT '商品快照JSON',
    `user_id`        BIGINT UNSIGNED NOT NULL               COMMENT '用户ID',
    `ticket_code`    CHAR(36)        NOT NULL              COMMENT 'UUID票码',
    `qr_data`        TEXT            DEFAULT NULL           COMMENT '加密QR内容',
    `seat_info`      VARCHAR(255)    DEFAULT NULL          COMMENT '座位信息',
    `spec_base_id`   BIGINT UNSIGNED DEFAULT 0              COMMENT 'spec_base_id',
    `real_name`      VARCHAR(60)     DEFAULT NULL          COMMENT '观演人姓名',
    `phone`          CHAR(15)        DEFAULT NULL          COMMENT '观演人手机',
    `id_card`        CHAR(18)        DEFAULT NULL          COMMENT '观演人身份证',
    `verify_status`  TINYINT UNSIGNED DEFAULT 0             COMMENT '核销状态',
    `verify_time`    INT UNSIGNED     DEFAULT 0             COMMENT '核销时间',
    `verifier_id`    BIGINT UNSIGNED DEFAULT 0             COMMENT '核销员ID',
    `issued_at`      INT UNSIGNED     DEFAULT 0             COMMENT '票发放时间',
    `created_at`     INT UNSIGNED     DEFAULT 0             COMMENT '创建时间',
    `updated_at`     INT UNSIGNED     DEFAULT 0             COMMENT '更新时间',
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_ticket_code` (`ticket_code`),
    KEY `idx_order_id` (`order_id`),
    KEY `idx_user_id` (`user_id`),
    KEY `idx_goods_id` (`goods_id`),
    KEY `idx_verify_status` (`verify_status`),
    KEY `idx_created_at` (`created_at`),
    KEY `idx_spec_base_id` (`spec_base_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='VR票务电子票';

CREATE TABLE IF NOT EXISTS `{{prefix}}vr_verifiers` (
    `id`         BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '核销员ID',
    `user_id`    BIGINT UNSIGNED NOT NULL                COMMENT 'ShopXO用户ID',
    `name`       VARCHAR(60)    NOT NULL                  COMMENT '核销员名称',
    `status`     TINYINT UNSIGNED DEFAULT 1               COMMENT '状态',
    `created_at` INT UNSIGNED   DEFAULT 0                 COMMENT '创建时间',
    PRIMARY KEY (`id`),
    KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='VR票务核销员';

CREATE TABLE IF NOT EXISTS `{{prefix}}vr_verifications` (
    `id`             BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '记录ID',
    `ticket_id`      BIGINT UNSIGNED NOT NULL               COMMENT '票ID',
    `ticket_code`    CHAR(36)        NOT NULL               COMMENT '票码',
    `verifier_id`    BIGINT UNSIGNED NOT NULL               COMMENT '核销员ID',
    `verifier_name`  VARCHAR(60)     DEFAULT NULL          COMMENT '核销员名称',
    `goods_id`       BIGINT UNSIGNED DEFAULT 0              COMMENT '商品ID',
    `created_at`     INT UNSIGNED     DEFAULT 0             COMMENT '核销时间',
    PRIMARY KEY (`id`),
    KEY `idx_ticket_id` (`ticket_id`),
    KEY `idx_verifier_id` (`verifier_id`),
    KEY `idx_verified_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='VR票务核销记录';

CREATE TABLE IF NOT EXISTS `{{prefix}}vr_audit_log` (
    `id`             BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '日志ID',
    `action`         VARCHAR(60)     NOT NULL                COMMENT '操作类型',
    `operator_id`    BIGINT UNSIGNED DEFAULT 0              COMMENT '操作用户ID',
    `operator_name`  VARCHAR(90)     DEFAULT NULL           COMMENT '操作用户名',
    `target_type`    VARCHAR(60)     DEFAULT NULL          COMMENT '对象类型',
    `target_id`      BIGINT UNSIGNED DEFAULT 0              COMMENT '对象ID',
    `target_desc`    VARCHAR(255)    DEFAULT NULL           COMMENT '对象描述',
    `client_ip`      VARCHAR(45)     DEFAULT NULL          COMMENT '客户端IP',
    `user_agent`     VARCHAR(512)    DEFAULT NULL           COMMENT 'User-Agent',
    `request_id`     VARCHAR(64)     DEFAULT NULL           COMMENT '请求追踪ID',
    `extra`          LONGTEXT        DEFAULT NULL           COMMENT '附加数据JSON',
    `created_at`     INT UNSIGNED     DEFAULT 0             COMMENT '操作时间',
    PRIMARY KEY (`id`),
    KEY `idx_action` (`action`),
    KEY `idx_operator_id` (`operator_id`),
    KEY `idx_target` (`target_type`, `target_id`),
    KEY `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='VR票务审计日志';
