create database points_sys;
use points_sys;
create table userinfo
(
    id               int(10) primary key auto_increment,
    open_id          varchar(50)  not null unique,
    nickname         varchar(30)  not null,
    head_image       varchar(200) not null,
    gender           tinyint(2)   null default -1,
    province         varchar(5)   null,
    city             varchar(20)  null,
    parent_id        int(10)      null default 0 comment '推荐人id',
    first_login_time datetime          default current_timestamp,
    update_time      datetime     null on update current_timestamp,
    status           tinyint(2)        default 1
) engine = innodb collate = 'utf8mb4_general_ci' comment '用户表';

create table point
(
    uid          int(10) primary key,
    total_point  int(10)  not null,
    valid_point  int(10)  not null,
    expire_point int(10)  null default 0,
    expire_time  datetime null,
    update_time  datetime null on update current_timestamp
) engine = innodb collate = 'utf8mb4_general_ci' comment '积分表';
create table point_record
(
    id                  bigint(15) primary key auto_increment,
    uid                 int(10)      not null,
    point               int(10)      not null,
    current_total_point int(10)      not null,
    reason              varchar(100) not null,
    valid_time          datetime     null,
    expire_time         datetime     null
) engine = innodb collate = 'utf8mb4_general_ci' comment '积分记录表';

create table sign_record
(
    id          bigint(15) primary key auto_increment,
    uid         int(10)     not null,
    point       int(10)     not null,
    ip          varchar(50) not null,
    create_time datetime    default current_timestamp
) engine = innodb collate = 'utf8mb4_general_ci' comment '打卡记录表';
    create_time datetime default current_timestamp
) engine = innodb comment '打卡记录表';

create table goods
(
    id           bigint(15) primary key auto_increment,
    category     tinyint(2)       null         default 1 comment '商品类别(1:普通 2:精选 3:秒杀 4:抽奖)',
    type         tinyint(2)       null         default 1 comment '商品类型(1:实物 2:虚拟)',
    title        varchar(50)      not null,
    origin_price int(10) unsigned comment '原价' default 0,
    price        int(10) unsigned not null comment '价格',
    stock        int(10) unsigned not null comment '库存数量',
    limit_count  int(10) unsigned null         default 1 comment '购买最大数量(0表示不限制)',
    cover        varchar(200)     not null comment '商品图',
    description  text             not null comment '描述',
    notice       varchar(500)     null comment '提示',
    online_time  datetime         not null comment '上架时间',
    offline_time datetime         not null comment '下架时间',
    create_time  datetime                      default current_timestamp,
    update_time  datetime         null on update current_timestamp,
    status       tinyint(2)                    default 1,
    index ix_title (title)
) engine = innodb comment '商品表';

create table order_info
(
    id          varchar(50) not null comment '订单编号',
    gid         bigint(15)  not null comment '商品编号',
    price       int(10)     not null comment '价格',
    uid         int(10)     not null comment '用户编号',
    data        json     null comment '订单数据',
    create_time datetime   default current_timestamp,
    update_time datetime    null on update current_timestamp,
    status      tinyint(2) default 1 comment '订单状态(0:已删除 1:待确认 2:已取消 3:已完成)'
) comment '订单表';