Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
624d9fdd
Unverified
Commit
624d9fdd
authored
Jan 26, 2026
by
Wesley Liddick
Committed by
GitHub
Jan 26, 2026
Browse files
Merge pull request #391 from geminiwen/main
fix(subscription): 修复订阅调整逻辑,已过期订阅从当前时间计算
parents
47fbe433
9cdb0568
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/subscription_service.go
View file @
624d9fdd
...
@@ -324,14 +324,29 @@ func (s *SubscriptionService) ExtendSubscription(ctx context.Context, subscripti
...
@@ -324,14 +324,29 @@ func (s *SubscriptionService) ExtendSubscription(ctx context.Context, subscripti
days
=
-
MaxValidityDays
days
=
-
MaxValidityDays
}
}
now
:=
time
.
Now
()
isExpired
:=
!
sub
.
ExpiresAt
.
After
(
now
)
// 如果订阅已过期,不允许负向调整
if
isExpired
&&
days
<
0
{
return
nil
,
infraerrors
.
BadRequest
(
"CANNOT_SHORTEN_EXPIRED"
,
"cannot shorten an expired subscription"
)
}
// 计算新的过期时间
// 计算新的过期时间
newExpiresAt
:=
sub
.
ExpiresAt
.
AddDate
(
0
,
0
,
days
)
var
newExpiresAt
time
.
Time
if
isExpired
{
// 已过期:从当前时间开始增加天数
newExpiresAt
=
now
.
AddDate
(
0
,
0
,
days
)
}
else
{
// 未过期:从原过期时间增加/减少天数
newExpiresAt
=
sub
.
ExpiresAt
.
AddDate
(
0
,
0
,
days
)
}
if
newExpiresAt
.
After
(
MaxExpiresAt
)
{
if
newExpiresAt
.
After
(
MaxExpiresAt
)
{
newExpiresAt
=
MaxExpiresAt
newExpiresAt
=
MaxExpiresAt
}
}
// 检查新的过期时间必须大于当前时间
// 检查新的过期时间必须大于当前时间
now
:=
time
.
Now
()
if
!
newExpiresAt
.
After
(
now
)
{
if
!
newExpiresAt
.
After
(
now
)
{
return
nil
,
ErrAdjustWouldExpire
return
nil
,
ErrAdjustWouldExpire
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment