Skip to content
Open
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
6dd933c
预付款退款退还已使用额度
qqjyy Apr 20, 2026
f32dc37
Merge pull request #1 from lynxtoncloud/stc
cts926 Apr 20, 2026
b796bdb
暂时用回监听机制
qqjyy Apr 20, 2026
e7dea72
Merge pull request #2 from lynxtoncloud/stc
cts926 Apr 20, 2026
8387c46
改变消费趋势时间范围
qqjyy Apr 20, 2026
1217fec
增加设置模型显示名称和模型输出类型
qqjyy Apr 21, 2026
cc68b83
增加prcing结构字段Modalities和DisplayName
qqjyy Apr 21, 2026
dc38021
Merge pull request #3 from lynxtoncloud/stc
cts926 Apr 21, 2026
c38d070
将企业折扣加入计费过程
qqjyy Apr 21, 2026
f619448
商业折扣应用于扣款
qqjyy Apr 22, 2026
babfc6d
更换商业折扣在计费流程的使用
qqjyy Apr 22, 2026
b83a5e8
增加应用折扣日志
qqjyy Apr 22, 2026
06a52d2
增加日志
qqjyy Apr 22, 2026
4456da0
增加日志
qqjyy Apr 23, 2026
6aa098f
更改getUserOrgDiscount使用表名
qqjyy Apr 23, 2026
79799c8
预扣费应用企业折扣,同时文本图片音频模型差额结算也应用企业折扣
qqjyy Apr 23, 2026
4049e3c
Merge remote-tracking branch 'origin/stc' into stc
Apr 23, 2026
c4a7c3c
fmj-4/23-登录不允许不同设备同时登录,7天登录有效期。聊天界面和模型界面适配手机端
Apr 23, 2026
b7303d7
Merge remote-tracking branch 'origin/stc' into stc
Apr 23, 2026
3a4d4c5
增加预扣款时应用企业折扣的具体日志
qqjyy Apr 23, 2026
1054b6d
取消文本音频模型应用企业折扣增加日志
qqjyy Apr 23, 2026
9bca53c
Merge remote-tracking branch 'origin/stc' into fmj
Apr 23, 2026
8d3334d
Merge pull request #4 from lynxtoncloud/fmj
Azilier7 Apr 23, 2026
acf6bb5
添加对ModelDisplayName和ModelModalities的初始化和更新处理
qqjyy Apr 23, 2026
1dd5d23
Merge pull request #5 from lynxtoncloud/stc
cts926 Apr 23, 2026
456f8a2
增加当OriginModelName为空时尝试从其他字段获取
qqjyy Apr 23, 2026
1206d02
增加当OriginModelName为空时尝试从其他字段获取
qqjyy Apr 23, 2026
cf19679
Merge remote-tracking branch 'origin/stc' into stc
qqjyy Apr 23, 2026
468bf12
解决视频模型调用消耗日志显示有误
qqjyy Apr 23, 2026
c1ab061
解决视频模型调用应用企业折扣有误
qqjyy Apr 23, 2026
b19c58a
解决重复应用企业折扣
qqjyy Apr 24, 2026
50b2f37
解决重复应用企业折扣
qqjyy Apr 24, 2026
4bb54d6
解决视频模型应用企业折扣后补扣
qqjyy Apr 24, 2026
87f3978
解决视频模型应用企业折扣后补扣
qqjyy Apr 24, 2026
abbce9a
Merge pull request #6 from lynxtoncloud/stc
cts926 Apr 24, 2026
88cfdd0
增加调用NormalizeRecordedQuota日志显示
qqjyy Apr 24, 2026
4ffbe50
测试NormalizeRecordedQuota
qqjyy Apr 24, 2026
c5328df
修改discountRate为orgDiscountRate
qqjyy Apr 24, 2026
ff877a0
Merge pull request #7 from lynxtoncloud/stc
cts926 Apr 24, 2026
baeb385
限制令牌限额不能小于零
qqjyy Apr 28, 2026
6b18e41
Merge pull request #8 from lynxtoncloud/stc
cts926 Apr 28, 2026
2b57c75
修改管理日志显示货币符号,小数点后位数
qqjyy Apr 28, 2026
150a13d
增加model_img字段显示和敏感词报错
qqjyy Apr 29, 2026
9a6bad0
Merge pull request #9 from lynxtoncloud/stc
cts926 Apr 29, 2026
0e23eb4
将有企业的成员的充值面板撤去,新增企业充值面板,只有企业拥有者有权进行企业充值,企业普通成员无权访问企业充值面板
qqjyy Apr 29, 2026
33168dc
日志页面耗时字段改为余额字段
qqjyy Apr 29, 2026
c34eecf
兑换码名字后加序号
qqjyy Apr 29, 2026
0f10fdf
Merge pull request #10 from lynxtoncloud/stc
cts926 Apr 29, 2026
e0d9832
限流中间件达到限流时返回具体"请求过于频繁,请稍后再试",限流条件改为同一IP一分钟20次
qqjyy Apr 30, 2026
e046cd5
修复:豆包图生视频请求的 content 项补齐 role,避免图片输入报 role 缺失错误
Yxin-art May 1, 2026
56c731c
修复:豆包视频任务仅对 image_url 设置 role,文本 content 禁止携带 role
Yxin-art May 2, 2026
67a54dc
fix(doubao): 视频任务图片统一为 reference_image
Yxin-art May 2, 2026
e84c31d
fix(doubao): 区分 r2v 与 i2v,修复 seedance 1.0 Pro 的 task_type
Yxin-art May 2, 2026
5e073fb
fix(doubao): 1.5 Pro 与 1.0 Pro 一样不走 r2v
Yxin-art May 2, 2026
fe0ea76
Merge remote-tracking branch 'origin/main' into stc
qqjyy May 6, 2026
b796d72
修改日志显示的余额
qqjyy May 6, 2026
02ebc73
修改退还用户已用额度
qqjyy May 6, 2026
ee9245c
任务提交失败时,无需退还用户已用额度
qqjyy May 6, 2026
36d28d3
异步任务资金调整改为强制立即写库
qqjyy May 6, 2026
ea1bd95
异步任务资金调整改回批量写库策略,日志快照按“数据库余额 + 未落库变更”记录。
qqjyy May 6, 2026
957bfad
Merge pull request #11 from lynxtoncloud/stc
cts926 May 6, 2026
5c82499
fix(doubao):视频任务图片支持裸 base64 并保留 metadata 中的 image_url role
Yxin-art May 7, 2026
8da1cc1
Merge branch 'dev2.0'
Yxin-art May 7, 2026
b156871
stc-5/7-21.12修复空返回仍然算任务成功
qqjyy May 7, 2026
fabdfda
Merge pull request #12 from lynxtoncloud/stc
cts926 May 7, 2026
4211409
stc-5/7-22.01解决文本等模型二次应用企业折扣
qqjyy May 7, 2026
05aa22b
Merge pull request #13 from lynxtoncloud/stc
cts926 May 7, 2026
1d46970
stc-5/8-15:53为用户使用量聚合表添加end_at字段
qqjyy May 8, 2026
0ba4d37
Merge pull request #14 from lynxtoncloud/stc
cts926 May 8, 2026
5d8cf8c
stc-5/12-10:41 feat(gateway): 新增 /v1/responses 请求转 chat completions 上…
qqjyy May 12, 2026
884c78f
stc-5/12-10:51 feat(gateway): 新增 /v1/responses 请求转 chat completions 上…
qqjyy May 12, 2026
b22cc9c
stc-5/12-15:27 feat(usage): 新增个人与企业分钟级模型用量聚合表
qqjyy May 12, 2026
057e862
Merge pull request #15 from lynxtoncloud/stc
cts926 May 12, 2026
aca670f
stc-5/13-10:04 fix(auth): 使用 Redis 存储验证码避免多实例校验失效
qqjyy May 13, 2026
ecc7fc8
stc-5/13-10:35 feat(auth): 新增单设备登录配置开关
qqjyy May 13, 2026
635a77c
feat(ops): 计费快照写入 Gin 上下文供上游运维日志消费
Yxin-art May 13, 2026
5e49edd
stc-5/13-15:34 fix(channel): 保存渠道时规范化 Base URL
qqjyy May 13, 2026
05fe523
Merge pull request #16 from lynxtoncloud/stc
cts926 May 13, 2026
a6e0806
stc-5/13-18:07 fix(channel): 修复渠道多模型时除首个外报模型ID错误
qqjyy May 13, 2026
c733683
Merge pull request #17 from lynxtoncloud/stc
cts926 May 13, 2026
eb9d639
·
qqjyy May 14, 2026
90ff23e
stc-5/14-14:39 fix(token):令牌额度不足时,切换列表展示下一位可用令牌使用
qqjyy May 14, 2026
2e3d921
Merge pull request #18 from lynxtoncloud/stc
cts926 May 14, 2026
c36449a
feat(logging): add GinLogWriterFactory hook for structured gin log ro…
Yxin-art May 14, 2026
5ce5a8a
stc-5/15-11:46 fix(logquota): 使用兑换码充值后,日志表记录的数据加上充值的具体金额
qqjyy May 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion service/task_billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ func RefundTaskQuota(ctx context.Context, task *model.Task, reason string) {
// 2. 退还令牌额度
taskAdjustTokenQuota(ctx, task, -quota)

// 3. 记录日志
//3. 更新用户和渠道的使用额度
model.UpdateUserUsedQuotaAndRequestCount(task.UserId, -quota)
model.UpdateChannelUsedQuota(task.ChannelId, -quota)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 1. Show the implementation of UpdateUserUsedQuotaAndRequestCount and UpdateChannelUsedQuota.
ast-grep --pattern $'func UpdateUserUsedQuotaAndRequestCount($$$) {
  $$$
}'

ast-grep --pattern $'func UpdateChannelUsedQuota($$$) {
  $$$
}'

# 2. Look for any sibling helpers that only touch used_quota (no request count).
rg -nP --type=go '\bfunc\s+(Update|Decrease|Increase)\w*(UsedQuota|RequestCount)\w*\s*\('

# 3. See how existing refund flows in the repo adjust these counters (if at all).
rg -nP --type=go -C3 'LogTypeRefund' -g '!service/task_billing.go'

Repository: QuantumNous/new-api

Length of output: 4392


🏁 Script executed:

# Inspect the underlying updateUserUsedQuotaAndRequestCount function implementation
cat -n model/user.go | sed -n '960,1050p'

Repository: QuantumNous/new-api

Length of output: 3164


🏁 Script executed:

# Check for alternative helpers that update quota without request count
rg -nP --type=go '\bfunc\s+(Update|Decrease)\w*User\w*(Quota|UsedQuota)\w*\s*\(' model/

Repository: QuantumNous/new-api

Length of output: 224


🏁 Script executed:

# Look at how RefundTaskQuota and RecalculateTaskQuota are called/tested
cat -n service/task_billing.go | sed -n '160,180p'
cat -n service/task_billing.go | sed -n '225,245p'

Repository: QuantumNous/new-api

Length of output: 1700


🏁 Script executed:

# Check if there are test cases that verify request_count behavior during refund
grep -n "request_count\|RequestCount" service/task_billing_test.go | head -20

Repository: QuantumNous/new-api

Length of output: 45


Refund paths incorrectly decrement user request_count.

model.UpdateUserUsedQuotaAndRequestCount updates both used_quota and request_count by 1, regardless of whether the quota parameter is positive or negative. Passing -quota on the refund path (lines 168 and 233) will decrement request_count by 1.

Semantically, a failed/refunded task should roll back quota usage but NOT decrement request_count — the user made a request regardless of success. Over time, this causes request_count to drift and violates the expectation that it is monotonically increasing.

The codebase already has updateUserUsedQuota() (model/user.go:981) which updates only used_quota and leaves request_count unchanged. Use this helper (or a public wrapper) for refunds instead:

  • Line 168 in RefundTaskQuota: Replace UpdateUserUsedQuotaAndRequestCount(task.UserId, -quota) with a quota-only update.
  • Line 233 in RecalculateTaskQuota: Replace UpdateUserUsedQuotaAndRequestCount(task.UserId, -quotaDelta) with a quota-only update.

Apply the same fix to channel updates if UpdateChannelUsedQuota exhibits the same pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@service/task_billing.go` around lines 167 - 169, In RefundTaskQuota and
RecalculateTaskQuota replace calls that pass a negative quota into
UpdateUserUsedQuotaAndRequestCount (e.g.,
UpdateUserUsedQuotaAndRequestCount(task.UserId, -quota) and
UpdateUserUsedQuotaAndRequestCount(task.UserId, -quotaDelta)) with the
quota-only helper updateUserUsedQuota (or the public wrapper
updateUserUsedQuota() from model/user.go) so only used_quota is decremented and
request_count remains unchanged; also audit UpdateChannelUsedQuota for the same
request_count side-effect and, if it similarly mutates request_count, switch to
a channel-only quota update helper for channel updates (e.g., a dedicated
UpdateChannelUsedQuotaOnly) to ensure refunds do not decrement request_count.


// 4. 记录日志
other := taskBillingOther(task)
other["task_id"] = task.TaskID
other["reason"] = reason
Expand Down Expand Up @@ -226,6 +230,8 @@ func RecalculateTaskQuota(ctx context.Context, task *model.Task, actualQuota int
} else {
logType = model.LogTypeRefund
logQuota = -quotaDelta
model.UpdateUserUsedQuotaAndRequestCount(task.UserId, -quotaDelta)
model.UpdateChannelUsedQuota(task.ChannelId, -quotaDelta)
}
other := taskBillingOther(task)
other["task_id"] = task.TaskID
Expand Down
Loading