From 313bb692c72bc194eefaff0133ecbc5966568fbc Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Wed, 1 Jul 2026 19:32:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E4=BD=99=E9=A2=9D=E5=93=8D=E5=BA=94=E7=BB=93=E6=9E=84=E5=8F=8A?= =?UTF-8?q?=E7=A7=9F=E6=88=B7ID=E5=BC=95=E7=94=A8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新 TenantSurplusResp 结构以匹配实际的嵌套 JSON 响应格式, 并修正 worker 中 billing 逻辑错误引用的租户ID变量。 --- service/gateway/gateway_http_service.go | 6 ++++-- service/task/worker.go | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/service/gateway/gateway_http_service.go b/service/gateway/gateway_http_service.go index 0ad2635..9df0638 100644 --- a/service/gateway/gateway_http_service.go +++ b/service/gateway/gateway_http_service.go @@ -257,7 +257,9 @@ func DeductBalance(ctx context.Context, tenantId uint64, amount float64) error { // TenantSurplusResp 租户余额返回 type TenantSurplusResp struct { - Surplus float64 `json:"surplus"` + Tenant struct { + Surplus float64 `json:"surplus"` + } `json:"tenant"` } // GetTenantSurplus 获取租户余额 @@ -278,7 +280,7 @@ func GetTenantSurplus(ctx context.Context, tenantId uint64) (float64, error) { g.Log().Warningf(ctx, "[获取余额] 失败 tenantId=%d err=%v", tenantId, err) return 0, err } - return resp.Surplus, nil + return resp.Tenant.Surplus, nil } //// callback 向回调地址 POST 任务结果(与查询接口 GetTaskRes 出参一致) diff --git a/service/task/worker.go b/service/task/worker.go index 79d7b2e..6146cb7 100644 --- a/service/task/worker.go +++ b/service/task/worker.go @@ -50,7 +50,7 @@ func (w *asyncWorker) handleOne(ctx context.Context, task *entity.ModelGatewayTa w.failTask(ctx, task, startTime, "租户余额不足") return } - g.Log().Infof(ctx, "[handleOne] 当前余额 tenantId=%d surplus=%.2f", task.TenantId, surplus) + g.Log().Infof(ctx, "[handleOne] 当前余额 tenantId=%d surplus=%.2f", model.TenantId, surplus) // ============================================ // 2) 调用模型 @@ -127,7 +127,7 @@ 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), task.TenantId, -totalFee) + _ = gateway.DeductBalance(util.AsyncCtx(ctx), model.TenantId, -totalFee) } } }