Compare commits
No commits in common. "a9205cc3fc884789fb899e22fc7cc8dd7ece60f2" and "3b4e88296524081d6d00243a89ef90c107df4e34" have entirely different histories.
a9205cc3fc
...
3b4e882965
@ -3,7 +3,6 @@ package user
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/group"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
@ -37,22 +36,12 @@ func (l *GetUserSubscribeByIdLogic) GetUserSubscribeById(req *types.GetUserSubsc
|
||||
var subscribeDetails types.UserSubscribeDetail
|
||||
tool.DeepCopy(&subscribeDetails, sub)
|
||||
|
||||
// 填充分组名
|
||||
if sub.NodeGroupId > 0 {
|
||||
var ng group.NodeGroup
|
||||
if err := l.svcCtx.DB.WithContext(l.ctx).First(&ng, sub.NodeGroupId).Error; err == nil {
|
||||
subscribeDetails.NodeGroupName = ng.Name
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate speed limit status
|
||||
if sub.Subscribe != nil && sub.Status == 1 {
|
||||
result := speedlimit.Calculate(l.ctx, l.svcCtx.DB, sub.UserId, sub.Id, sub.Subscribe.SpeedLimit, sub.Subscribe.TrafficLimit)
|
||||
subscribeDetails.EffectiveSpeed = result.EffectiveSpeed
|
||||
subscribeDetails.IsThrottled = result.IsThrottled
|
||||
subscribeDetails.ThrottleRule = result.ThrottleRule
|
||||
subscribeDetails.ThrottleStart = result.ThrottleStart
|
||||
subscribeDetails.ThrottleEnd = result.ThrottleEnd
|
||||
}
|
||||
|
||||
return &subscribeDetails, nil
|
||||
|
||||
@ -3,7 +3,6 @@ package user
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/group"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
@ -39,33 +38,10 @@ func (l *GetUserSubscribeLogic) GetUserSubscribe(req *types.GetUserSubscribeList
|
||||
Total: int64(len(data)),
|
||||
}
|
||||
|
||||
// 收集所有 node_group_id,批量查分组名
|
||||
groupIdSet := make(map[int64]struct{})
|
||||
for _, item := range data {
|
||||
if item.NodeGroupId > 0 {
|
||||
groupIdSet[item.NodeGroupId] = struct{}{}
|
||||
}
|
||||
}
|
||||
groupNames := make(map[int64]string)
|
||||
if len(groupIdSet) > 0 {
|
||||
ids := make([]int64, 0, len(groupIdSet))
|
||||
for id := range groupIdSet {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
var groups []group.NodeGroup
|
||||
if err := l.svcCtx.DB.WithContext(l.ctx).Where("id IN ?", ids).Find(&groups).Error; err == nil {
|
||||
for _, g := range groups {
|
||||
groupNames[g.Id] = g.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range data {
|
||||
var sub types.UserSubscribe
|
||||
tool.DeepCopy(&sub, item)
|
||||
sub.Short, _ = tool.FixedUniqueString(item.Token, 8, "")
|
||||
sub.NodeGroupId = item.NodeGroupId
|
||||
sub.NodeGroupName = groupNames[item.NodeGroupId]
|
||||
resp.List = append(resp.List, sub)
|
||||
}
|
||||
return
|
||||
|
||||
@ -59,14 +59,10 @@ func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeLi
|
||||
list[i] = sub
|
||||
}
|
||||
|
||||
// 老版本客户端(无 X-App-Id)去掉每个套餐 discount 的最后一个
|
||||
// 老版本客户端(无 X-App-Id)去掉排序最后一个套餐
|
||||
hasAppId, _ := l.ctx.Value(constant.CtxKeyHasAppId).(bool)
|
||||
if !hasAppId {
|
||||
for i := range list {
|
||||
if len(list[i].Discount) > 0 {
|
||||
list[i].Discount = list[i].Discount[:len(list[i].Discount)-1]
|
||||
}
|
||||
}
|
||||
if !hasAppId && len(list) > 0 {
|
||||
list = list[:len(list)-1]
|
||||
}
|
||||
|
||||
resp.List = list
|
||||
|
||||
@ -3259,8 +3259,6 @@ type UserSubscribe struct {
|
||||
OrderId int64 `json:"order_id"`
|
||||
SubscribeId int64 `json:"subscribe_id"`
|
||||
Subscribe Subscribe `json:"subscribe"`
|
||||
NodeGroupId int64 `json:"node_group_id"`
|
||||
NodeGroupName string `json:"node_group_name"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
ExpireTime int64 `json:"expire_time"`
|
||||
FinishedAt int64 `json:"finished_at"`
|
||||
@ -3287,7 +3285,6 @@ type UserSubscribeDetail struct {
|
||||
SubscribeId int64 `json:"subscribe_id"`
|
||||
Subscribe Subscribe `json:"subscribe"`
|
||||
NodeGroupId int64 `json:"node_group_id"`
|
||||
NodeGroupName string `json:"node_group_name"`
|
||||
GroupLocked bool `json:"group_locked"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
ExpireTime int64 `json:"expire_time"`
|
||||
@ -3300,8 +3297,6 @@ type UserSubscribeDetail struct {
|
||||
EffectiveSpeed int64 `json:"effective_speed"`
|
||||
IsThrottled bool `json:"is_throttled"`
|
||||
ThrottleRule string `json:"throttle_rule,omitempty"`
|
||||
ThrottleStart int64 `json:"throttle_start,omitempty"`
|
||||
ThrottleEnd int64 `json:"throttle_end,omitempty"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
}
|
||||
|
||||
@ -19,13 +19,11 @@ type TrafficLimitRule struct {
|
||||
|
||||
// ThrottleResult contains the computed speed limit status for a user subscription.
|
||||
type ThrottleResult struct {
|
||||
BaseSpeed int64 `json:"base_speed"` // Plan base speed limit (Mbps, 0=unlimited)
|
||||
EffectiveSpeed int64 `json:"effective_speed"` // Current effective speed limit (Mbps)
|
||||
IsThrottled bool `json:"is_throttled"` // Whether the user is currently throttled
|
||||
ThrottleRule string `json:"throttle_rule"` // Description of the matched rule (empty if not throttled)
|
||||
UsedTrafficGB float64 `json:"used_traffic_gb"` // Traffic used in the matched rule's window (GB)
|
||||
ThrottleStart int64 `json:"throttle_start"` // Window start Unix timestamp (seconds), 0 if not throttled
|
||||
ThrottleEnd int64 `json:"throttle_end"` // Window end Unix timestamp (seconds), 0 if not throttled
|
||||
BaseSpeed int64 `json:"base_speed"` // Plan base speed limit (Mbps, 0=unlimited)
|
||||
EffectiveSpeed int64 `json:"effective_speed"` // Current effective speed limit (Mbps)
|
||||
IsThrottled bool `json:"is_throttled"` // Whether the user is currently throttled
|
||||
ThrottleRule string `json:"throttle_rule"` // Description of the matched rule (empty if not throttled)
|
||||
UsedTrafficGB float64 `json:"used_traffic_gb"` // Traffic used in the matched rule's window (GB)
|
||||
}
|
||||
|
||||
// Calculate computes the effective speed limit for a user subscription,
|
||||
@ -91,8 +89,6 @@ func Calculate(ctx context.Context, db *gorm.DB, userId, subscribeId, baseSpeedL
|
||||
result.EffectiveSpeed = rule.SpeedLimit
|
||||
result.IsThrottled = true
|
||||
result.UsedTrafficGB = usedGB
|
||||
result.ThrottleStart = startTime.Unix()
|
||||
result.ThrottleEnd = now.Unix()
|
||||
|
||||
statLabel := "小时"
|
||||
if rule.StatType == "day" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user