fix(channel): use upstream model for account stats pricing and remove channel pricing fallback

- resolveAccountStatsCost now uses the final upstream model (after
  account-level mapping) to match custom pricing rules, fixing the
  issue where requested model (e.g. claude-sonnet-4-5) didn't match
  rules configured for upstream model (e.g. claude-opus-4-6)
- Remove tryChannelPricing fallback — only custom rules are applied,
  unmatched requests use default formula (total_cost × rate)
- Remove unused billingService and serviceTier parameters
- Update description: "启用后将支持自定义账号统计的模型价格"
This commit is contained in:
erio
2026-04-14 09:26:08 +08:00
parent 95f9b27e70
commit 11c4606874
5 changed files with 25 additions and 42 deletions
@@ -4573,12 +4573,16 @@ func (s *OpenAIGatewayService) RecordUsage(ctx context.Context, input *OpenAIRec
usageLog.SubscriptionID = &subscription.ID
}
// 计算账号统计定价费用
// 计算账号统计定价费用(使用最终上游模型匹配自定义规则)
if apiKey.GroupID != nil {
statsModel := result.UpstreamModel
if statsModel == "" {
statsModel = result.Model
}
usageLog.AccountStatsCost = resolveAccountStatsCost(
ctx, s.channelService, s.billingService,
account.ID, *apiKey.GroupID, billingModel,
tokens, 1, serviceTier,
ctx, s.channelService,
account.ID, *apiKey.GroupID, statsModel,
tokens, 1,
)
}