5d9667d27a
# Conflicts: # backend/cmd/server/VERSION # backend/ent/migrate/schema.go # backend/ent/mutation.go # backend/ent/runtime/runtime.go # backend/ent/usagelog.go # backend/ent/usagelog/usagelog.go # backend/ent/usagelog/where.go # backend/ent/usagelog_create.go # backend/ent/usagelog_update.go # backend/internal/repository/usage_log_repo.go # backend/internal/server/api_contract_test.go # backend/internal/server/middleware/cors.go # backend/internal/service/gateway_service.go
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package service
|
|
|
|
import "time"
|
|
|
|
const (
|
|
BillingTypeBalance int8 = 0 // 钱包余额
|
|
BillingTypeSubscription int8 = 1 // 订阅套餐
|
|
)
|
|
|
|
type UsageLog struct {
|
|
ID int64
|
|
UserID int64
|
|
APIKeyID int64
|
|
AccountID int64
|
|
RequestID string
|
|
Model string
|
|
// ReasoningEffort is the request's reasoning effort level (OpenAI Responses API),
|
|
// e.g. "low" / "medium" / "high" / "xhigh". Nil means not provided / not applicable.
|
|
ReasoningEffort *string
|
|
|
|
GroupID *int64
|
|
SubscriptionID *int64
|
|
|
|
InputTokens int
|
|
OutputTokens int
|
|
CacheCreationTokens int
|
|
CacheReadTokens int
|
|
|
|
CacheCreation5mTokens int `gorm:"column:cache_creation_5m_tokens"`
|
|
CacheCreation1hTokens int `gorm:"column:cache_creation_1h_tokens"`
|
|
|
|
InputCost float64
|
|
OutputCost float64
|
|
CacheCreationCost float64
|
|
CacheReadCost float64
|
|
TotalCost float64
|
|
ActualCost float64
|
|
RateMultiplier float64
|
|
// AccountRateMultiplier 账号计费倍率快照(nil 表示历史数据,按 1.0 处理)
|
|
AccountRateMultiplier *float64
|
|
|
|
BillingType int8
|
|
Stream bool
|
|
DurationMs *int
|
|
FirstTokenMs *int
|
|
UserAgent *string
|
|
IPAddress *string
|
|
|
|
// Cache TTL Override 标记(管理员强制替换了缓存 TTL 计费)
|
|
CacheTTLOverridden bool
|
|
|
|
// 图片生成字段
|
|
ImageCount int
|
|
ImageSize *string
|
|
MediaType *string
|
|
|
|
CreatedAt time.Time
|
|
|
|
User *User
|
|
APIKey *APIKey
|
|
Account *Account
|
|
Group *Group
|
|
Subscription *UserSubscription
|
|
}
|
|
|
|
func (u *UsageLog) TotalTokens() int {
|
|
return u.InputTokens + u.OutputTokens + u.CacheCreationTokens + u.CacheReadTokens
|
|
}
|