调整交易和账单模型,完善支付与用户余额基础处理逻辑

This commit is contained in:
2025-04-09 16:34:41 +08:00
parent 4c47a71f30
commit 02897db890
10 changed files with 203 additions and 85 deletions

View File

@@ -713,18 +713,23 @@ create table trade (
on update cascade
on delete cascade,
inner_no varchar(255) not null unique,
outer_no varchar(255) not null unique,
outer_no varchar(255),
type int not null,
subject varchar(255) not null,
remark varchar(255),
amount decimal(12, 2) not null default 0,
payment decimal(12, 2) not null default 0,
method int not null,
status int not null default 0,
paid_at timestamp,
cancel_at timestamp,
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
);
create index trade_user_id_index on trade (user_id);
create index trade_outer_no_index on trade (outer_no);
create index trade_type_index on trade (type);
create index trade_status_index on trade (status);
create index trade_deleted_at_index on trade (deleted_at);
@@ -734,59 +739,19 @@ comment on column trade.id is '订单ID';
comment on column trade.user_id is '用户ID';
comment on column trade.inner_no is '内部订单号';
comment on column trade.outer_no is '外部订单号';
comment on column trade.type is '订单类型0-充值余额1-购买产品';
comment on column trade.subject is '订单主题';
comment on column trade.remark is '订单备注';
comment on column trade.amount is '订单总金额';
comment on column trade.payment is '支付金额';
comment on column trade.method is '支付方式1-支付宝2-微信';
comment on column trade.status is '订单状态0-待支付1-已支付2-已取消3-已退款';
comment on column trade.paid_at is '支付时间';
comment on column trade.cancel_at is '取消时间';
comment on column trade.created_at is '创建时间';
comment on column trade.updated_at is '更新时间';
comment on column trade.deleted_at is '删除时间';
-- bill
drop table if exists bill cascade;
create table bill (
id serial primary key,
user_id int not null references "user" (id)
on update cascade
on delete cascade,
trade_id int references trade (id) --
on update cascade --
on delete set null,
resource_id int references resource (id) --
on update cascade --
on delete set null,
bill_no varchar(255) not null unique,
type int not null,
info varchar(255),
amount decimal(12, 2) not null default 0,
payment decimal(12, 2) not null default 0,
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
);
create index bill_user_id_index on bill (user_id);
create index bill_trade_id_index on bill (trade_id);
create index bill_resource_id_index on bill (resource_id);
create index bill_type_index on bill (type);
create index bill_deleted_at_index on bill (deleted_at);
-- bill表字段注释
comment on table bill is '账单表';
comment on column bill.id is '账单ID';
comment on column bill.trade_id is '订单ID';
comment on column bill.user_id is '用户ID';
comment on column bill.resource_id is '套餐ID';
comment on column bill.bill_no is '易读账单号';
comment on column bill.info is '产品可读信息';
comment on column bill.type is '账单类型0-充值1-消费2-退款';
comment on column bill.amount is '总金额';
comment on column bill.payment is '支付金额';
comment on column bill.created_at is '创建时间';
comment on column bill.updated_at is '更新时间';
comment on column bill.deleted_at is '删除时间';
-- refund
drop table if exists refund cascade;
create table refund (
@@ -816,4 +781,52 @@ comment on column refund.created_at is '创建时间';
comment on column refund.updated_at is '更新时间';
comment on column refund.deleted_at is '删除时间';
-- bill
drop table if exists bill cascade;
create table bill (
id serial primary key,
user_id int not null references "user" (id)
on update cascade
on delete cascade,
trade_id int references trade (id) --
on update cascade --
on delete set null,
resource_id int references resource (id) --
on update cascade --
on delete set null,
refund_id int references refund (id) --
on update cascade --
on delete set null,
bill_no varchar(255) not null unique,
info varchar(255),
type int not null,
status int not null,
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
);
create index bill_user_id_index on bill (user_id);
create index bill_trade_id_index on bill (trade_id);
create index bill_resource_id_index on bill (resource_id);
create index bill_refund_id_index on bill (refund_id);
create index bill_bill_no_index on bill (bill_no);
create index bill_type_index on bill (type);
create index bill_status_index on bill (status);
create index bill_deleted_at_index on bill (deleted_at);
-- bill表字段注释
comment on table bill is '账单表';
comment on column bill.id is '账单ID';
comment on column bill.user_id is '用户ID';
comment on column bill.trade_id is '订单ID';
comment on column bill.resource_id is '套餐ID';
comment on column bill.refund_id is '退款ID';
comment on column bill.bill_no is '易读账单号';
comment on column bill.info is '产品可读信息';
comment on column bill.type is '账单类型0-充值1-消费2-退款';
comment on column bill.status is '账单状态0-未完成1-已完成2-已作废';
comment on column bill.created_at is '创建时间';
comment on column bill.updated_at is '更新时间';
comment on column bill.deleted_at is '删除时间';
-- endregion