Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controller/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ func RelayTask(c *gin.Context) {
task.PrivateData.BillingSource = relayInfo.BillingSource
task.PrivateData.SubscriptionId = relayInfo.SubscriptionId
task.PrivateData.TokenId = relayInfo.TokenId
task.PrivateData.NodeName = common.NodeName
task.PrivateData.BillingContext = &model.TaskBillingContext{
ModelPrice: relayInfo.PriceData.ModelPrice,
GroupRatio: relayInfo.PriceData.GroupRatioInfo.GroupRatio,
Expand Down
7 changes: 6 additions & 1 deletion model/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ type RecordTaskBillingLogParams struct {
TokenId int
Group string
Other map[string]interface{}
NodeName string // 任务发起节点;为空时回退当前节点
}

func RecordTaskBillingLog(params RecordTaskBillingLogParams) {
Expand Down Expand Up @@ -423,6 +424,10 @@ func RecordTaskBillingLog(params RecordTaskBillingLogParams) {
common.SysLog("failed to record task billing log: " + err.Error())
}
if params.LogType == LogTypeConsume && common.DataExportEnabled {
nodeName := params.NodeName
if nodeName == "" {
nodeName = common.NodeName
}
gopool.Go(func() {
LogQuotaData(QuotaDataLogParams{
UserID: params.UserId,
Expand All @@ -433,7 +438,7 @@ func RecordTaskBillingLog(params RecordTaskBillingLogParams) {
UseGroup: params.Group,
TokenID: params.TokenId,
ChannelID: params.ChannelId,
NodeName: common.NodeName,
NodeName: nodeName,
})
})
}
Expand Down
1 change: 1 addition & 0 deletions model/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type TaskPrivateData struct {
BillingSource string `json:"billing_source,omitempty"` // "wallet" 或 "subscription"
SubscriptionId int `json:"subscription_id,omitempty"` // 订阅 ID,用于订阅退款
TokenId int `json:"token_id,omitempty"` // 令牌 ID,用于令牌额度退款
NodeName string `json:"node_name,omitempty"` // 发起任务的节点名,轮询结算阶段据此归属日志而非最后查询节点
BillingContext *TaskBillingContext `json:"billing_context,omitempty"` // 计费参数快照(用于轮询阶段重新计算)
}

Expand Down
1 change: 1 addition & 0 deletions service/task_billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func RecalculateTaskQuota(ctx context.Context, task *model.Task, actualQuota int
TokenId: task.PrivateData.TokenId,
Group: task.Group,
Other: other,
NodeName: task.PrivateData.NodeName,
})
}

Expand Down