use dev_ln_scene;
# -- >>------------------------------------------------------------------------------------
alter table adam_real_name add node tinyint default 2 not null comment '认证节点[2-二要素|3-三要素]' after type;

alter table goblin_goods add spu_type tinyint default 0 not null comment '商品类型[0-常规|1-数字藏品]' after spu_no;
alter table goblin_goods add attention varchar(256) null comment '注意事项' after details;
alter table goblin_goods add sale_start_time datetime null comment '开售时间' after shelves_time;
alter table goblin_goods add sale_stop_time datetime null comment '停售时间' after sale_start_time;
alter table goblin_goods add author varchar(100) null comment '创作者' after spu_appear;
alter table goblin_goods add spu_canbuy char null comment '是否购买[0-否|1-是]' after spu_appear;
alter table goblin_goods add publisher varchar(100) null comment '发行方' after author;
# alter table goblin_goods add has_box tinyint default 0 null comment '存在盲盒[0-否|1-是]' after spu_appear;

alter table goblin_goods_sku add sku_type tinyint default 0 not null comment '商品类型[0-常规|1-数字藏品]' after sku_no;
alter table goblin_goods_sku add sku_watch varchar(256) null comment '展示文件URL' after sku_pic;
alter table goblin_goods_sku add watch_type char null comment '展示文件类型[1-图片|2-视频|3-模型]' after sku_watch;
alter table goblin_goods_sku add intro varchar(256) null comment '简介' after weight;
alter table goblin_goods_sku add details text null comment '详情' after intro;

# alter table goblin_goods_sku add gift_stock int null comment '兑换库存' after sku_stock;
alter table goblin_goods_sku add price_v decimal(20, 2) null comment '苹果商品价格' after price;
alter table goblin_goods_sku add product_id varchar(20) null comment '苹果商品价格ID' after price_v;
alter table goblin_goods_sku add shelves_handle char default '1' comment '上架处理方式[1-等待手动上架|2-直接上架售卖|3-预约定时上架]' after store_id;
alter table goblin_goods_sku add shelves_time datetime null comment '预约上架时间[上架处理方式为3-预约定时上架时需要指定]' after shelves_handle;
alter table goblin_goods_sku add sale_start_time datetime null comment '开售时间' after shelves_time;
alter table goblin_goods_sku add sale_stop_time datetime null comment '停售时间' after sale_start_time;

alter table goblin_goods_sku add soldout_status char default '0' not null comment '是否售罄[0-否|1-是]' after shelves_status;
alter table goblin_goods_sku add sku_canbuy char null comment '是否购买[0-否|1-是]' after sku_appear;
alter table goblin_goods_sku add unbox char default '0' not null null comment '是否盲盒[0-否|1-是]' after sku_canbuy;
alter table goblin_goods_sku add hit_ratio decimal(8, 2) null comment '盲盒命中率[0.01~100%]' after unbox;
alter table goblin_goods_sku add opening_time datetime null comment '盲盒开启时间' after hit_ratio;
alter table goblin_goods_sku add opening_limit int default 0 comment '盲盒开启时限[单位秒]' after opening_time;

# alter table goblin_goods_sku add route_type varchar(20) null comment 'NFT路由' after opening_limit;
# alter table goblin_goods_sku add material_type char null comment '素材原始文件类型[1-图片|2-视频|3-模型]' after watch_type;
# alter table goblin_goods_sku add material_url varchar(256) null comment '素材原始文件URL' after material_type;
# alter table goblin_goods_sku add upchain tinyint default 0 null comment 'NFT上传声明状态[0-待上传|1-已声明|2-声明失败|9-声明中]' after route_type;
# alter table goblin_goods_sku add display_url varchar(500) null comment 'NFT预览图URL' after upchain;
# alter table goblin_goods_sku add nft_url varchar(500) null comment 'NFT素材访问URL' after display_url;
# alter table goblin_goods_sku add series_id varchar(256) null comment 'NFT系列ID' after nft_url;
# alter table goblin_goods_sku add series_hash varchar(256) null comment 'NFT系列HASH' after series_id;
# alter table goblin_goods_sku add nft_hash varchar(25) null comment 'NFT藏品HASH' after series_hash;
# alter table goblin_goods_sku add declare_at varchar(25) null comment 'NFT系列声明时间' after nft_hash;
# -- >>------------------------------------------------------------------------------------
drop table if exists goblin_goods_sku_nft;
create table goblin_goods_sku_nft
(
    mid           bigint auto_increment primary key,
    sku_id        varchar(64)  not null comment '单品id',
    route_type    varchar(20)  null comment 'NFT路由',
    material_type char         null comment '素材原始文件类型[1-图片|2-视频|3-模型]',
    material_url  varchar(256) null comment '素材原始文件URL',
    upchain       tinyint default 0 comment 'NFT上传声明状态[0-待上传|1-已声明|2-声明失败|9-声明中]',
    display_url   varchar(500) null comment 'NFT预览图URL',
    nft_url       varchar(500) null comment 'NFT素材访问URL',
    series_id     varchar(256) null comment 'NFT系列ID',
    series_hash   varchar(256) null comment 'NFT系列HASH',
    nft_hash      varchar(256)  null comment 'NFT藏品HASH',
    declare_at    varchar(25)  null comment 'NFT系列声明时间',
    created_at    datetime     not null,
    updated_at    datetime     null,
    comment       varchar(255)
) engine = InnoDB comment '商品NFT信息';

create unique index uidx_ggsn_sku_id on goblin_goods_sku_nft (sku_id);
# -- >>------------------------------------------------------------------------------------
# -- >>------------------------------------------------------------------------------------
drop table if exists goblin_goods_sku_tag;
create table goblin_goods_sku_tag
(
    mid        bigint auto_increment primary key,
    sku_id     varchar(64) not null comment '商品id',
    tag_id     varchar(30) not null comment '标签id，对应 goblin_self_tag.tag_id',
    sort       int  default 0 comment '排序[数值越小,排序越前]',
    tag_belong char default '0' comment '标签所属[0-普通标签|1-专属标签]',
    del_flg    char default '0' comment '删除标记[0-未删除|1-删除]',
    comment    varchar(255)
) engine = InnoDB comment '商品关联标签';

create unique index uidx_ggst_sku_tag on goblin_goods_sku_tag (sku_id, tag_id);
# -- >>------------------------------------------------------------------------------------
drop table if exists goblin_user_digital_artwork;
create table goblin_user_digital_artwork
(
    mid            bigint auto_increment primary key,
    artwork_id     varchar(64)  not null comment '藏品ID',
    uid            varchar(64)  not null comment '用户UID',
    sku_id         varchar(64)  not null comment '单品ID',
    order_id       varchar(64)  not null comment '藏品订单号',
    edition_sn     int          null comment '序列号',
    nft_id         varchar(256) null comment '藏品NFT ID',
    release_txhash varchar(256) null comment '发行HASH',
    release_at     varchar(25)  null comment '发行时间',
    trading_txhash varchar(256) null comment '发放HASH',
    trading_at     varchar(25)  null comment '交易时间',

    source         tinyint      null comment '获得方式[1-购买|2-兑换|3-赠送|5-受赠]',
    state          tinyint default 0 comment '藏品状态[0-生成中/未开启|1-已生成/已开启|2-生成失败/开启失败]',

    del_flg        char    default '0' comment '删除标记[0-未删除|1-删除]',
    opening_at     datetime     null comment '盲盒开启时间',
    created_at     datetime     not null,
    updated_at     datetime     null,
    deleted_at     datetime     null,
    comment        varchar(500)
) engine = InnoDB comment '用户数字藏品信息';
# -- >>------------------------------------------------------------------------------------
drop table if exists goblin_goods_sku_excode;
create table goblin_goods_sku_excode
(
    mid        bigint auto_increment primary key,
    sku_id     varchar(64) not null comment '单品ID',
    num        int comment '生成数量',
    type       tinyint comment '兑换码类型[0-普通商品|1-数字藏品|2-数字藏品盲盒]',

    code       varchar(64) not null comment '单品兑换码',
    state      tinyint default 0 comment '兑换码状态[0-未兑换|1-已兑换|10-用作生成模版]',
    start_at   datetime    null comment '开始时间',
    stop_at    datetime    null comment '截止时间',

    redeem_uid varchar(64) comment '兑换用户UID',
    redeem_for varchar(128) comment '兑换内容描述',
    redeem_at  datetime comment '兑换时间',

    operator   varchar(64),
    created_at datetime    not null,
    updated_at datetime    null,
    deleted_at datetime    null,
    comment    varchar(500)
) engine = InnoDB comment '单品兑换码';

create index idx_ggse_sku_id on goblin_goods_sku_excode (sku_id);
# -- >>------------------------------------------------------------------------------------

DROP TABLE IF EXISTS goblin_nft_order;
CREATE TABLE goblin_nft_order
(
    mid                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    order_id             VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '订单id',
    spu_id               VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '商品id',
    sku_id               VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '款式id',
    box_sku_id           VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '盲盒抽取的款式id',
    num                  INT UNSIGNED     NOT NULL DEFAULT 0 COMMENT '数量',
    store_id             VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '店铺id',
    store_name           VARCHAR(255)     NOT NULL DEFAULT '' COMMENT '商铺名称',
    order_code           VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '订单号',
    user_id              VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '用户id',
    user_name            VARCHAR(50)      NOT NULL DEFAULT '' COMMENT '用户昵称',
    user_mobile          VARCHAR(30)      NOT NULL DEFAULT '' COMMENT '用户手机号',
    price_total          DECIMAL(8, 2)    NOT NULL DEFAULT 0 COMMENT '应付金额',
    price_coupon         DECIMAL(8, 2)    NOT NULL DEFAULT 0 COMMENT '券优惠金额',
    store_price_coupon   DECIMAL(8, 2)    NOT NULL DEFAULT 0 COMMENT '商铺券优惠金额',
    price_red_envelope   DECIMAL(8, 2)    NOT NULL DEFAULT 0 COMMENT '红包优惠金额',
    price_voucher        DECIMAL(8, 2)    NOT NULL DEFAULT 0 COMMENT '总优惠价格',
    price_actual         DECIMAL(8, 2)    NOT NULL DEFAULT 0 COMMENT '实付金额',
    ucoupon_id           VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '券id',
    store_coupon_id      VARCHAR(255)     NOT NULL DEFAULT '' COMMENT '商铺券id',
    red_envelope_code    VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '红包code',
    status               TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单状态 1待付款 2已付款 3未付款取消订单 4退款中 5已退款',
    source               VARCHAR(32)      NOT NULL DEFAULT '' COMMENT '订单来源 app h5 applet',
    order_type           TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单类型 1购买订单 2兑换订单 3演出赠送订单',
    pay_type             VARCHAR(32)      NOT NULL DEFAULT '' COMMENT '支付类型 wepay微信 alipay阿里 douyinpay抖音 unionpay银联 applepay苹果支付',
    device_from          VARCHAR(32)      NOT NULL DEFAULT '' COMMENT '支付终端 app wap js applet',
    version              VARCHAR(32)      NOT NULL DEFAULT '' COMMENT '版本号',
    pay_countdown_minute TINYINT UNSIGNED          DEFAULT 5 COMMENT '订单过期时间(分钟)',
    pay_time             DATETIME         NULL     DEFAULT NULL COMMENT '支付时间',
    pay_code             VARCHAR(64)      NOT NULL DEFAULT '' COMMENT '支付单号',
    payment_type         VARCHAR(32)      NOT NULL DEFAULT '' COMMENT '支付中心返回实际支付类型',
    payment_id           VARCHAR(128)     NOT NULL DEFAULT '' COMMENT '支付中心返回支付id',
    cancel_reason        VARCHAR(256)     NOT NULL DEFAULT '' COMMENT '取消原因',
    cancel_time          DATETIME         NULL     DEFAULT NULL COMMENT '取消时间',
    ip_address           VARCHAR(32)               DEFAULT '' COMMENT 'ip地址',
    created_at           DATETIME         NULL     DEFAULT NULL COMMENT '创建时间',
    updated_at           DATETIME         NULL     DEFAULT NULL COMMENT '更新时间',
    KEY `nft_order_id_index` (`order_id`),
    KEY `nft_order_code_index` (`order_code`),
    KEY `nft_store_id_index` (`store_id`),
    KEY `nft_sku_id_index` (`sku_id`),
    KEY `nft_user_id_index` (`user_id`),
    KEY `nft_ucoupon_id_index` (`ucoupon_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET utf8mb4
  COLLATE utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT 'NFT订单表';
# -- >>------------------------------------------------------------------------------------
DROP TABLE IF EXISTS goblin_nft_order_refund;
CREATE TABLE goblin_nft_order_refund
(
    mid             BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    order_refund_id VARCHAR(64)   NOT NULL DEFAULT '' COMMENT '订单退单表id',
    refund_code     VARCHAR(64)   NOT NULL DEFAULT '' COMMENT '退款单号',
    order_id        VARCHAR(64)   NOT NULL DEFAULT '' COMMENT '订单id',
    order_code      VARCHAR(64)   NOT NULL DEFAULT '' COMMENT '订单编号',
    store_id        VARCHAR(64)   NOT NULL DEFAULT '' COMMENT '商铺id',
    user_id         VARCHAR(64)   NOT NULL DEFAULT '' COMMENT '用户id',
    price           DECIMAL(8, 2) NOT NULL DEFAULT 0 COMMENT '退款金额',
    status          INT UNSIGNED  NOT NULL DEFAULT 0 COMMENT '退款状态 1申请 2退款成功 3退款失败',
    refund_at       DATETIME      NULL     DEFAULT NULL COMMENT '退款时间',
    error_reason    VARCHAR(255)  NOT NULL DEFAULT '' COMMENT '退款失败原因',
    created_at      DATETIME      NULL     DEFAULT NULL COMMENT '创建时间',
    updated_at      DATETIME      NULL     DEFAULT NULL COMMENT '更新时间',
    KEY `nft_refund__index` (`order_refund_id`),
    KEY `nft_refund_refund_code_index` (`refund_code`),
    KEY `nft_refund_order_id_index` (`order_id`),
    KEY `nft_refund_order_code_index` (`order_code`),
    KEY `nft_refund_store_id_index` (`store_id`),
    KEY `nft_refund_user_id_index` (`user_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET utf8mb4
  COLLATE utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT 'NFT订单退款表';
# -- >>------------------------------------------------------------------------------------
# -- >>------------------------------------------------------------------------------------
# -- >>------------------------------------------------------------------------------------


# ----              CONFIG 修改               ----
# ---- liquidnet-client-admin-web.yml url7: "/goblin/common/goods?type=0" #商品 url9: "/goblin/common/goods?type=1" #NFT