model

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusDisabled  = 0
	StatusEnabled   = 1
	StatusSuspended = 2
)

状态常量

View Source
const (
	GameStatusDev         = "dev"
	GameStatusTest        = "test"
	GameStatusRunning     = "running"
	GameStatusOnline      = "online"
	GameStatusOffline     = "offline"
	GameStatusMaintenance = "maintenance"
)

游戏状态常量

View Source
const (
	PlayerStatusBanned    = 0
	PlayerStatusActive    = 1
	PlayerStatusSuspended = 2
)

玩家状态常量

Variables

View Source
var (
	ErrNotFound            = gorm.ErrRecordNotFound
	ErrDuplicateKey        = errors.New("duplicate key error")
	ErrInvalidData         = errors.New("invalid data")
	ErrInvalidPassword     = errors.New("invalid password")
	ErrPermissionDenied    = errors.New("permission denied")
	ErrInsufficientBalance = errors.New("insufficient balance")
)

常用错误定义

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) error

AutoMigrate runs gorm auto migration for all server-owned tables.

func CertificateStatus

func CertificateStatus(expiry time.Time) string

CertificateStatus calculates status by expiry.

func EncodeData

func EncodeData(data interface{}) (datatypes.JSON, error)

EncodeData converts arbitrary payload into datatypes.JSON.

func IsValidGameStatus

func IsValidGameStatus(status string) bool

IsValidGameStatus 检查游戏状态值是否有效

func IsValidStatus

func IsValidStatus(status int) bool

IsValidStatus 检查状态值是否有效

func NowUTC

func NowUTC() time.Time

NowUTC 获取当前 UTC 时间

Types

type Admin

type Admin struct {
	gorm.Model
	Username     string     `gorm:"uniqueIndex;size:64;not null"`
	Nickname     string     `gorm:"size:128;index"`
	Email        string     `gorm:"size:256;index"`
	Phone        string     `gorm:"size:32;index"`
	Avatar       string     `gorm:"size:512"`
	PasswordHash string     `gorm:"size:255"`
	Status       int        `gorm:"default:1;index"` // 1:active 0:disabled
	OTPSecret    string     `gorm:"size:64"`
	LastLoginAt  *time.Time `gorm:"index"`
	CreatedBy    uint       `gorm:"index"`
	UpdatedBy    uint
}

Admin represents administrator accounts.

func (Admin) TableName

func (Admin) TableName() string

TableName implements gorm's tabler interface.

type AdminGameEnvScope

type AdminGameEnvScope struct {
	gorm.Model
	AdminID uint   `gorm:"index:idx_admin_game_env_scopes_admin_id;not null"`
	GameID  uint   `gorm:"index:idx_admin_game_env_scopes_game_id;not null"`
	Env     string `gorm:"index:idx_admin_game_env_scopes_env;size:64;not null"`
}

AdminGameEnvScope limits admins to particular game environments.

func (AdminGameEnvScope) TableName

func (AdminGameEnvScope) TableName() string

TableName implements gorm's tabler interface.

type AdminGameScope

type AdminGameScope struct {
	gorm.Model
	AdminID uint `gorm:"index:idx_admin_game_scopes_admin_id;not null"`
	GameID  uint `gorm:"index:idx_admin_game_scopes_game_id;not null"`
}

AdminGameScope limits admins to particular games.

func (AdminGameScope) TableName

func (AdminGameScope) TableName() string

TableName implements gorm's tabler interface.

type AdminModel

type AdminModel struct {
	// contains filtered or unexported fields
}

AdminModel exposes CRUD helpers backed by gorm.

func NewAdminModel

func NewAdminModel(db *gorm.DB) *AdminModel

NewAdminModel creates a new AdminModel.

func (*AdminModel) AssignRole

func (m *AdminModel) AssignRole(ctx context.Context, adminID, roleID uint) error

AssignRole attaches a role to an admin.

func (*AdminModel) Create

func (m *AdminModel) Create(ctx context.Context, admin *Admin, password string) error

Create inserts an admin with the given password (hashed internally).

func (*AdminModel) Delete

func (m *AdminModel) Delete(ctx context.Context, id uint) error

Delete deletes an admin by ID.

func (*AdminModel) FindByUsername

func (m *AdminModel) FindByUsername(ctx context.Context, username string) (*Admin, error)

FindByUsername fetches an admin by username.

func (*AdminModel) FindOne

func (m *AdminModel) FindOne(ctx context.Context, id uint) (*Admin, error)

FindOne fetches an admin by ID.

func (*AdminModel) GetAdminRoles

func (m *AdminModel) GetAdminRoles(ctx context.Context, adminID uint) ([]Role, error)

GetAdminRoles returns roles for an admin.

func (*AdminModel) List

func (m *AdminModel) List(ctx context.Context, opts ListAdminsOptions) ([]Admin, int64, error)

List returns paginated admins plus total count.

func (*AdminModel) RemoveGameEnvScope

func (m *AdminModel) RemoveGameEnvScope(ctx context.Context, adminID, gameID uint, env string) error

RemoveGameEnvScope removes a game env scope entry.

func (*AdminModel) RemoveGameScope

func (m *AdminModel) RemoveGameScope(ctx context.Context, adminID, gameID uint) error

RemoveGameScope removes a game scope entry.

func (*AdminModel) RemoveRole

func (m *AdminModel) RemoveRole(ctx context.Context, adminID, roleID uint) error

RemoveRole detaches a role from an admin.

func (*AdminModel) SetGameEnvScope

func (m *AdminModel) SetGameEnvScope(ctx context.Context, adminID, gameID uint, env string) error

SetGameEnvScope assigns a game env scope to an admin.

func (*AdminModel) SetGameScope

func (m *AdminModel) SetGameScope(ctx context.Context, adminID, gameID uint) error

SetGameScope assigns a game scope to an admin.

func (*AdminModel) Update

func (m *AdminModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update updates the admin with arbitrary fields.

func (*AdminModel) UpdatePassword

func (m *AdminModel) UpdatePassword(ctx context.Context, id uint, newPassword string) error

UpdatePassword updates an admin password.

func (*AdminModel) ValidatePassword

func (m *AdminModel) ValidatePassword(ctx context.Context, username, password string) (*Admin, error)

ValidatePassword validates credentials and updates last login timestamp.

type AdminRole

type AdminRole struct {
	gorm.Model
	AdminID uint `gorm:"index:idx_admin_roles_admin_id;not null"`
	RoleID  uint `gorm:"index:idx_admin_roles_role_id;not null"`
}

AdminRole links admins and roles.

func (AdminRole) TableName

func (AdminRole) TableName() string

TableName implements gorm's tabler interface.

type Alert

type Alert struct {
	gorm.Model
	AlertID   string            `gorm:"size:64;uniqueIndex"`
	Type      string            `gorm:"size:64"`
	Level     string            `gorm:"size:32"`
	Message   string            `gorm:"type:text"`
	Source    string            `gorm:"size:64"`
	Status    string            `gorm:"size:32;index"`
	Details   datatypes.JSONMap `gorm:"type:json"`
	Metadata  datatypes.JSONMap `gorm:"type:json"`
	CreatedBy string            `gorm:"size:64"`
}

Alert captures runtime system alerts for ops center.

func (Alert) TableName

func (Alert) TableName() string

type AlertModel

type AlertModel struct {
	// contains filtered or unexported fields
}

AlertModel provides CRUD operations for alerts and silences.

func NewAlertModel

func NewAlertModel(db *gorm.DB) *AlertModel

NewAlertModel creates a new alert model helper.

func (*AlertModel) BootstrapAlerts

func (m *AlertModel) BootstrapAlerts(ctx context.Context, alerts []Alert) error

BootstrapAlerts ensures seed data for testing/dev.

func (*AlertModel) Create

func (m *AlertModel) Create(ctx context.Context, alert *Alert) error

Create inserts a new alert.

func (*AlertModel) CreateSilence

func (m *AlertModel) CreateSilence(ctx context.Context, silence *AlertSilence) error

CreateSilence records a new silence window.

func (*AlertModel) DeleteSilence

func (m *AlertModel) DeleteSilence(ctx context.Context, silenceID uint) error

DeleteSilence removes silence entry by ID.

func (*AlertModel) FindByAlertID

func (m *AlertModel) FindByAlertID(ctx context.Context, alertID string) (*Alert, error)

FindByAlertID returns alert by external alert id.

func (*AlertModel) FindByIDs

func (m *AlertModel) FindByIDs(ctx context.Context, ids []uint) (map[uint]*Alert, error)

FindByIDs returns alerts indexed by their primary key.

func (*AlertModel) List

func (m *AlertModel) List(ctx context.Context, opts ListAlertsOptions) ([]Alert, int64, error)

List returns paginated alerts.

func (*AlertModel) ListSilences

func (m *AlertModel) ListSilences(ctx context.Context, opts ListSilencesOptions) ([]AlertSilence, error)

ListSilences returns alert silences.

func (*AlertModel) PruneExpiredSilences

func (m *AlertModel) PruneExpiredSilences(ctx context.Context) error

PruneExpiredSilences removes expired silences.

func (*AlertModel) UpdateStatus

func (m *AlertModel) UpdateStatus(ctx context.Context, id uint, status string) error

UpdateStatus updates alert status.

type AlertSilence

type AlertSilence struct {
	gorm.Model
	AlertID        uint      `gorm:"index"`
	Reason         string    `gorm:"size:255"`
	DurationMinute int       `gorm:"default:0"`
	ExpiresAt      time.Time `gorm:"index"`
	CreatedBy      string    `gorm:"size:64"`
}

AlertSilence stores silence windows for alerts.

func (AlertSilence) TableName

func (AlertSilence) TableName() string

type Backup

type Backup struct {
	gorm.Model
	BackupID string `gorm:"size:64;uniqueIndex"`
	Name     string `gorm:"size:128"`
	Size     int64
	Type     string `gorm:"size:32"`
	Status   string `gorm:"size:32"`
	Location string `gorm:"size:255"`
	Checksum string `gorm:"size:64"`
}

Backup stores backup metadata.

func (Backup) TableName

func (Backup) TableName() string

type BackupModel

type BackupModel struct {
	// contains filtered or unexported fields
}

BackupModel provides CRUD helpers for backups.

func NewBackupModel

func NewBackupModel(db *gorm.DB) *BackupModel

NewBackupModel creates a new helper.

func (*BackupModel) Create

func (m *BackupModel) Create(ctx context.Context, backup *Backup) error

Create inserts a new backup entry.

func (*BackupModel) Delete

func (m *BackupModel) Delete(ctx context.Context, id uint) error

Delete removes a backup.

func (*BackupModel) DeleteByBackupID

func (m *BackupModel) DeleteByBackupID(ctx context.Context, backupID string) error

DeleteByBackupID removes a backup using backup_id.

func (*BackupModel) FindByBackupID

func (m *BackupModel) FindByBackupID(ctx context.Context, backupID string) (*Backup, error)

FindByBackupID fetches a backup via its stable backup_id.

func (*BackupModel) FindByID

func (m *BackupModel) FindByID(ctx context.Context, id uint) (*Backup, error)

FindByID fetches a backup.

func (*BackupModel) List

func (m *BackupModel) List(ctx context.Context, opts ListBackupsOptions) ([]Backup, int64, error)

List returns paginated backups.

type BehaviorDailyStat

type BehaviorDailyStat struct {
	Day         time.Time
	ActiveUsers int64
	Events      int64
}

BehaviorDailyStat describes per-day activity metrics.

type BehaviorEvent

type BehaviorEvent struct {
	gorm.Model
	GameID     string            `gorm:"size:64;index"`
	Env        string            `gorm:"size:32;index"`
	EventType  string            `gorm:"size:64;index"`
	UserID     string            `gorm:"size:64;index"`
	Data       datatypes.JSONMap `gorm:"type:json"`
	OccurredAt time.Time         `gorm:"index"`
}

BehaviorEvent stores raw behavior events for analytics.

type BehaviorEventOptions

type BehaviorEventOptions struct {
	PaginationOptions
	GameID    string
	Env       string
	EventType string
	StartTime time.Time
	EndTime   time.Time
}

BehaviorEventOptions controls event queries.

type BehaviorModel

type BehaviorModel struct {
	// contains filtered or unexported fields
}

BehaviorModel handles behavior analytics persistence.

func NewBehaviorModel

func NewBehaviorModel(db *gorm.DB) *BehaviorModel

NewBehaviorModel creates a new behavior model helper.

func (*BehaviorModel) CountDistinctUsers

func (m *BehaviorModel) CountDistinctUsers(ctx context.Context, gameID, env string, start, end time.Time) (int64, error)

CountDistinctUsers returns the number of unique users within the provided window.

func (*BehaviorModel) CountEvents

func (m *BehaviorModel) CountEvents(ctx context.Context, gameID, env string, start, end time.Time) (int64, error)

CountEvents returns total events within the provided window.

func (*BehaviorModel) DailyActivity

func (m *BehaviorModel) DailyActivity(ctx context.Context, gameID, env string, start, end time.Time) ([]BehaviorDailyStat, error)

DailyActivity returns per-day active users and event counts between the provided range.

func (*BehaviorModel) EventTypeCounts

func (m *BehaviorModel) EventTypeCounts(ctx context.Context, gameID, env string, start, end time.Time, limit int) ([]EventTypeCount, error)

EventTypeCounts aggregates events by type, ordered by volume.

func (*BehaviorModel) ListEvents

ListEvents returns paginated behavior events.

func (*BehaviorModel) ListFeatureAdoptions

func (m *BehaviorModel) ListFeatureAdoptions(ctx context.Context, gameID, env string) ([]FeatureAdoption, error)

ListFeatureAdoptions fetches adoption snapshots.

func (*BehaviorModel) RecordEvent

func (m *BehaviorModel) RecordEvent(ctx context.Context, event *BehaviorEvent) error

RecordEvent stores a new behavior event.

func (*BehaviorModel) UpsertFeatureAdoption

func (m *BehaviorModel) UpsertFeatureAdoption(ctx context.Context, adoption *FeatureAdoption) error

UpsertFeatureAdoption stores aggregated adoption data.

type Certificate

type Certificate struct {
	gorm.Model
	Domain         string     `gorm:"size:255;uniqueIndex"`
	CertificatePEM string     `gorm:"type:text"`
	PrivateKeyPEM  string     `gorm:"type:text"`
	Issuer         string     `gorm:"size:255;index"`
	ExpiresAt      time.Time  `gorm:"index"`
	Status         string     `gorm:"size:32;index"` // active, expiring, expired
	LastCheckedAt  *time.Time `gorm:"index"`
	ErrorMessage   string     `gorm:"type:text"`
}

Certificate stores TLS certificate metadata.

func (Certificate) TableName

func (Certificate) TableName() string

type CertificateAlert

type CertificateAlert struct {
	gorm.Model
	Domain          string     `gorm:"size:255;index"`
	ThresholdDays   int        `gorm:"default:30"`
	Active          bool       `gorm:"default:true;index"`
	LastTriggeredAt *time.Time `gorm:"index"`
}

CertificateAlert stores alert thresholds for certificates.

func (CertificateAlert) TableName

func (CertificateAlert) TableName() string

type CertificateModel

type CertificateModel struct {
	// contains filtered or unexported fields
}

CertificateModel manages certificate data.

func NewCertificateModel

func NewCertificateModel(db *gorm.DB) *CertificateModel

NewCertificateModel returns helper.

func (*CertificateModel) AddAlert

func (m *CertificateModel) AddAlert(ctx context.Context, alert *CertificateAlert) error

AddAlert creates alert.

func (*CertificateModel) Create

func (m *CertificateModel) Create(ctx context.Context, cert *Certificate) error

Create stores certificate.

func (*CertificateModel) Delete

func (m *CertificateModel) Delete(ctx context.Context, id uint) error

Delete removes certificate.

func (*CertificateModel) ExpiringWithin

func (m *CertificateModel) ExpiringWithin(ctx context.Context, d time.Duration) ([]Certificate, error)

ExpiringWithin lists certificates expiring within duration.

func (*CertificateModel) FindByDomain

func (m *CertificateModel) FindByDomain(ctx context.Context, domain string) (*Certificate, error)

FindByDomain fetches by domain.

func (*CertificateModel) FindOne

func (m *CertificateModel) FindOne(ctx context.Context, id uint) (*Certificate, error)

FindOne fetches certificate by ID.

func (*CertificateModel) List

List returns certificates with pagination.

func (*CertificateModel) ListAlerts

func (m *CertificateModel) ListAlerts(ctx context.Context, page, size int) ([]CertificateAlert, int64, error)

ListAlerts returns alerts with pagination.

func (*CertificateModel) ListAll

func (m *CertificateModel) ListAll(ctx context.Context) ([]Certificate, error)

ListAll returns all certificates.

func (*CertificateModel) Stats

func (m *CertificateModel) Stats(ctx context.Context) (map[string]int64, error)

Stats returns status counts.

func (*CertificateModel) Update

func (m *CertificateModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update updates fields by ID.

type ConfigListOptions

type ConfigListOptions struct {
	GameID string
	Env    string
	Format string
	IDLike string
}

type ConfigVersion

type ConfigVersion struct {
	gorm.Model
	Key       string `gorm:"size:128;index:idx_config_key_version,priority:1"`
	Version   int    `gorm:"index:idx_config_key_version,priority:2"`
	Value     string `gorm:"type:text"`
	Format    string `gorm:"size:16"`
	GameID    string `gorm:"size:64"`
	Env       string `gorm:"size:64"`
	Message   string `gorm:"size:255"`
	CreatedBy string `gorm:"size:64"`
}

ConfigVersion stores versioned configuration values for arbitrary keys.

func (ConfigVersion) TableName

func (ConfigVersion) TableName() string

type ConfigVersionModel

type ConfigVersionModel struct {
	// contains filtered or unexported fields
}

ConfigVersionModel provides helpers for managing configuration history.

func NewConfigVersionModel

func NewConfigVersionModel(db *gorm.DB) *ConfigVersionModel

func (*ConfigVersionModel) Create

func (m *ConfigVersionModel) Create(ctx context.Context, key, value, createdBy string) (*ConfigVersion, error)

Create inserts a new config version, automatically incrementing the version number.

func (*ConfigVersionModel) CreateWithMeta

func (m *ConfigVersionModel) CreateWithMeta(ctx context.Context, payload ConfigVersionPayload, createdBy string) (*ConfigVersion, error)

CreateWithMeta inserts a new config version with metadata and optimistic locking support.

func (*ConfigVersionModel) Find

func (m *ConfigVersionModel) Find(ctx context.Context, key string, version int) (*ConfigVersion, error)

Find returns the requested key/version pair.

func (*ConfigVersionModel) FindLatest

func (m *ConfigVersionModel) FindLatest(ctx context.Context, key string) (*ConfigVersion, error)

FindLatest returns the newest version for the given key.

func (*ConfigVersionModel) List

List returns all versions for the given key ordered from newest to oldest.

func (*ConfigVersionModel) ListLatest

ListLatest fetches the latest version per key with optional filters.

type ConfigVersionPayload

type ConfigVersionPayload struct {
	Key         string
	Content     string
	Format      string
	GameID      string
	Env         string
	Message     string
	BaseVersion int
}

type DailyNewPlayerStat

type DailyNewPlayerStat struct {
	Day   time.Time
	Count int64
}

DailyNewPlayerStat captures per-day signup counts.

type DailyRevenueStat

type DailyRevenueStat struct {
	Day          time.Time
	Revenue      float64
	Transactions int64
	Payers       int64
}

DailyRevenueStat tracks revenue per day.

type Descriptor

type Descriptor struct {
	gorm.Model
	DescriptorID string            `gorm:"size:64;uniqueIndex"`
	Name         string            `gorm:"size:128"`
	Description  string            `gorm:"type:text"`
	Category     string            `gorm:"size:64"`
	Schema       datatypes.JSONMap `gorm:"type:json"`
}

Descriptor represents reusable descriptors independent of a function.

func (Descriptor) TableName

func (Descriptor) TableName() string

type Entity

type Entity struct {
	gorm.Model
	Type       string         `gorm:"size:64;index;not null"` // 实体类型: player, item, quest 等
	Data       datatypes.JSON `gorm:"type:json"`              // JSON 数据
	ProviderID string         `gorm:"size:128;index"`         // 提供者 ID
	Status     int            `gorm:"default:1"`              // 0:禁用 1:启用
}

Entity 实体结构体,用于动态内容管理

func (*Entity) GetData

func (e *Entity) GetData(dest interface{}) error

GetData 解析 JSON 数据到指定结构

func (*Entity) SetData

func (e *Entity) SetData(data interface{}) error

SetData 设置 JSON 数据

func (Entity) TableName

func (Entity) TableName() string

TableName 实现 GORM 的表名接口

type EntityModel

type EntityModel struct {
	// contains filtered or unexported fields
}

EntityModel 提供实体数据访问方法

func NewEntityModel

func NewEntityModel(db *gorm.DB) *EntityModel

NewEntityModel 创建实体模型实例

func (*EntityModel) Create

func (m *EntityModel) Create(ctx context.Context, entity *Entity) error

Create 插入新实体

func (*EntityModel) Delete

func (m *EntityModel) Delete(ctx context.Context, id uint) error

Delete 删除实体

func (*EntityModel) FindOne

func (m *EntityModel) FindOne(ctx context.Context, id uint) (*Entity, error)

FindOne 根据 ID 获取实体

func (*EntityModel) List

func (m *EntityModel) List(ctx context.Context, opts ListEntitiesOptions) ([]Entity, int64, error)

List 分页获取实体列表

func (*EntityModel) Update

func (m *EntityModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update 更新实体

func (*EntityModel) ValidateEntityData

func (m *EntityModel) ValidateEntityData(entityType string, data interface{}) error

ValidateEntityData 验证实体数据格式

type EventTypeCount

type EventTypeCount struct {
	EventType string
	Total     int64
}

EventTypeCount represents aggregated counts per event type.

type FAQ

type FAQ struct {
	gorm.Model
	Question string         `gorm:"type:text"`
	Answer   string         `gorm:"type:text"`
	Category string         `gorm:"size:64;index"`
	Tags     datatypes.JSON `gorm:"type:json"`
	Visible  bool           `gorm:"default:true"`
	Sort     int            `gorm:"default:0"`
	Views    int            `gorm:"default:0"`
}

FAQ represents a knowledge base entry.

func (FAQ) TableName

func (FAQ) TableName() string

type FAQCategory

type FAQCategory struct {
	gorm.Model
	Name        string `gorm:"size:64;uniqueIndex"`
	Description string `gorm:"size:255"`
	Visible     bool   `gorm:"default:true"`
	Sort        int    `gorm:"default:0"`
}

FAQCategory stores FAQ category metadata.

func (FAQCategory) TableName

func (FAQCategory) TableName() string

type FAQCategoryStat

type FAQCategoryStat struct {
	Name  string
	Count int
}

ListCategories fetches FAQ categories.

type FAQModel

type FAQModel struct {
	// contains filtered or unexported fields
}

FAQModel manages FAQ data.

func NewFAQModel

func NewFAQModel(db *gorm.DB) *FAQModel

NewFAQModel creates a helper.

func (*FAQModel) Create

func (m *FAQModel) Create(ctx context.Context, faq *FAQ) error

Create inserts a new FAQ.

func (*FAQModel) Delete

func (m *FAQModel) Delete(ctx context.Context, id uint) error

Delete removes a FAQ.

func (*FAQModel) FindOne

func (m *FAQModel) FindOne(ctx context.Context, id uint) (*FAQ, error)

FindOne loads a FAQ.

func (*FAQModel) List

func (m *FAQModel) List(ctx context.Context, opts ListFAQOptions) ([]FAQ, int64, error)

List returns paginated FAQs.

func (*FAQModel) ListCategories

func (m *FAQModel) ListCategories(ctx context.Context) ([]FAQCategoryStat, error)

func (*FAQModel) Update

func (m *FAQModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update applies updates to FAQ.

func (*FAQModel) UpsertCategory

func (m *FAQModel) UpsertCategory(ctx context.Context, category *FAQCategory) error

UpsertCategory stores category metadata.

type FeatureAdoption

type FeatureAdoption struct {
	gorm.Model
	GameID       string  `gorm:"size:64;index"`
	Env          string  `gorm:"size:32;index"`
	Feature      string  `gorm:"size:64;index:idx_feature_unique,unique"`
	Users        int     `gorm:"default:0"`
	AdoptionRate float64 `gorm:"default:0"`
	Frequency    float64 `gorm:"default:0"`
	WindowStart  time.Time
	WindowEnd    time.Time
}

FeatureAdoption stores feature adoption metrics snapshots.

func (FeatureAdoption) TableName

func (FeatureAdoption) TableName() string

type Feedback

type Feedback struct {
	gorm.Model
	PlayerID string `gorm:"size:64;index"`
	Contact  string `gorm:"size:128"`
	Content  string `gorm:"type:text"`
	Category string `gorm:"size:64;index"`
	Priority string `gorm:"size:16;index"`
	Status   string `gorm:"size:16;index"`
	Rating   int    `gorm:"default:0;index"`
	Reply    string `gorm:"type:text"`
	Attach   string `gorm:"type:text"`
	GameID   string `gorm:"size:64;index:idx_feedback_game_env,priority:1"`
	Env      string `gorm:"size:64;index:idx_feedback_game_env,priority:2"`
}

Feedback represents player feedback submission.

func (Feedback) TableName

func (Feedback) TableName() string

type FeedbackModel

type FeedbackModel struct {
	// contains filtered or unexported fields
}

FeedbackModel manages feedback entries.

func NewFeedbackModel

func NewFeedbackModel(db *gorm.DB) *FeedbackModel

NewFeedbackModel creates helper.

func (*FeedbackModel) Create

func (m *FeedbackModel) Create(ctx context.Context, feedback *Feedback) error

Create inserts feedback entry.

func (*FeedbackModel) Delete

func (m *FeedbackModel) Delete(ctx context.Context, id uint) error

Delete removes feedback entry.

func (*FeedbackModel) FindByID

func (m *FeedbackModel) FindByID(ctx context.Context, id uint) (*Feedback, error)

FindByID returns a single feedback record.

func (*FeedbackModel) List

List fetches paginated feedback entries.

func (*FeedbackModel) Stats

Stats returns aggregate metrics for feedback entries.

func (*FeedbackModel) Update

func (m *FeedbackModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update changes feedback fields.

type FeedbackStatsOptions

type FeedbackStatsOptions struct {
	GameID string
	Days   int
}

FeedbackStatsOptions configures stats calculations.

type FeedbackStatsResult

type FeedbackStatsResult struct {
	Total      int64
	ByCategory map[string]int64
	ByStatus   map[string]int64
	AvgRating  float64
	Responded  int64
}

FeedbackStatsResult aggregates statistics for feedback.

type Function

type Function struct {
	gorm.Model
	FunctionID  string            `gorm:"size:64;uniqueIndex"`
	Name        string            `gorm:"size:128"`
	Description string            `gorm:"type:text"`
	Category    string            `gorm:"size:64;index"`
	GameID      string            `gorm:"size:64;index"`
	Status      int               `gorm:"index"`
	Version     string            `gorm:"size:32"`
	Instances   int               `gorm:"default:0"`
	Runtime     string            `gorm:"size:64"`
	Entry       string            `gorm:"size:128"`
	Schema      datatypes.JSONMap `gorm:"type:json"`
	Metadata    datatypes.JSONMap `gorm:"type:json"`
}

Function represents a registered callable unit.

func (Function) TableName

func (Function) TableName() string

type FunctionDescriptor

type FunctionDescriptor struct {
	gorm.Model
	FunctionID string            `gorm:"size:64;index"`
	Version    string            `gorm:"size:32"`
	Input      datatypes.JSONMap `gorm:"type:json"`
	Output     datatypes.JSONMap `gorm:"type:json"`
	Schema     datatypes.JSONMap `gorm:"type:json"`
}

FunctionDescriptor stores detailed descriptor versions.

func (FunctionDescriptor) TableName

func (FunctionDescriptor) TableName() string

type FunctionInstance

type FunctionInstance struct {
	gorm.Model
	FunctionID string            `gorm:"size:64;index"`
	AgentID    string            `gorm:"size:64;index"`
	AgentName  string            `gorm:"size:128"`
	Status     string            `gorm:"size:32"`
	UpdatedAt  time.Time         `gorm:"autoUpdateTime"`
	Metadata   datatypes.JSONMap `gorm:"type:json"`
}

FunctionInstance tracks runtime deployments.

func (FunctionInstance) TableName

func (FunctionInstance) TableName() string

type FunctionModel

type FunctionModel struct {
	// contains filtered or unexported fields
}

FunctionModel wraps data access for functions and related tables.

func NewFunctionModel

func NewFunctionModel(db *gorm.DB) *FunctionModel

NewFunctionModel creates the helper.

func (*FunctionModel) BatchCopyFunctions

func (m *FunctionModel) BatchCopyFunctions(ctx context.Context, functionIDs []string) (int, []string, []string, error)

BatchCopyFunctions copies multiple functions

func (*FunctionModel) BatchDeleteFunctions

func (m *FunctionModel) BatchDeleteFunctions(ctx context.Context, functionIDs []string) (int, []string, error)

BatchDeleteFunctions deletes multiple functions

func (*FunctionModel) BatchUpdateStatus

func (m *FunctionModel) BatchUpdateStatus(ctx context.Context, functionIDs []string, enabled bool) (int, []string, error)

BatchUpdateStatus updates status for multiple functions

func (*FunctionModel) CopyFunction

func (m *FunctionModel) CopyFunction(ctx context.Context, functionID string) (string, error)

CopyFunction creates a copy of a function with a new ID

func (*FunctionModel) Create

func (m *FunctionModel) Create(ctx context.Context, fn *Function) error

Create inserts a new function record.

func (*FunctionModel) Delete

func (m *FunctionModel) Delete(ctx context.Context, id uint) error

Delete removes a function.

func (*FunctionModel) DeleteFunction

func (m *FunctionModel) DeleteFunction(ctx context.Context, functionID string) error

DeleteFunction deletes a function by function_id

func (*FunctionModel) DeletePending

func (m *FunctionModel) DeletePending(ctx context.Context, functionID string) error

DeletePending removes a pending function.

func (*FunctionModel) FindByFunctionID

func (m *FunctionModel) FindByFunctionID(ctx context.Context, functionID string) (*Function, error)

FindByFunctionID fetches by external function ID.

func (*FunctionModel) FindByID

func (m *FunctionModel) FindByID(ctx context.Context, id uint) (*Function, error)

FindByID fetches a function.

func (*FunctionModel) List

List returns paginated functions.

func (*FunctionModel) ListDescriptorTemplates

func (m *FunctionModel) ListDescriptorTemplates(ctx context.Context, category string) ([]Descriptor, error)

ListDescriptorTemplates returns reusable descriptors filtered by category.

func (*FunctionModel) ListDescriptors

func (m *FunctionModel) ListDescriptors(ctx context.Context, functionID string) ([]FunctionDescriptor, error)

ListDescriptors fetches descriptors for a function.

func (*FunctionModel) ListInstances

func (m *FunctionModel) ListInstances(ctx context.Context, functionID string) ([]FunctionInstance, error)

ListInstances returns function instances.

func (*FunctionModel) ListPending

func (m *FunctionModel) ListPending(ctx context.Context) ([]PendingFunction, error)

ListPending returns pending submissions.

func (*FunctionModel) ListPermissions

func (m *FunctionModel) ListPermissions(ctx context.Context, functionID string) ([]FunctionPermission, error)

ListPermissions returns function permissions.

func (*FunctionModel) RegisterInstance

func (m *FunctionModel) RegisterInstance(ctx context.Context, instance *FunctionInstance) error

RegisterInstance upserts instance heartbeat data.

func (*FunctionModel) ReplacePermissions

func (m *FunctionModel) ReplacePermissions(ctx context.Context, functionID string, perms []FunctionPermission) error

ReplacePermissions fully replaces permissions for a function.

func (*FunctionModel) SavePendingFunction

func (m *FunctionModel) SavePendingFunction(ctx context.Context, pending *PendingFunction) error

SavePendingFunction upserts pending change set.

func (*FunctionModel) Update

func (m *FunctionModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update modifies function fields.

func (*FunctionModel) UpsertDescriptor

func (m *FunctionModel) UpsertDescriptor(ctx context.Context, desc *FunctionDescriptor) error

UpsertDescriptor stores descriptor metadata.

type FunctionPermission

type FunctionPermission struct {
	gorm.Model
	FunctionID string         `gorm:"size:64;index"`
	GameID     string         `gorm:"size:64;index"`
	Env        string         `gorm:"size:64;index"`
	Resource   string         `gorm:"size:64"`
	Actions    datatypes.JSON `gorm:"type:json"`
	Roles      datatypes.JSON `gorm:"type:json"`
}

FunctionPermission stores per-function permission mapping.

func (FunctionPermission) TableName

func (FunctionPermission) TableName() string

type Game

type Game struct {
	gorm.Model
	Name        string         `gorm:"size:128;not null;index"`
	Icon        string         `gorm:"size:255"`
	Description string         `gorm:"type:text"`
	Enabled     bool           `gorm:"default:true;index"`
	AliasName   string         `gorm:"size:64;uniqueIndex"`
	Homepage    string         `gorm:"size:255"`
	Status      string         `gorm:"size:32;default:'dev';index"` // dev, test, running, online, offline, maintenance
	GameType    string         `gorm:"size:64;index"`
	GenreCode   string         `gorm:"size:64;index"`
	Config      string         `gorm:"type:text"` // 游戏配置 JSON
	Color       string         `gorm:"size:32"`
	Envs        datatypes.JSON `gorm:"type:json"` // 环境列表 JSON
}

Game 游戏结构体

func (*Game) GetConfig

func (g *Game) GetConfig(dest interface{}) error

GetConfig 获取游戏配置

func (*Game) GetEnvs

func (g *Game) GetEnvs() ([]GameEnv, error)

GetEnvs 获取游戏环境列表

func (*Game) SetConfig

func (g *Game) SetConfig(config interface{}) error

SetConfig 设置游戏配置

func (*Game) SetEnvs

func (g *Game) SetEnvs(envs []GameEnv) error

SetEnvs 设置游戏环境列表

func (Game) TableName

func (Game) TableName() string

TableName 实现 GORM 的表名接口

type GameEnv

type GameEnv struct {
	Env         string `json:"env"`
	Description string `json:"description,omitempty"`
	Color       string `json:"color,omitempty"`
}

GameEnv 游戏环境项

type GameModel

type GameModel struct {
	// contains filtered or unexported fields
}

GameModel 提供游戏数据访问方法

func NewGameModel

func NewGameModel(db *gorm.DB) *GameModel

NewGameModel 创建游戏模型实例

func (*GameModel) Create

func (m *GameModel) Create(ctx context.Context, game *Game) error

Create 创建新游戏

func (*GameModel) Delete

func (m *GameModel) Delete(ctx context.Context, id uint) error

Delete 删除游戏

func (*GameModel) FindByName

func (m *GameModel) FindByName(ctx context.Context, name string) (*Game, error)

FindByName 根据名称获取游戏

func (*GameModel) FindOne

func (m *GameModel) FindOne(ctx context.Context, id uint) (*Game, error)

FindOne 根据 ID 获取游戏

func (*GameModel) List

func (m *GameModel) List(ctx context.Context, opts ListGamesOptions) ([]Game, int64, error)

List 分页获取游戏列表

func (*GameModel) ListAll

func (m *GameModel) ListAll(ctx context.Context) ([]Game, error)

ListAll returns every game ordered by updated time descending.

func (*GameModel) ToggleEnabled

func (m *GameModel) ToggleEnabled(ctx context.Context, id uint) error

ToggleEnabled 切换游戏启用状态

func (*GameModel) Update

func (m *GameModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update 更新游戏

func (*GameModel) UpdateStatus

func (m *GameModel) UpdateStatus(ctx context.Context, id uint, status string) error

UpdateStatus 更新游戏状态

type ListAdminsOptions

type ListAdminsOptions struct {
	Page     int
	PageSize int
	Search   string
	Role     string
	Status   *int
}

ListAdminsOptions controls pagination and filtering for listing admins.

type ListAlertsOptions

type ListAlertsOptions struct {
	PaginationOptions
	Level  string
	Status string
	Source string
}

ListAlertsOptions controls filtering/pagination.

type ListBackupsOptions

type ListBackupsOptions struct {
	PaginationOptions
	Type string
}

ListBackupsOptions controls list filtering.

type ListCertificatesOptions

type ListCertificatesOptions struct {
	Page     int
	PageSize int
	Status   string
}

ListCertificatesOptions controls pagination/filtering.

type ListEntitiesOptions

type ListEntitiesOptions struct {
	Page       int
	PageSize   int
	Type       string
	ProviderID string
	Status     *int
}

ListEntitiesOptions 控制实体列表查询的分页和过滤选项

type ListFAQOptions

type ListFAQOptions struct {
	PaginationOptions
	Category string
	Keyword  string
	Visible  *bool
}

ListFAQOptions controls listing.

type ListFeedbackOptions

type ListFeedbackOptions struct {
	PaginationOptions
	GameID   string
	Env      string
	Status   string
	Category string
	Keyword  string
}

ListFeedbackOptions controls filtering.

type ListFunctionsOptions

type ListFunctionsOptions struct {
	PaginationOptions
	GameID   string
	Category string
	Status   *int
	Search   string
}

ListFunctionsOptions controls listing.

type ListGamesOptions

type ListGamesOptions struct {
	Page     int
	PageSize int
	Status   string
	Search   string
}

ListGamesOptions 控制游戏列表查询的分页和过滤选项

type ListMessagesOptions

type ListMessagesOptions struct {
	Page     int
	PageSize int
	Type     string
	Status   string
	To       string
}

ListMessagesOptions controls pagination/filtering.

type ListNodesOptions

type ListNodesOptions struct {
	Type   string
	Status string
}

ListNodesOptions controls filtering.

type ListPermissionsOptions

type ListPermissionsOptions struct {
	Page     int
	PageSize int
	Category string
	Resource string
}

ListPermissionsOptions controls pagination/filtering.

type ListPlayersOptions

type ListPlayersOptions struct {
	Page     int
	PageSize int
	GameID   string
	Search   string
	Status   *int
	Level    *int
	VIP      *int
}

ListPlayersOptions 控制玩家列表查询的分页和过滤选项

type ListRolesOptions

type ListRolesOptions struct {
	Page     int
	PageSize int
	Category string
	Search   string
}

ListRolesOptions controls pagination/filtering when listing roles.

type ListSilencesOptions

type ListSilencesOptions struct {
	ActiveOnly bool
}

ListSilencesOptions filters silence entries.

type ListTicketsOptions

type ListTicketsOptions struct {
	PaginationOptions
	Status string
}

ListTicketsOptions controls filtering.

type Message

type Message struct {
	gorm.Model
	To      string         `gorm:"size:255;not null;index:idx_messages_to_status,priority:1;index:idx_messages_to_created"`
	Type    string         `gorm:"size:64;not null;index"`
	Title   string         `gorm:"size:255"`
	Content string         `gorm:"type:text"`
	Data    datatypes.JSON `gorm:"type:json"`
	Status  string         `gorm:"size:32;default:'unread';index:idx_messages_to_status,priority:2;index:idx_messages_status_created"`
	ReadAt  *time.Time     `gorm:"index"`
}

Message represents system/user notifications.

func (Message) TableName

func (Message) TableName() string

TableName implements gorm's tabler interface.

type MessageModel

type MessageModel struct {
	// contains filtered or unexported fields
}

MessageModel exposes CRUD helpers for messages.

func NewMessageModel

func NewMessageModel(db *gorm.DB) *MessageModel

NewMessageModel creates a message model.

func (*MessageModel) CountUnread

func (m *MessageModel) CountUnread(ctx context.Context, to string) (int64, error)

CountUnread returns number of unread messages (optionally filtered by recipient).

func (*MessageModel) Create

func (m *MessageModel) Create(ctx context.Context, msg *Message) error

Create inserts a new message.

func (*MessageModel) FindOne

func (m *MessageModel) FindOne(ctx context.Context, id uint) (*Message, error)

FindOne fetches a message by ID.

func (*MessageModel) List

List returns paginated messages with filters applied.

func (*MessageModel) MarkRead

func (m *MessageModel) MarkRead(ctx context.Context, id uint) error

MarkRead marks a message as read.

func (*MessageModel) Recent

func (m *MessageModel) Recent(ctx context.Context, limit int, to string) ([]Message, error)

Recent returns last N messages.

type Node

type Node struct {
	gorm.Model
	NodeID    string `gorm:"size:64;uniqueIndex"`
	Name      string `gorm:"size:128"`
	Type      string `gorm:"size:32;index"`
	Status    string `gorm:"size:32;index"`
	IP        string `gorm:"size:64"`
	Port      int
	Resources datatypes.JSONMap `gorm:"type:json"`
	Meta      datatypes.JSONMap `gorm:"type:json"`
}

Node stores managed node metadata.

func (Node) TableName

func (Node) TableName() string

type NodeCommand

type NodeCommand struct {
	gorm.Model
	Name        string `gorm:"size:64;uniqueIndex"`
	Description string `gorm:"size:255"`
}

NodeCommand describes an available agent command.

func (NodeCommand) TableName

func (NodeCommand) TableName() string

type NodeModel

type NodeModel struct {
	// contains filtered or unexported fields
}

NodeModel manages node metadata.

func NewNodeModel

func NewNodeModel(db *gorm.DB) *NodeModel

NewNodeModel returns helper.

func (*NodeModel) FindByNodeID

func (m *NodeModel) FindByNodeID(ctx context.Context, nodeID string) (*Node, error)

FindByNodeID fetches a node by its node_id.

func (*NodeModel) List

func (m *NodeModel) List(ctx context.Context, opts ListNodesOptions) ([]Node, error)

List returns nodes for filters.

func (*NodeModel) ListCommands

func (m *NodeModel) ListCommands(ctx context.Context) ([]NodeCommand, error)

ListCommands returns registered commands.

func (*NodeModel) UpdateMeta

func (m *NodeModel) UpdateMeta(ctx context.Context, nodeID string, updates map[string]interface{}) error

UpdateMeta updates node metadata map.

func (*NodeModel) UpdateStatus

func (m *NodeModel) UpdateStatus(ctx context.Context, nodeID, status string) error

UpdateStatus updates node status.

func (*NodeModel) Upsert

func (m *NodeModel) Upsert(ctx context.Context, node *Node) error

Upsert stores node info.

func (*NodeModel) UpsertCommand

func (m *NodeModel) UpsertCommand(ctx context.Context, command *NodeCommand) error

UpsertCommand stores a node command.

type PaginationOptions

type PaginationOptions struct {
	Page     int
	PageSize int
}

通用分页选项

func (*PaginationOptions) Normalize

func (opts *PaginationOptions) Normalize()

标准化分页参数

func (*PaginationOptions) Offset

func (opts *PaginationOptions) Offset() int

计算偏移量

type PaymentQueryOptions

type PaymentQueryOptions struct {
	PaginationOptions
	GameID    string
	Env       string
	Status    string
	StartTime time.Time
	EndTime   time.Time
}

PaymentQueryOptions controls transaction queries.

type PaymentTransaction

type PaymentTransaction struct {
	gorm.Model
	TransactionID string `gorm:"size:64;uniqueIndex"`
	GameID        string `gorm:"size:64;index"`
	Env           string `gorm:"size:32;index"`
	UserID        string `gorm:"size:64;index"`
	ProductID     string `gorm:"size:64;index"`
	ProductName   string `gorm:"size:128"`
	Amount        float64
	Currency      string            `gorm:"size:16"`
	Status        string            `gorm:"size:32;index"`
	PaymentMethod string            `gorm:"size:32"`
	Metadata      datatypes.JSONMap `gorm:"type:json"`
	OccurredAt    time.Time         `gorm:"index"`
}

PaymentTransaction records a single payment event.

func (PaymentTransaction) TableName

func (PaymentTransaction) TableName() string

type PaymentsModel

type PaymentsModel struct {
	// contains filtered or unexported fields
}

PaymentsModel handles payment analytics persistence.

func NewPaymentsModel

func NewPaymentsModel(db *gorm.DB) *PaymentsModel

NewPaymentsModel creates a new payments model helper.

func (*PaymentsModel) AggregateRevenue

func (m *PaymentsModel) AggregateRevenue(ctx context.Context, gameID, env string, start, end time.Time) (RevenueAggregate, error)

AggregateRevenue returns revenue, paying users, and transaction counts for the window.

func (*PaymentsModel) CreateTransaction

func (m *PaymentsModel) CreateTransaction(ctx context.Context, tx *PaymentTransaction) error

CreateTransaction records a new transaction.

func (*PaymentsModel) DailyRevenue

func (m *PaymentsModel) DailyRevenue(ctx context.Context, gameID, env string, start, end time.Time) ([]DailyRevenueStat, error)

DailyRevenue aggregates revenue per day within the range.

func (*PaymentsModel) ListProductTrends

func (m *PaymentsModel) ListProductTrends(ctx context.Context, gameID, env string) ([]ProductTrend, error)

ListProductTrends fetches trend snapshots.

func (*PaymentsModel) ListTransactions

func (m *PaymentsModel) ListTransactions(ctx context.Context, opts PaymentQueryOptions) ([]PaymentTransaction, int64, error)

ListTransactions returns paginated transactions.

func (*PaymentsModel) UpsertProductTrend

func (m *PaymentsModel) UpsertProductTrend(ctx context.Context, trend *ProductTrend) error

UpsertProductTrend stores aggregated product trend data.

type PendingFunction

type PendingFunction struct {
	gorm.Model
	FunctionID  string            `gorm:"size:64;uniqueIndex"`
	Payload     datatypes.JSONMap `gorm:"type:json"`
	RequestedBy string            `gorm:"size:64"`
	Status      string            `gorm:"size:32"`
}

PendingFunction stores functions awaiting approval.

func (PendingFunction) TableName

func (PendingFunction) TableName() string

type Permission

type Permission struct {
	ID          string         `gorm:"primaryKey;size:64;not null"`
	Name        string         `gorm:"size:128;not null"`
	Description string         `gorm:"type:text"`
	Resource    string         `gorm:"size:128;not null"`
	Action      string         `gorm:"size:64;not null"`
	Category    string         `gorm:"size:64;not null"`
	CreatedAt   time.Time      `gorm:"autoCreateTime"`
	UpdatedAt   time.Time      `gorm:"autoUpdateTime"`
	DeletedAt   gorm.DeletedAt `gorm:"index"`
}

Permission represents RBAC permissions.

func (Permission) TableName

func (Permission) TableName() string

TableName implements gorm's tabler interface.

type PermissionModel

type PermissionModel struct {
	// contains filtered or unexported fields
}

PermissionModel exposes query helpers for permissions.

func NewPermissionModel

func NewPermissionModel(db *gorm.DB) *PermissionModel

NewPermissionModel constructs a PermissionModel.

func (*PermissionModel) FindOne

func (m *PermissionModel) FindOne(ctx context.Context, id string) (*Permission, error)

FindOne fetches a permission by ID.

func (*PermissionModel) List

List fetches permissions using filters.

type Player

type Player struct {
	gorm.Model
	Username string `gorm:"size:64;not null;index:idx_player_username_game,priority:1"`
	Nickname string `gorm:"size:128;index"`
	Email    string `gorm:"size:256;index"`
	Phone    string `gorm:"size:32;index"`
	GameID   string `gorm:"size:64;index:idx_player_game_status,priority:1;index:idx_player_username_game,priority:2;not null"`
	Status   int    `gorm:"default:1;index:idx_player_game_status,priority:2"` // 1:active 0:banned 2:suspended
	Balance  int64  `gorm:"default:0;index"`                                   // 游戏货币
	Level    int    `gorm:"default:1;index"`
	VIP      int    `gorm:"default:0;index"`
	Password string `gorm:"size:255"` // 密码哈希
}

Player 玩家结构体 (对应 player.api)

func (*Player) Activate

func (p *Player) Activate()

Activate 激活玩家

func (*Player) Ban

func (p *Player) Ban()

Ban 封禁玩家

func (*Player) IsActive

func (p *Player) IsActive() bool

IsActive 检查玩家是否为活跃状态

func (*Player) IsBanned

func (p *Player) IsBanned() bool

IsBanned 检查玩家是否被封禁

func (*Player) IsSuspended

func (p *Player) IsSuspended() bool

IsSuspended 检查玩家是否被暂停

func (*Player) Suspend

func (p *Player) Suspend()

Suspend 暂停玩家

func (Player) TableName

func (Player) TableName() string

TableName 实现 GORM 的表名接口

type PlayerModel

type PlayerModel struct {
	// contains filtered or unexported fields
}

PlayerModel 提供玩家数据访问方法

func NewPlayerModel

func NewPlayerModel(db *gorm.DB) *PlayerModel

NewPlayerModel 创建玩家模型实例

func (*PlayerModel) ActivatePlayer

func (m *PlayerModel) ActivatePlayer(ctx context.Context, id uint) error

ActivatePlayer 激活玩家

func (*PlayerModel) BanPlayer

func (m *PlayerModel) BanPlayer(ctx context.Context, id uint) error

BanPlayer 封禁玩家

func (*PlayerModel) CountNewPlayers

func (m *PlayerModel) CountNewPlayers(ctx context.Context, gameID string, start, end time.Time) (int64, error)

CountNewPlayers returns the number of players created in the provided window.

func (*PlayerModel) Create

func (m *PlayerModel) Create(ctx context.Context, player *Player, password string) error

Create 创建新玩家

func (*PlayerModel) DailyNewPlayers

func (m *PlayerModel) DailyNewPlayers(ctx context.Context, gameID string, start, end time.Time) ([]DailyNewPlayerStat, error)

DailyNewPlayers aggregates new player counts per day within the window.

func (*PlayerModel) Delete

func (m *PlayerModel) Delete(ctx context.Context, id uint) error

Delete 删除玩家

func (*PlayerModel) FindByUsername

func (m *PlayerModel) FindByUsername(ctx context.Context, username string, gameID string) (*Player, error)

FindByUsername 根据用户名获取玩家

func (*PlayerModel) FindOne

func (m *PlayerModel) FindOne(ctx context.Context, id uint) (*Player, error)

FindOne 根据 ID 获取玩家

func (*PlayerModel) List

func (m *PlayerModel) List(ctx context.Context, opts ListPlayersOptions) ([]Player, int64, error)

List 分页获取玩家列表

func (*PlayerModel) SuspendPlayer

func (m *PlayerModel) SuspendPlayer(ctx context.Context, id uint) error

SuspendPlayer 暂停玩家

func (*PlayerModel) Update

func (m *PlayerModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update 更新玩家

func (*PlayerModel) UpdateBalance

func (m *PlayerModel) UpdateBalance(ctx context.Context, id uint, amount int64, reason string) (*Player, error)

UpdateBalance 更新玩家余额

func (*PlayerModel) UpdatePassword

func (m *PlayerModel) UpdatePassword(ctx context.Context, id uint, newPassword string) error

UpdatePassword 更新玩家密码

func (*PlayerModel) ValidatePassword

func (m *PlayerModel) ValidatePassword(ctx context.Context, username, password, gameID string) (*Player, error)

ValidatePassword 验证玩家密码

type ProductTrend

type ProductTrend struct {
	gorm.Model
	GameID      string `gorm:"size:64;index"`
	Env         string `gorm:"size:32;index"`
	ProductID   string `gorm:"size:64;index:idx_product_window,unique"`
	ProductName string `gorm:"size:128"`
	Revenue     float64
	Sales       int
	Growth      float64
	WindowStart time.Time `gorm:"index:idx_product_window,unique"`
	WindowEnd   time.Time
}

ProductTrend stores aggregated metrics per product.

func (ProductTrend) TableName

func (ProductTrend) TableName() string

type ProfileGame

type ProfileGame struct {
	gorm.Model
	AdminID     uint           `gorm:"index"`
	GameID      string         `gorm:"size:64"`
	GameName    string         `gorm:"size:128"`
	Color       string         `gorm:"size:32"`
	Envs        datatypes.JSON `gorm:"type:json"`
	Permissions datatypes.JSON `gorm:"type:json"`
}

ProfileGame stores admin game access summary.

func (ProfileGame) TableName

func (ProfileGame) TableName() string

type ProfileModel

type ProfileModel struct {
	// contains filtered or unexported fields
}

ProfileModel provides helpers for profile-related views.

func NewProfileModel

func NewProfileModel(db *gorm.DB) *ProfileModel

NewProfileModel creates helper.

func (*ProfileModel) ListGames

func (m *ProfileModel) ListGames(ctx context.Context, adminID uint) ([]ProfileGame, error)

ListGames returns cached games.

func (*ProfileModel) ListPermissions

func (m *ProfileModel) ListPermissions(ctx context.Context, adminID uint) ([]ProfilePermission, error)

ListPermissions returns cached permissions.

func (*ProfileModel) ReplaceGames

func (m *ProfileModel) ReplaceGames(ctx context.Context, adminID uint, games []ProfileGame) error

ReplaceGames replaces cached game scopes.

func (*ProfileModel) ReplacePermissions

func (m *ProfileModel) ReplacePermissions(ctx context.Context, adminID uint, perms []ProfilePermission) error

ReplacePermissions replaces cached permissions for an admin.

type ProfilePermission

type ProfilePermission struct {
	gorm.Model
	AdminID  uint           `gorm:"index"`
	Resource string         `gorm:"size:64"`
	GameID   string         `gorm:"size:64"`
	Env      string         `gorm:"size:32"`
	Actions  datatypes.JSON `gorm:"type:json"`
}

ProfilePermission stores cached permission info per admin.

func (ProfilePermission) TableName

func (ProfilePermission) TableName() string

type RateLimit

type RateLimit struct {
	gorm.Model
	RateLimitID string `gorm:"size:64;uniqueIndex"`
	Name        string `gorm:"size:128"`
	Resource    string `gorm:"size:64"`
	Limit       int
	Window      int
	Action      string            `gorm:"size:32"`
	Rules       datatypes.JSONMap `gorm:"type:json"`
	Status      int               `gorm:"default:1"`
}

RateLimit represents throttling configurations.

func (RateLimit) TableName

func (RateLimit) TableName() string

type RateLimitModel

type RateLimitModel struct {
	// contains filtered or unexported fields
}

RateLimitModel manages rate limit configs.

func NewRateLimitModel

func NewRateLimitModel(db *gorm.DB) *RateLimitModel

NewRateLimitModel creates helper.

func (*RateLimitModel) Delete

func (m *RateLimitModel) Delete(ctx context.Context, id uint) error

Delete removes a rate limit.

func (*RateLimitModel) DeleteByKey

func (m *RateLimitModel) DeleteByKey(ctx context.Context, key string) error

DeleteByKey removes a rate limit by RateLimitID.

func (*RateLimitModel) FindByID

func (m *RateLimitModel) FindByID(ctx context.Context, id uint) (*RateLimit, error)

FindByID loads a rate limit by numeric primary key.

func (*RateLimitModel) FindByKey

func (m *RateLimitModel) FindByKey(ctx context.Context, key string) (*RateLimit, error)

FindByKey loads a rate limit via RateLimitID.

func (*RateLimitModel) List

func (m *RateLimitModel) List(ctx context.Context, resource string) ([]RateLimit, error)

List returns rate limits filtered by resource.

func (*RateLimitModel) Upsert

func (m *RateLimitModel) Upsert(ctx context.Context, rl *RateLimit) error

Upsert stores a rate limit entry.

type RetentionCohort

type RetentionCohort struct {
	gorm.Model
	GameID      string         `gorm:"size:64;index"`
	Env         string         `gorm:"size:32;index"`
	Cohort      string         `gorm:"size:32;index"`
	Users       int            `gorm:"default:0"`
	Retention   datatypes.JSON `gorm:"type:json"`
	WindowStart time.Time
	WindowEnd   time.Time
}

RetentionCohort stores cohort retention metrics.

func (RetentionCohort) TableName

func (RetentionCohort) TableName() string

type RetentionModel

type RetentionModel struct {
	// contains filtered or unexported fields
}

RetentionModel manages cohort persistence.

func NewRetentionModel

func NewRetentionModel(db *gorm.DB) *RetentionModel

NewRetentionModel creates a retention model helper.

func (*RetentionModel) ListCohorts

func (m *RetentionModel) ListCohorts(ctx context.Context, gameID, env, cohortName string) ([]RetentionCohort, error)

ListCohorts fetches retention cohorts for filters.

func (*RetentionModel) UpsertCohort

func (m *RetentionModel) UpsertCohort(ctx context.Context, cohort *RetentionCohort) error

UpsertCohort stores cohort metrics.

type RevenueAggregate

type RevenueAggregate struct {
	Revenue      float64
	Payers       int64
	Transactions int64
}

RevenueAggregate summarizes revenue data for a period.

type Role

type Role struct {
	gorm.Model
	Name        string `gorm:"uniqueIndex;size:64;not null"`
	Description string `gorm:"size:256"`
	Category    string `gorm:"size:64;index"`
}

Role represents RBAC roles.

func (Role) TableName

func (Role) TableName() string

TableName implements gorm's tabler interface.

type RoleModel

type RoleModel struct {
	// contains filtered or unexported fields
}

RoleModel exposes CRUD helpers for Role + Permission relationships.

func NewRoleModel

func NewRoleModel(db *gorm.DB) *RoleModel

NewRoleModel constructs a RoleModel.

func (*RoleModel) Create

func (m *RoleModel) Create(ctx context.Context, role *Role) error

Create inserts a new role.

func (*RoleModel) Delete

func (m *RoleModel) Delete(ctx context.Context, id uint) error

Delete removes a role.

func (*RoleModel) FindOne

func (m *RoleModel) FindOne(ctx context.Context, id uint) (*Role, error)

FindOne fetches a role by ID.

func (*RoleModel) GetRolePermissionIDs

func (m *RoleModel) GetRolePermissionIDs(ctx context.Context, roleID uint) ([]string, error)

GetRolePermissionIDs returns permission IDs attached to the role.

func (*RoleModel) GetRolesPermissionIDs

func (m *RoleModel) GetRolesPermissionIDs(ctx context.Context, roleIDs []uint) (map[uint][]string, error)

GetRolesPermissionIDs fetches permission IDs for multiple roles.

func (*RoleModel) List

func (m *RoleModel) List(ctx context.Context, opts ListRolesOptions) ([]Role, int64, error)

List returns paginated roles plus total count.

func (*RoleModel) ReplacePermissions

func (m *RoleModel) ReplacePermissions(ctx context.Context, roleID uint, permissionIDs []string) error

ReplacePermissions rewrites role_permissions entries for the given role.

func (*RoleModel) Update

func (m *RoleModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update applies partial updates to a role.

func (*RoleModel) ValidatePermissionIDs

func (m *RoleModel) ValidatePermissionIDs(ctx context.Context, permissionIDs []string) ([]string, error)

ValidatePermissionIDs ensures all provided permission IDs exist and returns deduplicated IDs.

type RolePermission

type RolePermission struct {
	gorm.Model
	RoleID       uint   `gorm:"index:idx_role_permissions_role_id;not null"`
	PermissionID string `gorm:"index:idx_role_permissions_permission_id;size:64;not null"`
}

RolePermission links roles and permissions.

func (RolePermission) TableName

func (RolePermission) TableName() string

TableName implements gorm's tabler interface.

type SupportComment

type SupportComment struct {
	gorm.Model
	TicketID uint   `gorm:"index"`
	Author   string `gorm:"size:64"`
	Content  string `gorm:"type:text"`
	Attach   string `gorm:"type:text"`
}

SupportComment stores comments for support tickets.

func (SupportComment) TableName

func (SupportComment) TableName() string

type SupportFAQ

type SupportFAQ struct {
	gorm.Model
	Question string `gorm:"type:text"`
	Answer   string `gorm:"type:text"`
	Category string `gorm:"size:64"`
	Tags     string `gorm:"size:255"`
	Visible  bool   `gorm:"default:true"`
	Sort     int    `gorm:"default:0"`
}

SupportFAQ mirrors FAQ entries in the support context.

func (SupportFAQ) TableName

func (SupportFAQ) TableName() string

type SupportFeedback

type SupportFeedback struct {
	gorm.Model
	PlayerID string `gorm:"size:64"`
	Contact  string `gorm:"size:128"`
	Content  string `gorm:"type:text"`
	Category string `gorm:"size:64"`
	Priority string `gorm:"size:16"`
	Status   string `gorm:"size:32"`
	Attach   string `gorm:"type:text"`
	GameID   string `gorm:"size:64"`
	Env      string `gorm:"size:64"`
}

SupportFeedback stores support feedback.

func (SupportFeedback) TableName

func (SupportFeedback) TableName() string

type SupportModel

type SupportModel struct {
	// contains filtered or unexported fields
}

SupportModel wraps support data operations.

func NewSupportModel

func NewSupportModel(db *gorm.DB) *SupportModel

NewSupportModel creates helper.

func (*SupportModel) CreateComment

func (m *SupportModel) CreateComment(ctx context.Context, comment *SupportComment) error

CreateComment inserts ticket comment.

func (*SupportModel) CreateFAQ

func (m *SupportModel) CreateFAQ(ctx context.Context, faq *SupportFAQ) error

CreateFAQ inserts FAQ.

func (*SupportModel) CreateFeedback

func (m *SupportModel) CreateFeedback(ctx context.Context, feedback *SupportFeedback) error

CreateFeedback inserts support feedback.

func (*SupportModel) CreateTicket

func (m *SupportModel) CreateTicket(ctx context.Context, ticket *SupportTicket) error

CreateTicket inserts ticket.

func (*SupportModel) DeleteTicket

func (m *SupportModel) DeleteTicket(ctx context.Context, id uint) error

DeleteTicket deletes ticket.

func (*SupportModel) ListComments

func (m *SupportModel) ListComments(ctx context.Context, ticketID uint) ([]SupportComment, error)

ListComments fetches ticket comments.

func (*SupportModel) ListFAQs

func (m *SupportModel) ListFAQs(ctx context.Context) ([]SupportFAQ, error)

ListFAQs returns FAQs.

func (*SupportModel) ListFeedback

func (m *SupportModel) ListFeedback(ctx context.Context) ([]SupportFeedback, error)

ListFeedback returns support feedback entries.

func (*SupportModel) ListTickets

func (m *SupportModel) ListTickets(ctx context.Context, opts ListTicketsOptions) ([]SupportTicket, int64, error)

ListTickets returns paginated tickets.

func (*SupportModel) UpdateTicket

func (m *SupportModel) UpdateTicket(ctx context.Context, id uint, updates map[string]interface{}) error

UpdateTicket updates ticket fields.

type SupportTicket

type SupportTicket struct {
	gorm.Model
	Title    string `gorm:"size:255"`
	Content  string `gorm:"type:text"`
	Category string `gorm:"size:64"`
	Priority string `gorm:"size:16"`
	Status   string `gorm:"size:32;index"`
	Assignee string `gorm:"size:64"`
	Tags     string `gorm:"size:255"`
	PlayerID string `gorm:"size:64"`
	Contact  string `gorm:"size:128"`
	GameID   string `gorm:"size:64;index"`
	Env      string `gorm:"size:64"`
	Source   string `gorm:"size:32"`
	DueAt    *time.Time
}

SupportTicket captures support ticket data.

func (SupportTicket) TableName

func (SupportTicket) TableName() string

type Ticket

type Ticket struct {
	gorm.Model
	Title    string         `gorm:"size:255"`
	Content  string         `gorm:"type:text"`
	Category string         `gorm:"size:64;index:idx_ticket_category_status"`
	Priority string         `gorm:"size:16;index"`
	Status   string         `gorm:"size:32;index:idx_ticket_status;index:idx_ticket_category_status"`
	Assignee string         `gorm:"size:64;index"`
	Tags     datatypes.JSON `gorm:"type:json"`
	PlayerID string         `gorm:"size:64;index"`
	Contact  string         `gorm:"size:128"`
	GameID   string         `gorm:"size:64;index:idx_ticket_game_env,priority:1"`
	Env      string         `gorm:"size:64;index:idx_ticket_game_env,priority:2"`
	Source   string         `gorm:"size:32;index"`
	DueAt    *time.Time     `gorm:"index"`
}

Ticket represents the primary ticketing model for /tickets API.

func (Ticket) TableName

func (Ticket) TableName() string

type TicketComment

type TicketComment struct {
	gorm.Model
	TicketID uint   `gorm:"index"`
	Author   string `gorm:"size:64"`
	Content  string `gorm:"type:text"`
}

TicketComment stores comments under /tickets module.

func (TicketComment) TableName

func (TicketComment) TableName() string

type TicketModel

type TicketModel struct {
	// contains filtered or unexported fields
}

TicketModel manages ticket entities for the ticket module.

func NewTicketModel

func NewTicketModel(db *gorm.DB) *TicketModel

NewTicketModel creates helper.

func (*TicketModel) Create

func (m *TicketModel) Create(ctx context.Context, ticket *Ticket) error

Create inserts a ticket.

func (*TicketModel) CreateComment

func (m *TicketModel) CreateComment(ctx context.Context, comment *TicketComment) error

CreateComment inserts ticket comment.

func (*TicketModel) Delete

func (m *TicketModel) Delete(ctx context.Context, id uint) error

Delete removes a ticket.

func (*TicketModel) FindOne

func (m *TicketModel) FindOne(ctx context.Context, id uint) (*Ticket, error)

FindOne loads a ticket.

func (*TicketModel) List

func (m *TicketModel) List(ctx context.Context, opts TicketQueryOptions) ([]Ticket, int64, error)

List returns paginated tickets.

func (*TicketModel) ListComments

func (m *TicketModel) ListComments(ctx context.Context, ticketID uint) ([]TicketComment, error)

ListComments fetches ticket comments.

func (*TicketModel) Update

func (m *TicketModel) Update(ctx context.Context, id uint, updates map[string]interface{}) error

Update modifies a ticket.

type TicketQueryOptions

type TicketQueryOptions struct {
	PaginationOptions
	Status   string
	Category string
	Priority string
	Assignee string
}

ListTicketsOptions controls filtering.

type TimestampMixin

type TimestampMixin struct {
	CreatedAt time.Time `gorm:"autoCreateTime"`
	UpdatedAt time.Time `gorm:"autoUpdateTime"`
}

通用更新时间跟踪

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL