CREATE TABLE `nh_task_progress`
(
    `id`         int(11) unsigned NOT NULL AUTO_INCREMENT,
    `uid`        int(11) unsigned NOT NULL,
    `task_id`    int(11) unsigned NOT NULL COMMENT '任务id',
    `task_seq`   int(11)          NOT NULL COMMENT '用于可重复任务的序列号',
    `stage`      tinyint          NOT NULL DEFAULT 0 COMMENT '任务的阶段, 0:未完成 1:待校验 2:已完成未领取 3:已领取',
    `created_at` timestamp        NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at` timestamp        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    UNIQUE KEY `uid_task_id_seq` (`uid`, `task_id`, `task_seq`)
) COMMENT ='用户任务节点';

CREATE TABLE `nh_nft_holder`
(
    `id`         int unsigned NOT NULL AUTO_INCREMENT,
    `address`    varchar(80)  NOT NULL COMMENT '钱包地址',
    `token_id`   varchar(32)  NOT NULL COMMENT 'token id',
    `balance`    int(11)      NOT NULL DEFAULT 0 COMMENT '余额',
    `update_seq` int          NOT NULL COMMENT '更新序列号',
    `created_at` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    UNIQUE KEY (`token_id`),
    INDEX (`update_seq`)
) COMMENT ='nft 持有表';

CREATE TABLE `nh_nft_holder_change_log`
(
    `id`         int unsigned NOT NULL AUTO_INCREMENT,
    `address`    varchar(80)  NOT NULL COMMENT '钱包地址',
    `token_id`   varchar(32)  NOT NULL COMMENT 'token id',
    `value`      int(11)      NOT NULL COMMENT '变化数量',
    `balance`    int(11)      NOT NULL COMMENT '余额',
    `created_at` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
) COMMENT ='nft 持有表变化日志';

CREATE TABLE `nh_task_nft_stake`
(
    `id`         int unsigned NOT NULL AUTO_INCREMENT,
    `uid`        int unsigned NOT NULL COMMENT '用户钱包',
    `role_id`    bigint unsigned NOT NULL COMMENT '角色id',
    `token_id`   varchar(32)  NOT NULL COMMENT 'token id',
    `state`      tinyint      NOT NULL DEFAULT 0 COMMENT '状态：1质押中， 0已取消质押',
    `created_at` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    UNIQUE KEY (`uid`, `token_id`)
) COMMENT ='nft质押表';

CREATE TABLE `nh_task_nft_stake_log`
(
    `id`         int unsigned NOT NULL AUTO_INCREMENT,
    `uid`        int unsigned NOT NULL COMMENT '用户钱包',
    `role_id`    bigint unsigned NOT NULL COMMENT '角色id',
    `address`    varchar(80)  NOT NULL COMMENT '钱包地址',
    `token_id`   varchar(32)  NOT NULL COMMENT 'token id',
    `award_seq`  int          NOT NULL COMMENT '派奖序列号',
    `balance`    int(11)      NOT NULL COMMENT '余额',
    `stake`      tinyint      NOT NULL DEFAULT 0 COMMENT '状态：1质押中， 0未质押',
    `created_at` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
) COMMENT ='派奖时nft质押日志表';

CREATE TABLE `nh_task_nft_stake_reward`
(
    `id`                 int unsigned   NOT NULL AUTO_INCREMENT,
    `uid`                int unsigned   NOT NULL COMMENT '用户钱包',
    `award_seq`          int            NOT NULL COMMENT '派奖序列号',
    `pledge_output`      decimal(18, 6) NOT NULL DEFAULT 0 COMMENT '质押产出代币',
    `random_coefficient` float          NOT NULL COMMENT '随机系数',
    `occupy_percent`     int            NOT NULL DEFAULT 100 COMMENT '占领百分比',
    `reward`             decimal(18, 6) NOT NULL DEFAULT 0 COMMENT '奖励金额',
    `sent`               bool           NOT NULL DEFAULT false COMMENT '是否已发放',
    `created_at`         timestamp      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at`         timestamp      NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    UNIQUE KEY (`uid`, `award_seq`)
) COMMENT ='nft质押派奖表';