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 '所属收钱吧商城编号',
  `sqb_product_id` VARCHAR(64) NOT NULL COMMENT '收钱吧商品ID',
  `sqb_product_sn` VARCHAR(64) NOT NULL COMMENT '收钱吧商品编号',
  `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 '排序权重',
  `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_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 '退款原因',
  `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='收钱吧演出级全局配置';
