From b8006329d12d7a2f7e41ae6c2950c9bca88009ba Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Wed, 8 Jul 2026 09:22:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E4=B8=8E=E7=BB=93=E6=9E=9C=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=8F=8A=E6=89=A9=E5=B1=95=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构执行列表树状结构,扁平化日期节点下的输出项,新增会话列表查询、结果删除与软删除标记,引入扩展字段与模板配置,升级依赖版本。 --- common/util/billing.go | 22 ++-------------------- service/task/worker.go | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/common/util/billing.go b/common/util/billing.go index b9dabe6..85e8eed 100644 --- a/common/util/billing.go +++ b/common/util/billing.go @@ -117,23 +117,8 @@ func calculateVideoResolutionBilling(config map[string]any, data map[string]any) } func calculateTTSBilling(config map[string]any, data map[string]any) map[string]any { - unit, _ := config["unit"].(string) - usage := gconv.Float64(data["usage"]) - - tiers := config["pricing"].(map[string]any)["tiers"].([]any) - var matched map[string]any - for _, t := range tiers { - tier := t.(map[string]any) - if usage >= gconv.Float64(tier["min"]) && usage <= gconv.Float64(tier["max"]) { - matched = tier - break - } - } - if matched == nil { - return nil - } - - unitPrice := gconv.Float64(matched["unit_price"]) + usage := gconv.Float64(data["synthesize_text_length"]) + unitPrice := gconv.Float64(config["pricing"]) totalFee := usage * unitPrice return map[string]any{ @@ -143,10 +128,7 @@ func calculateTTSBilling(config map[string]any, data map[string]any) map[string] // 明细 "prompt_tokens": 0, "completion_tokens": int64(usage), - "usage": usage, - "unit": unit, "unit_price": unitPrice, - "tier": fmt.Sprintf("[%v, %v]", matched["min"], matched["max"]), } } diff --git a/service/task/worker.go b/service/task/worker.go index 5f466c8..357c8ce 100644 --- a/service/task/worker.go +++ b/service/task/worker.go @@ -126,7 +126,13 @@ func (w *asyncWorker) handleOne(ctx context.Context, task *entity.ModelGatewayTa task.BillingData[0] = billingResult totalFee := gconv.Float64(billingResult["total_fee"]) if totalFee > 0 { - _ = gateway.DeductBalance(util.AsyncCtx(ctx), model.TenantId, -totalFee) + for attempt := 0; attempt <= maxRetry; attempt++ { + err = gateway.DeductBalance(util.AsyncCtx(ctx), model.TenantId, -totalFee) + if err == nil { + break + } + g.Log().Warningf(ctx, "[handleOne] 扣除余额失败 taskId=%s attempt=%d/%d err=%v", task.TaskID, attempt, maxRetry, err) + } } } } @@ -337,7 +343,13 @@ func (w *asyncWorker) parseAndRetry(ctx context.Context, body map[string]any, mo task.BillingData = append(task.BillingData, billingResult) totalFee := gconv.Float64(billingResult["total_fee"]) if totalFee > 0 { - _ = gateway.DeductBalance(util.AsyncCtx(ctx), task.TenantId, -totalFee) + for a := 0; a <= maxRetry; a++ { + errr := gateway.DeductBalance(util.AsyncCtx(ctx), task.TenantId, -totalFee) + if errr == nil { + break + } + g.Log().Warningf(ctx, "[handleOne] 扣除余额失败 taskId=%s attempt=%d/%d err=%v", task.TaskID, a, maxRetry, errr) + } } }