Files
junhong_cmp_fiber/migrations/000117_create_tb_recharge_order.up.sql
huang b972a776d9
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m32s
重构充值订单模块:用 tb_recharge_order + tb_payment 替换 tb_asset_recharge_record
- 新增 RechargeOrder 和 Payment 模型及对应 Store
- 新增 ClientRechargeOrderHandler 提供充值订单列表/详情接口
- 修改 client_wallet.go 使用新表读写充值数据
- 修改 callback/payment.go 将 CRCH 订单路由到 rechargeOrderService
- 修改 client_order/service.go 的强充流程使用新表
- 修改 auto_purchase.go 从 tb_recharge_order 读取 linked_package_ids
- 修改 order/service.go 的 WalletPay 使用 tb_payment 记录
- 修改 wechat_config_store.go 从 tb_recharge_order 统计待支付充值数
- 移除 AssetRechargeStore 和 AssetRechargeRecord 的注册引用
- 修复文档生成器缺失 ClientRechargeOrder handler
- 状态枚举改为 0-based: Pending=0, Paid=1, Closed=2, Refunded=3
2026-04-15 11:00:32 +08:00

38 lines
2.3 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 创建充值订单表 tb_recharge_order
-- 承接原 tb_asset_recharge_record 的业务字段 + 增加与资产的直接关联
CREATE TABLE tb_recharge_order (
id BIGSERIAL PRIMARY KEY,
recharge_order_no VARCHAR(40) NOT NULL UNIQUE, -- 沿用 CRCH 前缀
user_id BIGINT NOT NULL, -- 发起用户(个人客户 ID
asset_wallet_id BIGINT NOT NULL,
resource_type VARCHAR(20) NOT NULL, -- iot_card | device
resource_id BIGINT NOT NULL,
iot_card_id BIGINT, -- 单卡充值时有值(用于 ListOrders 查询)
device_id BIGINT, -- 设备充值时有值
amount BIGINT NOT NULL, -- 充值金额(分)
status SMALLINT NOT NULL DEFAULT 1, -- 1待支付 2已支付 3已关闭 4已退款
paid_at TIMESTAMPTZ,
shop_id_tag BIGINT NOT NULL DEFAULT 0,
enterprise_id_tag BIGINT,
operator_type VARCHAR(30) NOT NULL, -- personal_customer | admin_user
generation INT NOT NULL DEFAULT 1,
-- 强充专有字段(普通充值为 NULL
linked_package_ids JSONB,
linked_order_type VARCHAR(20),
linked_carrier_type VARCHAR(20),
linked_carrier_id BIGINT,
auto_purchase_status VARCHAR(20), -- pending | success | failed
-- 累计充值(用于强充阈值判断)
accumulated_recharge_series BIGINT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMPTZ
);
-- 索引
CREATE INDEX idx_recharge_order_card ON tb_recharge_order(iot_card_id, generation) WHERE deleted_at IS NULL;
CREATE INDEX idx_recharge_order_device ON tb_recharge_order(device_id, generation) WHERE deleted_at IS NULL;
CREATE INDEX idx_recharge_order_user ON tb_recharge_order(user_id) WHERE deleted_at IS NULL;
CREATE INDEX idx_recharge_order_no ON tb_recharge_order(recharge_order_no) WHERE deleted_at IS NULL;
CREATE INDEX idx_recharge_order_status ON tb_recharge_order(status) WHERE deleted_at IS NULL;