create database if not exists ln_scene character set utf8mb4 collate utf8mb4_unicode_ci;
-- >>------------------------------------------------------------------------------------
use ln_scene;

-- 积分活动表
drop TABLE if exists `sweet_integral_activity`;
CREATE TABLE `sweet_integral_activity`
(
    `mid`                  bigint unsigned NOT NULL AUTO_INCREMENT,
    `integral_activity_id` varchar(255)    NOT NULL DEFAULT '' COMMENT '活动id',
    `activity_title`       varchar(255)    NOT NULL DEFAULT '' COMMENT '活动名称',
    `activity_img`         varchar(255)    NOT NULL DEFAULT '' COMMENT '活动图片',
    `activity_type`        tinyint         NOT NULL DEFAULT 0 COMMENT '活动类型 1转盘',
    `time_type`            tinyint         NOT NULL DEFAULT 0 COMMENT '活动时间类型 1长期 2开始结束时间',
    `start_time`           datetime        NULL     DEFAULT NULL COMMENT '如果活动有时间限制 开始时间',
    `end_time`             datetime        NULL     DEFAULT NULL COMMENT '如果活动有时间限制 结束时间',
    `express_fee_type`     tinyint         NOT NULL DEFAULT 0 COMMENT '快递费用类型 1包邮 2到付',
    `activity_rules`       text            NULL     DEFAULT NULL COMMENT '活动规则',
    `is_online`            tinyint         NOT NULL DEFAULT 0 COMMENT '是否上线 1未上线 2已上线',
    `created_at`           datetime        NULL     DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at`           datetime        NULL     DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    PRIMARY KEY (`mid`),
    KEY `sweet_integral_activity_id` (`integral_activity_id`),
    KEY `sweet_integral_activity_title` (`activity_title`)
) ENGINE = InnoDB
  DEFAULT CHARSET utf8mb4
  COLLATE utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT '积分活动表';

-- 积分活动奖品表
drop TABLE if exists `sweet_integral_activity_prize`;
CREATE TABLE `sweet_integral_activity_prize`
(
    `mid`                  bigint unsigned NOT NULL AUTO_INCREMENT,
    `prize_id`             varchar(255)    NOT NULL DEFAULT '' COMMENT '奖品id',
    `integral_activity_id` varchar(255)    NOT NULL DEFAULT '' COMMENT '关联活动id',
    `prize_title`          varchar(255)    NOT NULL DEFAULT '' COMMENT '奖品名称',
    `prize_img`            varchar(255)    NOT NULL DEFAULT '' COMMENT '奖品图片',
    `prize_type`           tinyint         NOT NULL DEFAULT 0 COMMENT '奖品类型 1谢谢惠顾 2积分 3优惠券 4实物',
    `relation_id`          varchar(255)    NOT NULL DEFAULT '' COMMENT '关联id 如商品id 券id',
    `prize_num`            int             NOT NULL DEFAULT 0 COMMENT '奖品数量',
    `winners_num`          int             NOT NULL DEFAULT 0 COMMENT '限制的中奖人数',
    `winning_probability`  decimal         NOT NULL DEFAULT 0 COMMENT '中奖概率',
    `created_at`           datetime        NULL     DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at`           datetime        NULL     DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    PRIMARY KEY (`mid`),
    KEY `sweet_prize_id` (`prize_id`),
    KEY `sweet_prize_integral_activity_id` (`integral_activity_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET utf8mb4
  COLLATE utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT '积分活动奖品表';

-- 积分活动抽奖记录表
drop TABLE if exists `sweet_integral_activity_draw`;
CREATE TABLE `sweet_integral_activity_draw`
(
    `mid`                    bigint unsigned NOT NULL AUTO_INCREMENT,
    `draw_id`                varchar(255)    NOT NULL DEFAULT '' COMMENT '抽奖id',
    `integral_activity_id`   varchar(255)    NOT NULL DEFAULT '' COMMENT '关联活动id',
    `prize_id`               varchar(255)    NOT NULL DEFAULT '' COMMENT '关联奖品id',
    `user_id`                varchar(255)    NOT NULL DEFAULT '' COMMENT '关联用户id',
    `receiving_addresses_id` varchar(255)    NOT NULL DEFAULT '' COMMENT 'adam收货地址addresses_id',
    `receiving_name`         varchar(255)    NOT NULL DEFAULT '' COMMENT 'adam收货人姓名',
    `receiving_phone`        varchar(255)    NOT NULL DEFAULT '' COMMENT 'adam收货人手机号',
    `receiving_address`      varchar(255)    NOT NULL DEFAULT '' COMMENT 'adam收货人完整地址 空格隔离省市区详细地址',
    `receiving_status`       smallint        NOT NULL DEFAULT 1 COMMENT '收货状态 1中奖未发放 2已发放',
    `created_at`             datetime        NULL     DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at`             datetime        NULL     DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    PRIMARY KEY (`mid`),
    KEY `sweet_draw_id` (`draw_id`),
    KEY `sweet_draw_integral_activity_id` (`integral_activity_id`),
    KEY `sweet_draw_prize_id` (`prize_id`),
    KEY `sweet_draw_user_id` (`user_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET utf8mb4
  COLLATE utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT '积分活动抽奖记录表';