-- 5. 用户银行卡表 create table if not exists ml_user_bank_cards ( id uuid default gen_random_uuid() primary key, user_id uuid not null, bank_name varchar(100) not null, -- 银行名称 card_no_last4 varchar(4) not null, -- 卡号后4位 card_type varchar(20) default 'debit', -- 卡类型: debit(储蓄卡), credit(信用卡) holder_name varchar(100) not null, -- 持卡人姓名 phone varchar(20), -- 预留手机号 is_default boolean default false, created_at timestamptz default now() ); -- 6. 用户红包/现金券表 create table if not exists ml_user_red_packets ( id uuid default gen_random_uuid() primary key, user_id uuid not null, amount decimal(10,2) not null, -- 金额 name varchar(100) not null, -- 红包名称 status int default 0, -- 0: 未使用, 1: 已使用, 2: 已过期 expire_at timestamptz, -- 过期时间 used_at timestamptz, -- 使用时间 (转入余额的时间) created_at timestamptz default now() ); comment on table ml_user_bank_cards is '用户绑定银行卡'; comment on table ml_user_red_packets is '用户红包现金券'; -- 插入测试数据 DO $$ DECLARE target_user_id uuid := 'b653fded-7d5e-4950-aa0d-725595543e3c'; BEGIN -- 银行卡 INSERT INTO ml_user_bank_cards (user_id, bank_name, card_no_last4, holder_name, is_default) VALUES (target_user_id, '招商银行', '8888', '测试用户', true), (target_user_id, '中国建设银行', '1234', '测试用户', false); -- 红包 INSERT INTO ml_user_red_packets (user_id, amount, name, status, expire_at) VALUES (target_user_id, 10.00, '新人专享红包', 0, now() + interval '7 days'), (target_user_id, 5.00, '每日签到红包', 0, now() + interval '1 days'), (target_user_id, 50.00, '过期大红包', 2, now() - interval '1 days'); END $$;