chore: 添加计费处理调试日志
This commit is contained in:
@@ -107,7 +107,6 @@ func (w *asyncWorker) handleOne(ctx context.Context, task *entity.ModelGatewayTa
|
||||
|
||||
// 计费处理
|
||||
if len(model.BillingConfig) > 0 && len(task.BillingData) > 0 {
|
||||
fmt.Printf("[handleOne] 计费处理 BillingConfig=%s, BillingData=%s", model.BillingConfig, task.BillingData)
|
||||
// 取请求阶段数据作为基础
|
||||
billingInput := make(map[string]any)
|
||||
for k, v := range task.BillingData[0] {
|
||||
@@ -123,12 +122,12 @@ func (w *asyncWorker) handleOne(ctx context.Context, task *entity.ModelGatewayTa
|
||||
if billingResult != nil {
|
||||
task.BillingData[0] = billingResult
|
||||
}
|
||||
fmt.Printf("[handleOne] 计费处理 BillingResult=%s", billingResult)
|
||||
if billingResult != nil {
|
||||
task.BillingData[0] = billingResult
|
||||
totalFee := gconv.Float64(billingResult["total_fee"])
|
||||
fmt.Printf("[handleOne] 计费处理 totalFee=%f", totalFee)
|
||||
fmt.Printf("[handleOne] 计费处理 totalFee1=%f", totalFee)
|
||||
if totalFee > 0 {
|
||||
fmt.Printf("[handleOne] 计费处理 totalFee2=%f", totalFee)
|
||||
_ = gateway.DeductBalance(util.AsyncCtx(ctx), model.TenantId, -totalFee)
|
||||
}
|
||||
}
|
||||
@@ -326,8 +325,6 @@ func (w *asyncWorker) parseAndRetry(ctx context.Context, body map[string]any, mo
|
||||
|
||||
// 计费
|
||||
if len(model.BillingConfig) > 0 && len(task.BillingData) > 0 {
|
||||
fmt.Println("task.BillingData", task.BillingData)
|
||||
fmt.Println("task.BillingData", task.BillingData)
|
||||
requestData := task.BillingData[0]
|
||||
retryData := make(map[string]any)
|
||||
for k, v := range requestData {
|
||||
@@ -338,12 +335,12 @@ func (w *asyncWorker) parseAndRetry(ctx context.Context, body map[string]any, mo
|
||||
retryData[k] = v
|
||||
}
|
||||
billingResult := util.CalculateBilling(model.BillingConfig, retryData)
|
||||
fmt.Println("billingResult", billingResult)
|
||||
if billingResult != nil {
|
||||
task.BillingData = append(task.BillingData, billingResult)
|
||||
totalFee := gconv.Float64(billingResult["total_fee"])
|
||||
fmt.Println("totalFee", totalFee)
|
||||
fmt.Println("totalFee==================", totalFee)
|
||||
if totalFee > 0 {
|
||||
fmt.Println("deduct balance================", totalFee)
|
||||
_ = gateway.DeductBalance(util.AsyncCtx(ctx), task.TenantId, -totalFee)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user