fix(backend): 补齐三处漏洞——暂停租户拦截/金额不符落审计终态/邀请码列表滤失效

P0 暂停租户是空开关:admin 能设 suspended,但 preflight 只查预算+余额、不看
租户 status → 暂停后照样能提交烧积分。加 TenantSuspended 校验(活跃租户 + 分叉时
的计费租户都拦),403 拒绝。

P1 金额不符只刷日志:回调/查单判了不符却没落审计、订单永远卡 pending 被补偿定时器
每轮重扫刷屏。加 disputed 终态 + MarkOrderDisputed(CAS 只挂一次) + 审计(首次写一次);
disputed 不在 pending 扫描内,停止无限重扫。admin /orders?status=disputed 可查。

P1 邀请码列表混入失效码:ListInvites 只按 status=active 过滤,过期/满员的码仍显示为
有效、误导邀请人。有效列表加 expires_at>now 且 used<max 过滤(RedeemInvite 本就会拒,
这里修的是展示一致性)。

三处均带 store 单测(TenantSuspended/MarkOrderDisputed CAS/ListInvites 过滤)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-21 14:20:34 +08:00
parent bd829cfecb
commit ce7cca657e
6 changed files with 151 additions and 3 deletions
+4 -1
View File
@@ -100,7 +100,10 @@ func (p *Postgres) ListInvites(ctx context.Context, tenantID string, onlyActive
}
q := p.db.WithContext(ctx).Where("tenant_id = ?", tenantID)
if onlyActive {
q = q.Where("status = ?", InviteActive)
// 「有效」= 未撤销 + 未过期 + 未满员。只看 status 会把过期/满员的码当有效展示、误导邀请人。
q = q.Where("status = ?", InviteActive).
Where("expires_at > ?", time.Now()).
Where("max_uses = 0 OR used_count < max_uses")
}
var out []TenantInvite
q.Order("created_at desc").Limit(100).Find(&out)