Skip to content

fix(qoder): 额度按套餐+加量包+资源包求和,修复签到后额度不显示 - #231

Open
BrianBoyCN wants to merge 1 commit into
caigee-cmd:mainfrom
BrianBoyCN:fix/qoder-quota-sum-buckets
Open

BrianBoyCN wants to merge 1 commit into
caigee-cmd:mainfrom
BrianBoyCN:fix/qoder-quota-sum-buckets

Conversation

@BrianBoyCN

Copy link
Copy Markdown

Refs #229

概述

修复 Qoder(国内版/国际版)签到后额度不显示 / 一直停在 300 的问题(#229)。

根因

Qoder 上游把额度拆在最多三个桶里:套餐额度 userQuota、加量包 addOnQuota、组织资源包 orgResourcePackage。

  • 每日签到奖励进的是 addOnQuota;
  • 而 internal/providers/qoder/quota.go 的 snapshot() 只取 userQuota 作为卡片主数值。

所以:套餐额度为 300 的账号签到后,主数字仍是 300(奖励在加量包里没被算进去)→ 就是 #229 说的「一直显示 300 积分,未增加过」;纯余额档(personal_standard,上游 userQuota 全 0)则永远显示 0%。

上游口径(本机实测,非猜测)

用一个真实 CN 账号核对,上游自己返回的百分比就是三桶合计:

userQuota 139/300 + addOnQuota 0/400  →  上游 totalUsagePercentage = 20
139 / (300 + 400) = 19.86% ≈ 20

并且 Qoder 客户端自身的合计逻辑也是三桶相加:

remaining = userQuota.remaining + addOnQuota.remaining + orgResourcePackage.remaining

改动

snapshot() 的 headline(Used / Total / Remaining / Percentage)改为可用桶之和,对齐上游口径:

  • 套餐 + 加量包 + 组织资源包求和(跳过 available === false 的桶);
  • 每桶明细字段(has_add_on / add_on_* / has_resource_package / resource_package_*)保持不变,控制台 tooltip 照旧;
  • Exceeded 语义不变:套餐耗尽但加量包/资源包仍有可用额度时,账号仍可路由;
  • 三个桶都缺失时返回 nil(未知),不编造 0。

纯后端改动,无前端/接口字段变更。

Test plan

  • go test ./...
  • go vet ./...
  • cd worker && npm test
  • cd frontend && npm run build && npm run lint
  • 已添加 changelog/unreleased/qoder-quota-sum-buckets.md
  • diff 中无 token、鉴权 blob、原始抓包或主机信息

另附:新增/更新单测覆盖「套餐+加量包求和」「纯余额档」「套餐耗尽但加量包可用」「资源包参与合计 / 不可用资源包被忽略」「无任何桶 → nil」;go test -race ./... 与 gitleaks 本地通过。

Qoder reports credits in up to three buckets: the plan's monthly user quota,
the add-on pack, and an organization resource package. The account card read
only the plan quota, so a plan-only account never moved after a daily check-in
— the reward lands in the add-on bucket (issue caigee-cmd#229, "一直显示 300 积分,未增加过"),
and a balance-only account with no plan quota showed a flat 0%.

Sum the available buckets for the headline Used/Total/Remaining/Percentage,
matching how the Qoder client itself totals them (its remaining is
userQuota + addOnQuota + orgResourcePackage) and the upstream
totalUsagePercentage, which is the same aggregate ratio. Per-bucket detail
fields (has_add_on / add_on_* / has_resource_package / resource_package_*) are
unchanged, and Exceeded keeps its meaning: an available add-on or package still
keeps an exhausted plan routable.

Refs caigee-cmd#229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant