This commit is contained in:
@@ -43,7 +43,7 @@ func (m *customAnnouncementModel) GetAnnouncementListByPage(ctx context.Context,
|
||||
if filter.Search != "" {
|
||||
conn = conn.Where("`title` LIKE ? OR `content` LIKE ?", "%"+filter.Search+"%", "%"+filter.Search+"%")
|
||||
}
|
||||
return conn.Count(&total).Offset((page - 1) * size).Limit(size).Find(v).Error
|
||||
return conn.Count(&total).Offset((page - 1) * size).Limit(size).Find(&list).Error
|
||||
})
|
||||
return total, list, err
|
||||
}
|
||||
|
||||
+18
-17
@@ -33,23 +33,24 @@ const (
|
||||
TypeTrafficStat Type = 42 // Daily traffic statistics log
|
||||
)
|
||||
const (
|
||||
ResetSubscribeTypeAuto uint16 = 231 // Auto reset
|
||||
ResetSubscribeTypeAdvance uint16 = 232 // Advance reset
|
||||
ResetSubscribeTypePaid uint16 = 233 // Paid reset
|
||||
ResetSubscribeTypeQuota uint16 = 234 // Quota reset
|
||||
BalanceTypeRecharge uint16 = 321 // Recharge
|
||||
BalanceTypeWithdraw uint16 = 322 // Withdraw
|
||||
BalanceTypePayment uint16 = 323 // Payment
|
||||
BalanceTypeRefund uint16 = 324 // Refund
|
||||
BalanceTypeAdjust uint16 = 326 // Admin Adjust
|
||||
BalanceTypeReward uint16 = 325 // Reward
|
||||
CommissionTypePurchase uint16 = 331 // Purchase
|
||||
CommissionTypeRenewal uint16 = 332 // Renewal
|
||||
CommissionTypeRefund uint16 = 333 // Refund
|
||||
commissionTypeWithdraw uint16 = 334 // withdraw
|
||||
CommissionTypeAdjust uint16 = 335 // Admin Adjust
|
||||
GiftTypeIncrease uint16 = 341 // Increase
|
||||
GiftTypeReduce uint16 = 342 // Reduce
|
||||
ResetSubscribeTypeAuto uint16 = 231 // Auto reset
|
||||
ResetSubscribeTypeAdvance uint16 = 232 // Advance reset
|
||||
ResetSubscribeTypePaid uint16 = 233 // Paid reset
|
||||
ResetSubscribeTypeQuota uint16 = 234 // Quota reset
|
||||
BalanceTypeRecharge uint16 = 321 // Recharge
|
||||
BalanceTypeWithdraw uint16 = 322 // Withdraw
|
||||
BalanceTypePayment uint16 = 323 // Payment
|
||||
BalanceTypeRefund uint16 = 324 // Refund
|
||||
BalanceTypeAdjust uint16 = 326 // Admin Adjust
|
||||
BalanceTypeReward uint16 = 325 // Reward
|
||||
CommissionTypePurchase uint16 = 331 // Purchase
|
||||
CommissionTypeRenewal uint16 = 332 // Renewal
|
||||
CommissionTypeRefund uint16 = 333 // Refund
|
||||
CommissionTypeWithdraw uint16 = 334 // withdraw
|
||||
CommissionTypeAdjust uint16 = 335 // Admin Adjust
|
||||
CommissionTypeConvertBalance uint16 = 336 // Convert to Balance
|
||||
GiftTypeIncrease uint16 = 341 // Increase
|
||||
GiftTypeReduce uint16 = 342 // Reduce
|
||||
)
|
||||
|
||||
// Uint8 converts Type to uint8.
|
||||
|
||||
@@ -23,6 +23,7 @@ type (
|
||||
UpdateServer(ctx context.Context, data *Server, tx ...*gorm.DB) error
|
||||
DeleteServer(ctx context.Context, id int64, tx ...*gorm.DB) error
|
||||
Transaction(ctx context.Context, fn func(db *gorm.DB) error) error
|
||||
QueryServerList(ctx context.Context, ids []int64) (servers []*Server, err error)
|
||||
}
|
||||
|
||||
NodeModel interface {
|
||||
|
||||
@@ -3,8 +3,10 @@ package node
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/perfect-panel/server/pkg/tool"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type customServerLogicModel interface {
|
||||
@@ -63,6 +65,12 @@ func (m *customServerModel) FilterServerList(ctx context.Context, params *Filter
|
||||
return total, servers, err
|
||||
}
|
||||
|
||||
func (m *customServerModel) QueryServerList(ctx context.Context, ids []int64) (servers []*Server, err error) {
|
||||
query := m.WithContext(ctx).Model(&Server{})
|
||||
err = query.Where("id IN (?)", ids).Find(&servers).Error
|
||||
return
|
||||
}
|
||||
|
||||
// FilterNodeList Filter Node List
|
||||
func (m *customServerModel) FilterNodeList(ctx context.Context, params *FilterNodeParams) (int64, []*Node, error) {
|
||||
var nodes []*Node
|
||||
@@ -85,10 +93,7 @@ func (m *customServerModel) FilterNodeList(ctx context.Context, params *FilterNo
|
||||
query = query.Where("server_id IN ?", params.ServerId)
|
||||
}
|
||||
if len(params.Tag) > 0 {
|
||||
query = query.Where("1 = 0")
|
||||
for _, tag := range params.Tag {
|
||||
query = query.Or("FIND_IN_SET(?,tags)", tag)
|
||||
}
|
||||
query = query.Scopes(InSet("tags", params.Tag))
|
||||
}
|
||||
if params.Protocol != "" {
|
||||
query = query.Where("protocol = ?", params.Protocol)
|
||||
@@ -165,3 +170,22 @@ func (m *customServerModel) ClearServerCache(ctx context.Context, serverId int64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InSet 支持多值 OR 查询
|
||||
func InSet(field string, values []string) func(db *gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if len(values) == 0 {
|
||||
return db
|
||||
}
|
||||
|
||||
conds := make([]string, len(values))
|
||||
args := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
conds[i] = "FIND_IN_SET(?, " + field + ")"
|
||||
args[i] = v
|
||||
}
|
||||
|
||||
// 用括号包裹 OR 条件,保证外层 AND 不受影响
|
||||
return db.Where("("+strings.Join(conds, " OR ")+")", args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,9 +85,10 @@ func (l *AlipayF2FConfig) Unmarshal(data []byte) error {
|
||||
}
|
||||
|
||||
type EPayConfig struct {
|
||||
Pid string `json:"pid"`
|
||||
Url string `json:"url"`
|
||||
Key string `json:"key"`
|
||||
Pid string `json:"pid"`
|
||||
Url string `json:"url"`
|
||||
Key string `json:"key"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
func (l *EPayConfig) Marshal() ([]byte, error) {
|
||||
@@ -109,6 +110,7 @@ type CryptoSaaSConfig struct {
|
||||
Endpoint string `json:"endpoint"`
|
||||
AccountID string `json:"account_id"`
|
||||
SecretKey string `json:"secret_key"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
func (l *CryptoSaaSConfig) Marshal() ([]byte, error) {
|
||||
|
||||
@@ -22,8 +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 Ids"`
|
||||
Server string `gorm:"type:varchar(255);comment:Server Ids"`
|
||||
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"`
|
||||
|
||||
@@ -46,6 +46,16 @@ func (m *customUserModel) QueryDevicePageList(ctx context.Context, userId, subsc
|
||||
return list, total, err
|
||||
}
|
||||
|
||||
// QueryDeviceList returns a list of records that meet the conditions.
|
||||
func (m *customUserModel) QueryDeviceList(ctx context.Context, userId int64) ([]*Device, int64, error) {
|
||||
var list []*Device
|
||||
var total int64
|
||||
err := m.QueryNoCacheCtx(ctx, &list, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&Device{}).Where("`user_id` = ?", userId).Count(&total).Find(&list).Error
|
||||
})
|
||||
return list, total, err
|
||||
}
|
||||
|
||||
func (m *customUserModel) UpdateDevice(ctx context.Context, data *Device, tx ...*gorm.DB) error {
|
||||
old, err := m.FindOneDevice(ctx, data.Id)
|
||||
if err != nil {
|
||||
@@ -76,3 +86,18 @@ func (m *customUserModel) DeleteDevice(ctx context.Context, id int64, tx ...*gor
|
||||
}, data.GetCacheKeys()...)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *customUserModel) InsertDevice(ctx context.Context, data *Device, tx ...*gorm.DB) error {
|
||||
defer func() {
|
||||
if clearErr := m.ClearDeviceCache(ctx, data); clearErr != nil {
|
||||
// log cache clear error
|
||||
}
|
||||
}()
|
||||
|
||||
return m.ExecNoCacheCtx(ctx, func(conn *gorm.DB) error {
|
||||
if len(tx) > 0 {
|
||||
conn = tx[0]
|
||||
}
|
||||
return conn.Create(data).Error
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ type SubscribeDetails struct {
|
||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired; 4: Cancelled"`
|
||||
Note string `gorm:"type:varchar(500);default:'';comment:User note for subscription"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
}
|
||||
@@ -95,10 +96,12 @@ type customUserLogicModel interface {
|
||||
FindUserAuthMethodByPlatform(ctx context.Context, userId int64, platform string) (*AuthMethods, error)
|
||||
FindOneByEmail(ctx context.Context, email string) (*User, error)
|
||||
FindOneDevice(ctx context.Context, id int64) (*Device, error)
|
||||
QueryDeviceList(ctx context.Context, userid int64) ([]*Device, int64, error)
|
||||
QueryDevicePageList(ctx context.Context, userid, subscribeId int64, page, size int) ([]*Device, int64, error)
|
||||
UpdateDevice(ctx context.Context, data *Device, tx ...*gorm.DB) error
|
||||
FindOneDeviceByIdentifier(ctx context.Context, id string) (*Device, error)
|
||||
DeleteDevice(ctx context.Context, id int64, tx ...*gorm.DB) error
|
||||
InsertDevice(ctx context.Context, data *Device, tx ...*gorm.DB) error
|
||||
|
||||
ClearSubscribeCache(ctx context.Context, data ...*Subscribe) error
|
||||
ClearUserCache(ctx context.Context, data ...*User) error
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
type User struct {
|
||||
Id int64 `gorm:"primaryKey"`
|
||||
Password string `gorm:"type:varchar(100);not null;comment:User Password"`
|
||||
Algo string `gorm:"type:varchar(20);default:'default';comment:Encryption Algorithm"`
|
||||
Salt string `gorm:"type:varchar(20);default:null;comment:Password Salt"`
|
||||
Avatar string `gorm:"type:MEDIUMTEXT;comment:User Avatar"`
|
||||
Balance int64 `gorm:"default:0;comment:User Balance"` // User Balance Amount
|
||||
ReferCode string `gorm:"type:varchar(20);default:'';comment:Referral Code"`
|
||||
@@ -24,6 +26,7 @@ type User struct {
|
||||
EnableTradeNotify *bool `gorm:"default:false;not null;comment:Enable Trade Notifications"`
|
||||
AuthMethods []AuthMethods `gorm:"foreignKey:UserId;references:Id"`
|
||||
UserDevices []Device `gorm:"foreignKey:UserId;references:Id"`
|
||||
Rules string `gorm:"type:TEXT;comment:User Rules"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
}
|
||||
@@ -47,6 +50,7 @@ type Subscribe struct {
|
||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired 4: Deducted"`
|
||||
Note string `gorm:"type:varchar(500);default:'';comment:User note for subscription"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
}
|
||||
@@ -99,3 +103,18 @@ type DeviceOnlineRecord struct {
|
||||
func (DeviceOnlineRecord) TableName() string {
|
||||
return "user_device_online_record"
|
||||
}
|
||||
|
||||
type Withdrawal struct {
|
||||
Id int64 `gorm:"primaryKey"`
|
||||
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
||||
Amount int64 `gorm:"not null;comment:Withdrawal Amount"`
|
||||
Content string `gorm:"type:text;comment:Withdrawal Content"`
|
||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Withdrawal Status: 0: Pending 1: Approved 2: Rejected"`
|
||||
Reason string `gorm:"type:varchar(500);default:'';comment:Rejection Reason"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
}
|
||||
|
||||
func (*Withdrawal) TableName() string {
|
||||
return "user_withdrawal"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user