合并 internal → main: 退款/提现/激活/CI 全面优化 #4
@@ -575,6 +575,7 @@ type (
|
|||||||
Traffic int64 `json:"traffic"`
|
Traffic int64 `json:"traffic"`
|
||||||
Download int64 `json:"download"`
|
Download int64 `json:"download"`
|
||||||
Upload int64 `json:"upload"`
|
Upload int64 `json:"upload"`
|
||||||
|
TrafficLimit []TrafficLimit `json:"user_traffic_limit"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Status uint8 `json:"status"`
|
Status uint8 `json:"status"`
|
||||||
EntitlementSource string `json:"entitlement_source"`
|
EntitlementSource string `json:"entitlement_source"`
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/model/group"
|
"github.com/perfect-panel/server/internal/model/group"
|
||||||
|
"github.com/perfect-panel/server/internal/model/user"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/logger"
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
@@ -61,12 +63,20 @@ func (l *GetUserSubscribeLogic) GetUserSubscribe(req *types.GetUserSubscribeList
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range data {
|
for _, item := range data {
|
||||||
var sub types.UserSubscribe
|
sub := buildUserSubscribeListItem(item, groupNames[item.NodeGroupId])
|
||||||
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)
|
resp.List = append(resp.List, sub)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildUserSubscribeListItem(item *user.SubscribeDetails, groupName string) types.UserSubscribe {
|
||||||
|
var sub types.UserSubscribe
|
||||||
|
tool.DeepCopy(&sub, item)
|
||||||
|
sub.Short, _ = tool.FixedUniqueString(item.Token, 8, "")
|
||||||
|
sub.NodeGroupId = item.NodeGroupId
|
||||||
|
sub.NodeGroupName = groupName
|
||||||
|
if item.TrafficLimit != nil && *item.TrafficLimit != "" {
|
||||||
|
_ = json.Unmarshal([]byte(*item.TrafficLimit), &sub.TrafficLimit)
|
||||||
|
}
|
||||||
|
return sub
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
modeluser "github.com/perfect-panel/server/internal/model/user"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBuildUserSubscribeListItem(t *testing.T) {
|
||||||
|
trafficLimitJSON := `[{"stat_type":"day","stat_value":1,"traffic_usage":10,"speed_limit":5}]`
|
||||||
|
now := time.Unix(1718000000, 0)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
item *modeluser.SubscribeDetails
|
||||||
|
wantTrafficLimit []types.TrafficLimit
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "non-empty user traffic limit",
|
||||||
|
item: &modeluser.SubscribeDetails{
|
||||||
|
Id: 1,
|
||||||
|
UserId: 2,
|
||||||
|
NodeGroupId: 3,
|
||||||
|
Token: "token-12345678",
|
||||||
|
TrafficLimit: &trafficLimitJSON,
|
||||||
|
StartTime: now,
|
||||||
|
ExpireTime: now,
|
||||||
|
},
|
||||||
|
wantTrafficLimit: []types.TrafficLimit{
|
||||||
|
{
|
||||||
|
StatType: "day",
|
||||||
|
StatValue: 1,
|
||||||
|
TrafficUsage: 10,
|
||||||
|
SpeedLimit: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty user traffic limit",
|
||||||
|
item: &modeluser.SubscribeDetails{
|
||||||
|
Id: 4,
|
||||||
|
UserId: 5,
|
||||||
|
NodeGroupId: 6,
|
||||||
|
Token: "token-empty",
|
||||||
|
StartTime: now,
|
||||||
|
ExpireTime: now,
|
||||||
|
},
|
||||||
|
wantTrafficLimit: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
got := buildUserSubscribeListItem(tc.item, "group-a")
|
||||||
|
if got.NodeGroupName != "group-a" {
|
||||||
|
t.Fatalf("NodeGroupName = %q, want %q", got.NodeGroupName, "group-a")
|
||||||
|
}
|
||||||
|
if len(got.Short) != 8 {
|
||||||
|
t.Fatalf("Short length = %d, want 8", len(got.Short))
|
||||||
|
}
|
||||||
|
if len(got.TrafficLimit) != len(tc.wantTrafficLimit) {
|
||||||
|
t.Fatalf("TrafficLimit length = %d, want %d", len(got.TrafficLimit), len(tc.wantTrafficLimit))
|
||||||
|
}
|
||||||
|
for i := range tc.wantTrafficLimit {
|
||||||
|
if got.TrafficLimit[i] != tc.wantTrafficLimit[i] {
|
||||||
|
t.Fatalf("TrafficLimit[%d] = %+v, want %+v", i, got.TrafficLimit[i], tc.wantTrafficLimit[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3694,6 +3694,7 @@ type UserSubscribe struct {
|
|||||||
Traffic int64 `json:"traffic"`
|
Traffic int64 `json:"traffic"`
|
||||||
Download int64 `json:"download"`
|
Download int64 `json:"download"`
|
||||||
Upload int64 `json:"upload"`
|
Upload int64 `json:"upload"`
|
||||||
|
TrafficLimit []TrafficLimit `json:"user_traffic_limit"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Status uint8 `json:"status"`
|
Status uint8 `json:"status"`
|
||||||
EntitlementSource string `json:"entitlement_source"`
|
EntitlementSource string `json:"entitlement_source"`
|
||||||
|
|||||||
Reference in New Issue
Block a user