feat: add TenantLedger model and query generation

- Introduced TenantLedger model with fields for managing tenant transactions, including ID, TenantID, UserID, OrderID, transaction Type, Amount, and balance details.
- Implemented CRUD operations for TenantLedger with methods for Create, Update, Delete, and Reload.
- Generated query methods for TenantLedger to facilitate database interactions, including filtering, pagination, and aggregation functions.
- Established relationships with Order model for foreign key references.
This commit is contained in:
2025-12-18 13:12:26 +08:00
parent f93caefcb2
commit 1da84f2af3
42 changed files with 6468 additions and 265 deletions

View File

@@ -18,19 +18,19 @@ const TableNameContent = "contents"
// Content mapped from table <contents>
type Content struct {
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"`
Title string `gorm:"column:title;type:character varying(255);not null" json:"title"`
Description string `gorm:"column:description;type:text;not null" json:"description"`
Status consts.ContentStatus `gorm:"column:status;type:character varying(32);not null;default:draft" json:"status"`
Visibility consts.ContentVisibility `gorm:"column:visibility;type:character varying(32);not null;default:tenant_only" json:"visibility"`
PreviewSeconds int32 `gorm:"column:preview_seconds;type:integer;not null;default:60" json:"preview_seconds"`
PreviewDownloadable bool `gorm:"column:preview_downloadable;type:boolean;not null" json:"preview_downloadable"`
PublishedAt time.Time `gorm:"column:published_at;type:timestamp with time zone" json:"published_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
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_id" json:"tenant_id"` // 租户ID多租户隔离关键字段所有查询/写入必须限定 tenant_id
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID内容创建者/发布者;用于权限与审计(例如私有内容仅作者可见)" json:"user_id"` // 用户ID内容创建者/发布者;用于权限与审计(例如私有内容仅作者可见)
Title string `gorm:"column:title;type:character varying(255);not null;comment:标题:用于列表展示与搜索;建议限制长度(由业务校验)" json:"title"` // 标题:用于列表展示与搜索;建议限制长度(由业务校验)
Description string `gorm:"column:description;type:text;not null;comment:描述:用于详情页展示;可为空字符串" json:"description"` // 描述:用于详情页展示;可为空字符串
Status consts.ContentStatus `gorm:"column:status;type:character varying(32);not null;default:draft;comment:状态draft/reviewing/published/unpublished/blockedpublished 才对外展示" json:"status"` // 状态draft/reviewing/published/unpublished/blockedpublished 才对外展示
Visibility consts.ContentVisibility `gorm:"column:visibility;type:character varying(32);not null;default:tenant_only;comment:可见性public/tenant_only/private仅控制详情可见正片资源仍需按价格/权益校验" json:"visibility"` // 可见性public/tenant_only/private仅控制详情可见正片资源仍需按价格/权益校验
PreviewSeconds int32 `gorm:"column:preview_seconds;type:integer;not null;default:60;comment:试看秒数:默认 60只对 preview 资源生效;必须为正整数" json:"preview_seconds"` // 试看秒数:默认 60只对 preview 资源生效;必须为正整数
PreviewDownloadable bool `gorm:"column:preview_downloadable;type:boolean;not null;comment:试看是否允许下载:默认 false当前策略固定为不允许下载仅 streaming" json:"preview_downloadable"` // 试看是否允许下载:默认 false当前策略固定为不允许下载仅 streaming
PublishedAt time.Time `gorm:"column:published_at;type:timestamp with time zone;comment:发布时间:首次发布时写入;用于时间窗与排序" json:"published_at"` // 发布时间:首次发布时写入;用于时间窗与排序
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone;comment:软删除时间:非空表示已删除;对外接口需过滤" json:"deleted_at"` // 软删除时间:非空表示已删除;对外接口需过滤
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();编辑内容时写入
}
// Quick operations without importing query package