CREATE TABLE `goblin_sqb_mall_info` (
  `mid`        BIGINT       NOT NULL AUTO_INCREMENT,
  `mall_id`    VARCHAR(64)  NOT NULL COMMENT '商城唯一ID',
  `mall_sn`    VARCHAR(64)  NOT NULL COMMENT '收钱吧商城编号',
  `mall_name`  VARCHAR(128) NOT NULL COMMENT '商城名称',
  `signature`  VARCHAR(256) NOT NULL COMMENT '商城密钥',
  `store_id`   VARCHAR(64)  NOT NULL COMMENT '关联我方店铺ID',
  `status`     TINYINT      NOT NULL DEFAULT 1 COMMENT '0-禁用 1-启用',
  `created_at`    timestamp        NULL     DEFAULT NULL,
  `updated_at`    timestamp        NULL     DEFAULT NULL,
  PRIMARY KEY (`mid`),
  UNIQUE KEY `uk_mall_sn` (`mall_sn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='收钱吧商城信息';

CREATE TABLE `goblin_sqb_goods_ext` (
  `mid`            BIGINT      NOT NULL AUTO_INCREMENT,
  `spu_id`         VARCHAR(64) NOT NULL COMMENT '关联 goblin_goods.spu_id',
  `sku_id`         VARCHAR(64) NOT NULL COMMENT '关联 goblin_goods_sku.sku_id',
  `mall_sn`        VARCHAR(64) NOT NULL COMMENT '所属收钱吧商城编号',
  `signature` VARCHAR(64) NOT NULL COMMENT '商城密钥',
  `sqb_spu_id` VARCHAR(64) NOT NULL COMMENT '收钱吧SPU ID',
  `sqb_sku_id`     VARCHAR(64)          COMMENT '收钱吧SKU ID',
  `created_at`    timestamp        NULL     DEFAULT NULL,
  `updated_at`    timestamp        NULL     DEFAULT NULL,
  PRIMARY KEY (`mid`),
  UNIQUE KEY `uk_spu_sku` (`spu_id`, `sku_id`),
  KEY `idx_mall_sn` (`mall_sn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='收钱吧商品扩展信息';

CREATE TABLE `goblin_sqb_performance_goods` (
  `mid`             BIGINT      NOT NULL AUTO_INCREMENT,
  `performances_id` VARCHAR(64) NOT NULL COMMENT '演出ID',
  `spu_id`          VARCHAR(64) NOT NULL COMMENT '商品ID',
  `sku_id`          VARCHAR(64) NOT NULL COMMENT 'SKU ID',
  `sort`            INT         NOT NULL DEFAULT 0 COMMENT '排序权重',
  `settlement_price` DECIMAL(10,2) DEFAULT NULL COMMENT '换购价格（不设置则按商品售价售卖）',
  `status`          TINYINT     NOT NULL DEFAULT 1 COMMENT '0-禁用 1-启用',
  `created_at`    timestamp        NULL     DEFAULT NULL,
  `updated_at`    timestamp        NULL     DEFAULT NULL,
  PRIMARY KEY (`mid`),
  UNIQUE KEY `uk_perf_sku` (`performances_id`, `sku_id`),
  KEY `idx_performances_id` (`performances_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='演出-收钱吧商品关联';

CREATE TABLE `goblin_sqb_order` (
  `mid`                   BIGINT       NOT NULL AUTO_INCREMENT,
  `order_id`              VARCHAR(64)  NOT NULL COMMENT '本地订单ID',
  `user_id`               VARCHAR(64)  NOT NULL COMMENT '用户ID',
  `performances_id`       VARCHAR(64)  NOT NULL COMMENT '关联演出ID',
  `spu_id`                VARCHAR(64)  NOT NULL COMMENT '商品ID',
  `sku_id`                VARCHAR(64)  NOT NULL COMMENT 'SKU ID',
  `quantity`              INT          NOT NULL DEFAULT 1,
  `amount`                BIGINT       NOT NULL COMMENT '支付金额（分）',
  `sqb_order_sn`          VARCHAR(64)           COMMENT '收钱吧订单号',
  `sqb_order_signature`   VARCHAR(256)          COMMENT '收钱吧订单签名',
  `sqb_acquiring_sn`      VARCHAR(64)           COMMENT '收钱吧收单号',
  `sqb_acquiring_sign`    VARCHAR(255)     DEFAULT ''  COMMENT '收钱吧收单密钥',
  `sqb_checkout_items_id` VARCHAR(64)           COMMENT '结算明细ID',
  `coupon_sn`             VARCHAR(64)           COMMENT '券码编号',
  `coupon_qr_code`        VARCHAR(512)          COMMENT '核销二维码',
  `coupon_expire_time`    DATETIME              COMMENT '券码过期时间',
  `status`                TINYINT      NOT NULL DEFAULT 0 COMMENT '0-待支付 1-已支付 2-已核销 3-已退款 4-退款中 9-失败',
  `refund_reason`         VARCHAR(256)          COMMENT '退款原因',
  `sqb_refund_sn`         VARCHAR(256)          COMMENT '收钱吧-退款号',
  `sqb_refund_signature`         VARCHAR(256)          COMMENT '收钱吧-退款号密码',
  `created_at`    timestamp        NULL     DEFAULT NULL,
  `updated_at`    timestamp        NULL     DEFAULT NULL,
  PRIMARY KEY (`mid`),
  UNIQUE KEY `uk_order_id` (`order_id`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_performances_id` (`performances_id`),
  KEY `idx_sqb_acquiring_sn` (`sqb_acquiring_sn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='收钱吧订单';

CREATE TABLE `goblin_sqb_performance_config` (
                                                 `mid` bigint(20) NOT NULL AUTO_INCREMENT,
                                                 `performances_id` varchar(64) NOT NULL COMMENT '演出ID',
                                                 `auto_offline` tinyint(4) DEFAULT '0' COMMENT '演出结束自动下架 0-否 1-是',
                                                 `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
                                                 `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                                                 PRIMARY KEY (`mid`),
                                                 UNIQUE KEY `uk_perf_id` (`performances_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='收钱吧演出级全局配置';
-- 2026-03-30 增加逻辑删除及审计建议字段
ALTER TABLE `goblin_sqb_goods_ext` ADD COLUMN `updated_by` varchar(64) DEFAULT NULL COMMENT '更新人' AFTER `updated_at`;
ALTER TABLE `goblin_sqb_goods_ext` ADD COLUMN `del_flg` char(1) DEFAULT '0' COMMENT '删除标记[0-未删除|1-删除]' AFTER `updated_by`;
ALTER TABLE `goblin_sqb_goods_ext` ADD COLUMN `deleted_by` varchar(64) DEFAULT NULL COMMENT '删除人' AFTER `del_flg`;
ALTER TABLE `goblin_sqb_goods_ext` ADD COLUMN `deleted_at` timestamp NULL DEFAULT NULL COMMENT '删除时间' AFTER `deleted_by`;
