fix: 修复释放回库存的上游限频误判与不可用强制释放
- 110001/请求过于频繁归为 rate_limited,冷却期直接返回剩余秒数且不再请求上游 - 释放校验区分限频、校验失败与可强制释放:仅 upstream_status=bound 允许强制 - 弹窗对限频/校验失败改为可重试或关闭,不再展示必然失败的强制释放输入 - 提交前重新校验按钮复用 checkSeq,避免重复打开弹窗 - 修正绑定刷新测试夹具的上游时间未按业务时区格式化导致的失败
This commit is contained in:
@@ -324,10 +324,12 @@ func extractRockFulfillID(ref *RockRefreshResponse, baseline time.Time) int64 {
|
||||
// RockReleaseCheckResult 是释放回库存前的上游校验结果。
|
||||
type RockReleaseCheckResult struct {
|
||||
CanRelease bool `json:"can_release"`
|
||||
UpstreamStatus string `json:"upstream_status"` // unbound / bound / redeemed / abnormal / not_found / check_failed
|
||||
UpstreamStatus string `json:"upstream_status"` // unbound / bound / redeemed / abnormal / not_found / check_failed / rate_limited
|
||||
RoleName string `json:"role_name,omitempty"`
|
||||
RoleID string `json:"role_id,omitempty"`
|
||||
Message string `json:"message"`
|
||||
// RetryAfterSeconds 仅在上游限频(110001)时返回,提示前端冷却剩余秒数。
|
||||
RetryAfterSeconds int `json:"retry_after_seconds,omitempty"`
|
||||
}
|
||||
|
||||
// RockReleaseRequiresForceError 表示上游状态不允许直接释放,需要人工强制确认。
|
||||
@@ -375,6 +377,16 @@ func (s *RockService) checkReleaseToken(ctx context.Context, tokenID uint) (*mod
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 全局频控冷却期内不再请求上游,直接返回可重试的限频状态。
|
||||
if remain := rockUpstreamRateLimitRemaining(); remain > 0 {
|
||||
seconds := int((remain + time.Second - 1) / time.Second)
|
||||
return &token, &RockReleaseCheckResult{
|
||||
UpstreamStatus: "rate_limited",
|
||||
Message: fmt.Sprintf("上游限频冷却中,请 %d 秒后重试", seconds),
|
||||
RetryAfterSeconds: seconds,
|
||||
}, nil
|
||||
}
|
||||
|
||||
ref, err := s.client.RefreshToken(ctx, cfg.BearerToken, token.UpstreamTokenID)
|
||||
if err != nil {
|
||||
if isRockTokenNotFoundError(err) {
|
||||
@@ -383,6 +395,19 @@ func (s *RockService) checkReleaseToken(ctx context.Context, tokenID uint) (*mod
|
||||
Message: "上游卡密不存在(可能已失效)",
|
||||
}, nil
|
||||
}
|
||||
// 110001 是上游全局频控,不是 Token 状态问题,单独归为可重试状态。
|
||||
if isRockRateLimitError(err) {
|
||||
markRockUpstreamRateLimited()
|
||||
seconds := int((rockUpstreamRateLimitRemaining() + time.Second - 1) / time.Second)
|
||||
if seconds <= 0 {
|
||||
seconds = int(rockRateLimitCooldown / time.Second)
|
||||
}
|
||||
return &token, &RockReleaseCheckResult{
|
||||
UpstreamStatus: "rate_limited",
|
||||
Message: fmt.Sprintf("上游请求过于频繁(110001),请 %d 秒后重试", seconds),
|
||||
RetryAfterSeconds: seconds,
|
||||
}, nil
|
||||
}
|
||||
return &token, &RockReleaseCheckResult{
|
||||
UpstreamStatus: "check_failed",
|
||||
Message: "确认上游状态失败: " + err.Error(),
|
||||
@@ -456,6 +481,9 @@ func (s *RockService) ReleaseUnboundUsingToken(ctx context.Context, tokenID uint
|
||||
if !check.CanRelease && !force {
|
||||
return &RockReleaseRequiresForceError{Check: *check}
|
||||
}
|
||||
if check.UpstreamStatus == "rate_limited" {
|
||||
return errors.New("上游限频(110001),请稍后重新校验通过后再释放")
|
||||
}
|
||||
switch check.UpstreamStatus {
|
||||
case "redeemed", "abnormal", "not_found", "check_failed":
|
||||
return fmt.Errorf("上游状态为 %s,禁止释放回库存", check.UpstreamStatus)
|
||||
|
||||
Reference in New Issue
Block a user