From 615b87ef265986b59a0bbf3a6d4f89d5a15b41c6 Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Sun, 28 Dec 2025 17:25:11 -0800 Subject: [PATCH] fix: resolve build errors after merge (types, config, logic) --- cmd/migrate.go | 42 +++++++++++++++++++ internal/config/config.go | 8 ++-- .../subscribe/querySubscribeListLogic.go | 2 +- internal/model/subscribe/subscribe.go | 1 + internal/svc/serviceContext.go | 11 ++--- internal/types/types.go | 7 +++- pkg/conf/default.go | 4 ++ 7 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 cmd/migrate.go diff --git a/cmd/migrate.go b/cmd/migrate.go new file mode 100644 index 0000000..3b6c76a --- /dev/null +++ b/cmd/migrate.go @@ -0,0 +1,42 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/perfect-panel/server/initialize" + "github.com/perfect-panel/server/internal/config" + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/pkg/conf" + "github.com/perfect-panel/server/pkg/logger" + "github.com/spf13/cobra" +) + +func init() { + migrateCmd.Flags().StringVar(&migrateConfigPath, "config", "etc/ppanel.yaml", "ppanel.yaml directory to read from") + rootCmd.AddCommand(migrateCmd) +} + +var ( + migrateConfigPath string +) + +var migrateCmd = &cobra.Command{ + Use: "migrate", + Short: "Run database migrations", + Run: func(cmd *cobra.Command, args []string) { + runMigrate() + }, +} + +func runMigrate() { + var c config.Config + conf.MustLoad(migrateConfigPath, &c) + if err := logger.SetUp(c.Logger); err != nil { + fmt.Println("Logger setup failed:", err.Error()) + os.Exit(1) + } + ctx := svc.NewServiceContext(c) + initialize.Migrate(ctx) + logger.Info("[Migrate] database migration completed") +} diff --git a/internal/config/config.go b/internal/config/config.go index d582fb7..eaadfd5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -200,10 +200,12 @@ type File struct { } type InviteConfig struct { - ForcedInvite bool `yaml:"ForcedInvite" default:"false"` - FirstPurchasePercentage int64 `yaml:"FirstPurchasePercentage" default:"20"` + ForcedInvite bool `yaml:"ForcedInvite" default:"false"` + FirstPurchasePercentage int64 `yaml:"FirstPurchasePercentage" default:"20"` FirstYearlyPurchasePercentage int64 `yaml:"FirstYearlyPurchasePercentage" default:"25"` - NonFirstPurchasePercentage int64 `yaml:"NonFirstPurchasePercentage" default:"10"` + NonFirstPurchasePercentage int64 `yaml:"NonFirstPurchasePercentage" default:"10"` + ReferralPercentage uint8 `yaml:"ReferralPercentage" default:"10"` + OnlyFirstPurchase bool `yaml:"OnlyFirstPurchase" default:"false"` } type Telegram struct { diff --git a/internal/logic/public/subscribe/querySubscribeListLogic.go b/internal/logic/public/subscribe/querySubscribeListLogic.go index 0504e35..f17827a 100644 --- a/internal/logic/public/subscribe/querySubscribeListLogic.go +++ b/internal/logic/public/subscribe/querySubscribeListLogic.go @@ -58,7 +58,7 @@ func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeLi } list[i] = sub // 通过服务组查询关联的节点数量 - servers, err := l.svcCtx.ServerModel.FindServerListByGroupIds(l.ctx, sub.ServerGroup) + servers, err := l.svcCtx.ServerModel.FindServerListByGroupIds(l.ctx, tool.StringToInt64Slice(sub.ServerGroup)) if err != nil { l.Errorw("[QuerySubscribeListLogic] FindServerListByGroupIds error", logger.Field("error", err.Error())) sub.ServerCount = 0 diff --git a/internal/model/subscribe/subscribe.go b/internal/model/subscribe/subscribe.go index a80ea63..1a44121 100644 --- a/internal/model/subscribe/subscribe.go +++ b/internal/model/subscribe/subscribe.go @@ -22,6 +22,7 @@ type Subscribe struct { Quota int64 `gorm:"type:int;not null;default:0;comment:Quota"` Nodes string `gorm:"type:varchar(255);comment:Node Ids"` NodeTags string `gorm:"type:varchar(255);comment:Node Tags"` + ServerGroup string `gorm:"type:varchar(255);comment:Server Group"` Show *bool `gorm:"type:tinyint(1);not null;default:0;comment:Show portal page"` Sell *bool `gorm:"type:tinyint(1);not null;default:0;comment:Sell"` Sort int64 `gorm:"type:int;not null;default:0;comment:Sort"` diff --git a/internal/svc/serviceContext.go b/internal/svc/serviceContext.go index 4f6bc3a..7ec2704 100644 --- a/internal/svc/serviceContext.go +++ b/internal/svc/serviceContext.go @@ -17,6 +17,7 @@ import ( "github.com/perfect-panel/server/internal/model/order" "github.com/perfect-panel/server/internal/model/payment" "github.com/perfect-panel/server/internal/model/subscribe" + "github.com/perfect-panel/server/internal/model/server" "github.com/perfect-panel/server/internal/model/system" "github.com/perfect-panel/server/internal/model/ticket" "github.com/perfect-panel/server/internal/model/traffic" @@ -48,10 +49,10 @@ type ServiceContext struct { OrderModel order.Model ClientModel client.Model TicketModel ticket.Model - //ServerModel server.Model - SystemModel system.Model - CouponModel coupon.Model - PaymentModel payment.Model + ServerModel server.Model + SystemModel system.Model + CouponModel coupon.Model + PaymentModel payment.Model DocumentModel document.Model SubscribeModel subscribe.Model TrafficLogModel traffic.Model @@ -109,7 +110,7 @@ func NewServiceContext(c config.Config) *ServiceContext { OrderModel: order.NewModel(db, rds), ClientModel: client.NewSubscribeApplicationModel(db), TicketModel: ticket.NewModel(db, rds), - //ServerModel: server.NewModel(db, rds), + ServerModel: server.NewModel(db, rds), SystemModel: system.NewModel(db, rds), CouponModel: coupon.NewModel(db, rds), PaymentModel: payment.NewModel(db, rds), diff --git a/internal/types/types.go b/internal/types/types.go index 565c4ce..918af0b 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -951,8 +951,9 @@ type GetServerUserListResponse struct { type GetStatResponse struct { User int64 `json:"user"` Node int64 `json:"node"` - Country int64 `json:"country"` - Protocol []string `json:"protocol"` + Country int64 `json:"country"` + Protocol []string `json:"protocol"` + OnlineDevice int64 `json:"online_devices"` } type GetSubscribeApplicationListRequest struct { @@ -2060,6 +2061,8 @@ type Subscribe struct { Quota int64 `json:"quota"` Nodes []int64 `json:"nodes"` NodeTags []string `json:"node_tags"` + ServerGroup string `json:"server_group"` + ServerCount int64 `json:"server_count"` Show bool `json:"show"` Sell bool `json:"sell"` Sort int64 `json:"sort"` diff --git a/pkg/conf/default.go b/pkg/conf/default.go index 9c6af19..e1b1760 100644 --- a/pkg/conf/default.go +++ b/pkg/conf/default.go @@ -56,6 +56,10 @@ func parseDefaultValue(kind reflect.Kind, defaultValue string) any { var i uint32 _, _ = fmt.Sscanf(defaultValue, "%d", &i) return i + case reflect.Uint8: + var i uint8 + _, _ = fmt.Sscanf(defaultValue, "%d", &i) + return i default: fmt.Printf("类型 %v 没有处理, 值为: %v \n", kind, defaultValue) panic("unhandled default case")