create table pet_house.goods
(
    id           bigint unsigned auto_increment
        primary key,
    name         varchar(191) not null,
    goods_type   bigint       not null,
    time         varchar(191) null,
    price        int          not null,
    parent_id    bigint       not null,
    buy_many     bigint       not null,
    goods_detail varchar(191) not null,
    create_time  timestamp default CURRENT_TIMESTAMP null
);

create table pet_house.order_details
(
    id           bigint unsigned auto_increment
        primary key,
    sub_order_id bigint not null,
    goods_id     bigint not null,
    amount       bigint not null
);

create index idx_order_details_goods_id
    on pet_house.order_details (goods_id);

create index idx_order_details_sub_order_id
    on pet_house.order_details (sub_order_id);

create table pet_house.order_mains
(
    id          bigint unsigned auto_increment
        primary key,
    order_id    varchar(191) not null,
    uid         bigint       not null,
    status      bigint null,
    create_time timestamp default CURRENT_TIMESTAMP null,
    constraint uni_order_mains_order_id
        unique (order_id)
);

create index idx_order_mains_order_id
    on pet_house.order_mains (order_id);

create index idx_order_mains_uid
    on pet_house.order_mains (uid);

create table pet_house.order_subs
(
    id              bigint unsigned auto_increment
        primary key,
    main_order_id   bigint null,
    status          bigint       not null,
    pet_id          bigint null,
    pay_type        bigint       not null,
    discount        bigint null,
    total_amount    int          not null,
    pay_amount      int null,
    pay_time        varchar(191) null,
    reserve_time    varchar(191) not null,
    service_time    varchar(191) null,
    service_addr_id bigint null,
    service_remark  varchar(191) null,
    create_time     timestamp default CURRENT_TIMESTAMP null,
    update_time     timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP
);

create index idx_order_subs_main_order_id
    on pet_house.order_subs (main_order_id);

create index idx_order_subs_pet_id
    on pet_house.order_subs (pet_id);

create table pet_house.pet_base_infos
(
    id          bigint unsigned auto_increment
        primary key,
    pet_type    bigint       not null,
    assortment  varchar(191) not null,
    size        bigint       not null,
    create_time timestamp default CURRENT_TIMESTAMP null
);

create table pet_house.pets
(
    id                bigint unsigned auto_increment
        primary key,
    uid               bigint                                 not null,
    nick_name         varchar(191)                           not null,
    head_img_type     bigint null,
    head_img_url      varchar(191) null,
    `desc`            varchar(191) null,
    precaution        varchar(191) null,
    gender            bigint null,
    birthday          varchar(191) null,
    pet_id            bigint null,
    eunuch            bigint null,
    last_service_proj varchar(191) default '' - '' null,
    last_service_date varchar(191) default '' - '' null,
    create_time       timestamp    default CURRENT_TIMESTAMP not null
);

create index idx_pets_uid
    on pet_house.pets (uid);

create table pet_house.service_addrs
(
    id        bigint unsigned auto_increment
        primary key,
    longitude varchar(191) null,
    latitude  varchar(191) null,
    addr      varchar(191) not null
);

create table pet_house.system_configs
(
    name        varchar(191) null,
    `desc`      varchar(191) null,
    config_type varchar(191) null,
    desc_type   bigint null
);

create table pet_house.user_service_addrs
(
    id          bigint unsigned auto_increment
        primary key,
    uid         bigint                              not null,
    name        varchar(191)                        not null,
    mobile      varchar(191)                        not null,
    area        varchar(191)                        not null,
    addr        varchar(191)                        not null,
    create_time timestamp default CURRENT_TIMESTAMP not null
);

create index idx_user_service_addrs_uid
    on pet_house.user_service_addrs (uid);

create table pet_house.users
(
    id           bigint unsigned auto_increment
        primary key,
    nick_name    varchar(191) null,
    head_img_url varchar(191) null,
    amount       bigint null,
    open_id      varchar(191)                        not null,
    union_id     varchar(191)                        not null,
    user_type    bigint null,
    mobile       varchar(191) null,
    role         bigint null,
    create_time  timestamp default CURRENT_TIMESTAMP not null,
    constraint uni_users_open_id
        unique (open_id),
    constraint uni_users_union_id
        unique (union_id)
);

create index idx_users_open_id
    on pet_house.users (open_id);

create index idx_users_union_id
    on pet_house.users (union_id);

