fix: resolve build errors after merge (types, config, logic)

This commit is contained in:
shanshanzhong 2025-12-28 17:25:11 -08:00
parent d94cbc09b0
commit 615b87ef26
7 changed files with 64 additions and 11 deletions

42
cmd/migrate.go Normal file
View File

@ -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")
}

View File

@ -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 {

View File

@ -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

View File

@ -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"`

View File

@ -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),

View File

@ -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"`

View File

@ -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")