fix(backend): 登录设备配额三修复——过期会话不占坑/同设备重登不叠加/配额跟套餐档位

S003 线上登录锁死根因修复:
- 活跃会话统计排除 refresh 已过期的行(此前过期未清理的会话把配额占满,
  正常用户被锁在门外,需等 cleanup retention 天后才释放)
- 同 shop+user+device_id 重登先吊销旧会话(reason=relogin),重装/重复登录
  不再叠占配额
- effectiveTotalQuota 接线套餐档位:session_policy 运维覆盖 > 有效授权
  max_devices(标准 2/高级 5,floor 2 兜底 trial=1)> 全局默认 5(无有效授权)

test(backend): session_quota_test.go 五用例覆盖三分支 + policy 优先级 + trial 兜底

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-04 13:46:59 +08:00
parent 5b9262a166
commit c9e3664d68
3 changed files with 204 additions and 10 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ type UserSession struct {
// 否则 revoke/cleanup 等任意 Updates 都会把已撤销会话误刷成「刚活跃」。
LastSeenAt time.Time `gorm:"autoCreateTime" json:"last_seen_at"`
RevokedAt *time.Time `gorm:"index" json:"revoked_at,omitempty"`
RevokedReason string `gorm:"size:30" json:"revoked_reason,omitempty"` // kicked|logout|admin|disabled|reuse|pwd_reset
RevokedReason string `gorm:"size:30" json:"revoked_reason,omitempty"` // kicked|logout|admin|disabled|reuse|pwd_reset|relogin
RevokedBy *uint64 `gorm:"column:revoked_by" json:"revoked_by,omitempty"` // 吊销操作人 user_id;系统/自助吊销为 NULL
RefreshExpAt time.Time `json:"refresh_exp_at"`
}