alter table conf_condition
    add app_platform varchar(255) default '*' not null comment '应用平台' after package_name;

create table pay_item
(
    id             bigint auto_increment
        primary key,
    sort           int default 0 not null comment '排序',
    code           varchar(255)  not null comment '商品编号，用于区分不同平台的相同商品',
    name           varchar(255)  not null comment '名称',
    amount         bigint        not null comment '价格',
    apple_goods_id varchar(255) null comment '苹果商品id',
    app_platform   int           not null comment '应用平台',
    package_name   varchar(255)  not null comment '应用包名',
    create_time    datetime      not null comment '创建时间',
    update_time    datetime      not null comment '更新时间',
    status         int default 0 not null,
    extra          json          not null comment '额外字段json',
    remark         varchar(255) null comment '备注'
) comment '商品表';

create table pay_item_channel
(
    id           bigint auto_increment
        primary key,
    item_id      bigint       not null,
    channel_name varchar(255) not null,
    amount       bigint       not null,
    create_time  datetime     not null,
    update_time  datetime     not null,
    status       int          not null
) comment '商品渠道表';

create index item_id
    on pay_item_channel (item_id);

create table pay_option
(
    id            bigint auto_increment
        primary key,
    package_name  varchar(255)  not null,
    app_platform  int           not null,
    title         varchar(255)  not null,
    pay_method    int           not null,
    pay_platform  int           not null,
    pay_config_id int           not null,
    sort          int default 0 not null,
    status        int default 0 not null,
    remark        varchar(255) null
);

create index package_name_index
    on pay_option (package_name);

create table pay_order
(
    id           bigint auto_increment
        primary key,
    out_trade_no varchar(128) not null comment '支付订单号',
    pay_status   int          not null comment '-- 0:已创建 1:未支付 2:已支付 3:已关闭 4:已退款',
    item_id      bigint       not null comment '商品id',
    item_code    varchar(255) not null comment '商品编号',
    item_name    varchar(255) not null comment '商品名称',
    amount       bigint       not null comment '商品价格',
    ssid         varchar(64)  not null comment '用户唯一标识',
    device_id    varchar(64)  not null comment '设备id',
    phone        varchar(64) null comment '电话号码',
    project_code varchar(255) null comment '产品编号',
    app_platform int          not null comment '应用平台',
    package_name varchar(255) not null comment '应用包名',
    channel_name varchar(255) null comment '渠道',
    ip           varchar(255) null comment 'id',
    create_time  datetime     not null comment '创建时间',
    update_time  datetime     not null comment '更新时间',
    status       int          not null,
    constraint out_trade_no_index
        unique (out_trade_no)
) comment '订单表';

