create database if not exists 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 '打卡记录表';