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) } } }