mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 02:25:00 +00:00
refactor(logs): add refund logging for asynchronous tasks and update translations
This commit is contained in:
43
model/log.go
43
model/log.go
@@ -199,6 +199,49 @@ func RecordConsumeLog(c *gin.Context, userId int, params RecordConsumeLogParams)
|
||||
}
|
||||
}
|
||||
|
||||
type RecordTaskBillingLogParams struct {
|
||||
UserId int
|
||||
LogType int
|
||||
Content string
|
||||
ChannelId int
|
||||
ModelName string
|
||||
Quota int
|
||||
TokenId int
|
||||
Group string
|
||||
Other map[string]interface{}
|
||||
}
|
||||
|
||||
func RecordTaskBillingLog(params RecordTaskBillingLogParams) {
|
||||
if params.LogType == LogTypeConsume && !common.LogConsumeEnabled {
|
||||
return
|
||||
}
|
||||
username, _ := GetUsernameById(params.UserId, false)
|
||||
tokenName := ""
|
||||
if params.TokenId > 0 {
|
||||
if token, err := GetTokenById(params.TokenId); err == nil {
|
||||
tokenName = token.Name
|
||||
}
|
||||
}
|
||||
log := &Log{
|
||||
UserId: params.UserId,
|
||||
Username: username,
|
||||
CreatedAt: common.GetTimestamp(),
|
||||
Type: params.LogType,
|
||||
Content: params.Content,
|
||||
TokenName: tokenName,
|
||||
ModelName: params.ModelName,
|
||||
Quota: params.Quota,
|
||||
ChannelId: params.ChannelId,
|
||||
TokenId: params.TokenId,
|
||||
Group: params.Group,
|
||||
Other: common.MapToJsonStr(params.Other),
|
||||
}
|
||||
err := LOG_DB.Create(log).Error
|
||||
if err != nil {
|
||||
common.SysLog("failed to record task billing log: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, startIdx int, num int, channel int, group string, requestId string) (logs []*Log, total int64, err error) {
|
||||
var tx *gorm.DB
|
||||
if logType == LogTypeUnknown {
|
||||
|
||||
Reference in New Issue
Block a user