package model import ( "time" ) // 登录类型常量 const ( LoginTypeLogin = "login" // 登录 LoginTypeRefresh = "refresh" // 刷新Token ) // UserActiveLog 用户活跃日志 type UserActiveLog struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` UserID string `gorm:"type:varchar(36);not null;index:idx_user_date,priority:1;index" json:"user_id"` // 用户ID (UUID) ActiveDate time.Time `gorm:"type:date;not null;index:idx_user_date,priority:2;index" json:"active_date"` // 活跃日期 LoginType string `gorm:"type:varchar(20);not null" json:"login_type"` // 登录类型: login/refresh LoginIP string `gorm:"type:varchar(45)" json:"login_ip"` // 登录IP UserAgent string `gorm:"type:varchar(500)" json:"user_agent"` // 用户代理 CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` // 关联 User User `gorm:"foreignKey:UserID" json:"user,omitempty"` } // TableName 指定表名 func (UserActiveLog) TableName() string { return "user_active_logs" } // UserActivityStat 用户活跃统计快照 type UserActivityStat struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` StatType string `gorm:"type:varchar(10);not null;uniqueIndex:idx_type_date" json:"stat_type"` // dau/wau/mau StatDate time.Time `gorm:"type:date;not null;uniqueIndex:idx_type_date" json:"stat_date"` // 统计日期 ActiveCount int64 `gorm:"not null" json:"active_count"` // 活跃用户数 NewCount int64 `gorm:"default:0" json:"new_count"` // 新增用户数 Retention1 float64 `gorm:"type:decimal(5,2)" json:"retention_1"` // 次日留存率 Retention7 float64 `gorm:"type:decimal(5,2)" json:"retention_7"` // 7日留存率 Retention30 float64 `gorm:"type:decimal(5,2)" json:"retention_30"` // 30日留存率 CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` } // TableName 指定表名 func (UserActivityStat) TableName() string { return "user_activity_stats" }