feat: implement new structure

This commit is contained in:
2025-12-29 09:30:49 +08:00
parent 503b15aab7
commit ad52371028
116 changed files with 17579 additions and 1213 deletions

View File

@@ -8,8 +8,6 @@ import (
"context"
"time"
"quyun/v2/pkg/consts"
"go.ipao.vip/gen"
)
@@ -17,24 +15,23 @@ const TableNameTenantLedger = "tenant_ledgers"
// TenantLedger mapped from table <tenant_ledgers>
type TenantLedger struct {
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID自增" json:"id"` // 主键ID自增
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID多租户隔离关键字段必须与 tenant_users.tenant_id 一致" json:"tenant_id"` // 租户ID多租户隔离关键字段必须与 tenant_users.tenant_id 一致
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID余额账户归属用户对应 tenant_users.user_id" json:"user_id"` // 用户ID余额账户归属用户对应 tenant_users.user_id
OrderID int64 `gorm:"column:order_id;type:bigint;comment:关联订单ID购买/退款类流水应关联 orders.id非订单类可为空" json:"order_id"` // 关联订单ID购买/退款类流水应关联 orders.id非订单类可为空
Type consts.TenantLedgerType `gorm:"column:type;type:character varying(32);not null;comment:流水类型debit_purchase/credit_refund/freeze/unfreeze/adjustment不同类型决定余额/冻结余额的变更方向" json:"type"` // 流水类型debit_purchase/credit_refund/freeze/unfreeze/adjustment不同类型决定余额/冻结余额的变更方向
Amount int64 `gorm:"column:amount;type:bigint;not null;comment:流水金额:分/最小货币单位;通常为正数,方向由 type 决定(由业务层约束)" json:"amount"` // 流水金额:分/最小货币单位;通常为正数,方向由 type 决定(由业务层约束)
BalanceBefore int64 `gorm:"column:balance_before;type:bigint;not null;comment:变更前可用余额:用于审计与对账回放" json:"balance_before"` // 变更前可用余额:用于审计与对账回放
BalanceAfter int64 `gorm:"column:balance_after;type:bigint;not null;comment:变更后可用余额:用于审计与对账回放" json:"balance_after"` // 变更后可用余额:用于审计与对账回放
FrozenBefore int64 `gorm:"column:frozen_before;type:bigint;not null;comment:变更前冻结余额:用于审计与对账回放" json:"frozen_before"` // 变更前冻结余额:用于审计与对账回放
FrozenAfter int64 `gorm:"column:frozen_after;type:bigint;not null;comment:变更后冻结余额:用于审计与对账回放" json:"frozen_after"` // 变更后冻结余额:用于审计与对账回放
IdempotencyKey string `gorm:"column:idempotency_key;type:character varying(128);not null;comment:幂等键:同一租户同一用户同一业务操作固定;用于防止重复落账(建议由业务层生成)" json:"idempotency_key"` // 幂等键:同一租户同一用户同一业务操作固定;用于防止重复落账(建议由业务层生成)
Remark string `gorm:"column:remark;type:character varying(255);not null;comment:备注:业务说明/后台操作原因等;用于审计" json:"remark"` // 备注:业务说明/后台操作原因等;用于审计
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now()" json:"created_at"` // 创建时间:默认 now()
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now()" json:"updated_at"` // 更新时间:默认 now()
OperatorUserID int64 `gorm:"column:operator_user_id;type:bigint;comment:操作者用户ID谁触发该流水admin/buyer/system用于审计与追责可为空历史数据或无法识别时" json:"operator_user_id"` // 操作者用户ID谁触发该流水admin/buyer/system用于审计与追责可为空历史数据或无法识别时
BizRefType string `gorm:"column:biz_ref_type;type:character varying(32);comment:业务引用类型order/refund/etc与 biz_ref_id 组成可选的结构化幂等/追溯键" json:"biz_ref_type"` // 业务引用类型order/refund/etc与 biz_ref_id 组成可选的结构化幂等/追溯键
BizRefID int64 `gorm:"column:biz_ref_id;type:bigint;comment:业务引用ID与 biz_ref_type 配合使用(例如 orders.id用于对账与审计" json:"biz_ref_id"` // 业务引用ID与 biz_ref_type 配合使用(例如 orders.id用于对账与审计
Order *Order `gorm:"foreignKey:OrderID;references:ID" json:"order,omitempty"`
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
OrderID int64 `gorm:"column:order_id;type:bigint" json:"order_id"`
Type string `gorm:"column:type;type:character varying(32);not null" json:"type"`
Amount int64 `gorm:"column:amount;type:bigint;not null" json:"amount"`
BalanceBefore int64 `gorm:"column:balance_before;type:bigint;not null" json:"balance_before"`
BalanceAfter int64 `gorm:"column:balance_after;type:bigint;not null" json:"balance_after"`
FrozenBefore int64 `gorm:"column:frozen_before;type:bigint;not null" json:"frozen_before"`
FrozenAfter int64 `gorm:"column:frozen_after;type:bigint;not null" json:"frozen_after"`
IdempotencyKey string `gorm:"column:idempotency_key;type:character varying(128);not null" json:"idempotency_key"`
Remark string `gorm:"column:remark;type:character varying(255);not null" json:"remark"`
OperatorUserID int64 `gorm:"column:operator_user_id;type:bigint" json:"operator_user_id"`
BizRefType string `gorm:"column:biz_ref_type;type:character varying(32)" json:"biz_ref_type"`
BizRefID int64 `gorm:"column:biz_ref_id;type:bigint" json:"biz_ref_id"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
}
// Quick operations without importing query package