- 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.
66 lines
4.1 KiB
Go
66 lines
4.1 KiB
Go
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||
|
||
package models
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
"quyun/v2/pkg/consts"
|
||
|
||
"go.ipao.vip/gen"
|
||
)
|
||
|
||
const TableNameContentAccess = "content_access"
|
||
|
||
// ContentAccess mapped from table <content_access>
|
||
type ContentAccess 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:多租户隔离;与内容、用户归属一致" json:"tenant_id"` // 租户ID:多租户隔离;与内容、用户归属一致
|
||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:权益所属用户;用于访问校验" json:"user_id"` // 用户ID:权益所属用户;用于访问校验
|
||
ContentID int64 `gorm:"column:content_id;type:bigint;not null;comment:内容ID:权益对应内容;唯一约束 (tenant_id, user_id, content_id)" json:"content_id"` // 内容ID:权益对应内容;唯一约束 (tenant_id, user_id, content_id)
|
||
OrderID int64 `gorm:"column:order_id;type:bigint;comment:订单ID:产生该权益的订单;可为空(例如后台补发/迁移)" json:"order_id"` // 订单ID:产生该权益的订单;可为空(例如后台补发/迁移)
|
||
Status consts.ContentAccessStatus `gorm:"column:status;type:character varying(16);not null;default:active;comment:权益状态:active/revoked/expired;revoked 表示立即失效(例如退款/违规)" json:"status"` // 权益状态:active/revoked/expired;revoked 表示立即失效(例如退款/违规)
|
||
RevokedAt time.Time `gorm:"column:revoked_at;type:timestamp with time zone;comment:撤销时间:当 status=revoked 时写入;用于审计与追责" json:"revoked_at"` // 撤销时间:当 status=revoked 时写入;用于审计与追责
|
||
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();更新 status 时写入" json:"updated_at"` // 更新时间:默认 now();更新 status 时写入
|
||
}
|
||
|
||
// Quick operations without importing query package
|
||
// Update applies changed fields to the database using the default DB.
|
||
func (m *ContentAccess) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||
return Q.ContentAccess.WithContext(ctx).Updates(m)
|
||
}
|
||
|
||
// Save upserts the model using the default DB.
|
||
func (m *ContentAccess) Save(ctx context.Context) error {
|
||
return Q.ContentAccess.WithContext(ctx).Save(m)
|
||
}
|
||
|
||
// Create inserts the model using the default DB.
|
||
func (m *ContentAccess) Create(ctx context.Context) error {
|
||
return Q.ContentAccess.WithContext(ctx).Create(m)
|
||
}
|
||
|
||
// Delete removes the row represented by the model using the default DB.
|
||
func (m *ContentAccess) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||
return Q.ContentAccess.WithContext(ctx).Delete(m)
|
||
}
|
||
|
||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||
func (m *ContentAccess) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||
return Q.ContentAccess.WithContext(ctx).Unscoped().Delete(m)
|
||
}
|
||
|
||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||
func (m *ContentAccess) Reload(ctx context.Context) error {
|
||
fresh, err := Q.ContentAccess.WithContext(ctx).GetByID(m.ID)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
*m = *fresh
|
||
return nil
|
||
}
|