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:
@@ -32,6 +32,7 @@ const (
|
||||
OrderFailed = "failed"
|
||||
OrderExpired = "expired"
|
||||
OrderRefunded = "refunded"
|
||||
OrderDisputed = "disputed" // 渠道已付但金额与订单不符:不入账、挂起待人工核对(终态,不再重扫)
|
||||
)
|
||||
|
||||
// 渠道名。P5.1 只有 redeem;wechat 在 P5.2 挂上。
|
||||
@@ -220,6 +221,21 @@ func (p *Postgres) GetOrder(ctx context.Context, id string) (*PaymentOrder, erro
|
||||
return &o, nil
|
||||
}
|
||||
|
||||
// MarkOrderDisputed 把一张 pending 订单 CAS 置为 disputed(渠道已付但金额不符)。
|
||||
// 返回 changed:仅首次转移为 true,供调用方决定是否只写一次审计。CAS 保证并发/重复回调只挂起一次。
|
||||
// disputed 是终态:补偿定时器只扫 pending,从此不再重复查它、不再刷屏。
|
||||
func (p *Postgres) MarkOrderDisputed(ctx context.Context, orderID string) (bool, error) {
|
||||
if p.db == nil {
|
||||
return false, errStoreDisabled
|
||||
}
|
||||
res := p.db.WithContext(WithoutTenant(ctx)).Model(&PaymentOrder{}).
|
||||
Where("id = ? AND status = ?", orderID, OrderPending).Update("status", OrderDisputed)
|
||||
if res.Error != nil {
|
||||
return false, res.Error
|
||||
}
|
||||
return res.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
// MarkOrderPaid 渠道确认已支付后的入账:一个事务里「订单 CAS(pending→paid) → 分录 → 物化余额」。
|
||||
// 返回 changed=false 表示这单已被处理过(回调重复推送/回调与主动查单赛跑),幂等直接成功。
|
||||
// 双闸:CAS 是主闸;credit_ledger (kind,ref=订单号) 唯一索引兜底。
|
||||
|
||||
Reference in New Issue
Block a user