refactor: 重构服务器冠名逻辑至独立表
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -47,3 +47,4 @@ public/login-linux-amd64
|
|||||||
public/login-login-linux-amd64
|
public/login-login-linux-amd64
|
||||||
public/logic_linux-amd64_1
|
public/logic_linux-amd64_1
|
||||||
.cache/**
|
.cache/**
|
||||||
|
.agents/**
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ type ServerList struct {
|
|||||||
OldScreen string `gorm:"comment:'服务器screen参数'" json:"old_screen"`
|
OldScreen string `gorm:"comment:'服务器screen参数'" json:"old_screen"`
|
||||||
//到期时间ServerList
|
//到期时间ServerList
|
||||||
ExpireTime time.Time `gorm:"default:0;comment:'到期时间'" json:"expire_time"`
|
ExpireTime time.Time `gorm:"default:0;comment:'到期时间'" json:"expire_time"`
|
||||||
//CDK冠名到期时间ServerList
|
|
||||||
CDKExpireTime time.Time `gorm:"column:cdk_expire_time;default:0;comment:'CDK冠名到期时间'" json:"cdk_expire_time"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerList) GetID() string {
|
func (s *ServerList) GetID() string {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
playerservice "blazing/modules/player/service"
|
playerservice "blazing/modules/player/service"
|
||||||
|
|
||||||
"github.com/deatil/go-cryptobin/cryptobin/crypto"
|
"github.com/deatil/go-cryptobin/cryptobin/crypto"
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
)
|
)
|
||||||
@@ -123,7 +122,7 @@ type SessionRes struct {
|
|||||||
UserID int `json:"userid"`
|
UserID int `json:"userid"`
|
||||||
Session string `json:"session"`
|
Session string `json:"session"`
|
||||||
|
|
||||||
Server gdb.List `json:"server"`
|
Server []config.ServerShowInfo `json:"server"`
|
||||||
PetID []int `json:"petid"`
|
PetID []int `json:"petid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const TableNameServerList = "server_list"
|
|||||||
type ServerList struct {
|
type ServerList struct {
|
||||||
*cool.Model
|
*cool.Model
|
||||||
coolconfig.ServerList
|
coolconfig.ServerList
|
||||||
|
ServerShow *ServerShow `orm:"with:server_id=online_id" json:"server_show,omitempty"`
|
||||||
// isonline
|
// isonline
|
||||||
IsOnline uint8 `gorm:"column:isonline;default:0;comment:'是否在线'" json:"isonline"`
|
IsOnline uint8 `gorm:"column:isonline;default:0;comment:'是否在线'" json:"isonline"`
|
||||||
}
|
}
|
||||||
|
|||||||
39
modules/config/model/server_show.go
Normal file
39
modules/config/model/server_show.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/cool"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const TableNameServerShow = "server_show"
|
||||||
|
|
||||||
|
// ServerShow 绑定服务器展示信息(冠名、属主、到期时间)。
|
||||||
|
type ServerShow struct {
|
||||||
|
*cool.Model
|
||||||
|
ServerID uint32 `gorm:"column:server_id;comment:'服务器ID';uniqueIndex" json:"server_id"`
|
||||||
|
Name string `gorm:"comment:'服务器展示名'" json:"name"`
|
||||||
|
Owner uint32 `gorm:"comment:'服务器属主'" json:"owner"`
|
||||||
|
ExpireTime time.Time `gorm:"column:expire_time;default:0;comment:'展示到期时间'" json:"expire_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName ServerShow's table name
|
||||||
|
func (*ServerShow) TableName() string {
|
||||||
|
return TableNameServerShow
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupName ServerShow's table group
|
||||||
|
func (*ServerShow) GroupName() string {
|
||||||
|
return "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServerShow create a new ServerShow
|
||||||
|
func NewServerShow() *ServerShow {
|
||||||
|
return &ServerShow{
|
||||||
|
Model: cool.NewModel(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// init 创建表
|
||||||
|
func init() {
|
||||||
|
cool.CreateTable(&ServerShow{})
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -165,7 +166,6 @@ type ServerNamingCDKResult struct {
|
|||||||
ServerName string
|
ServerName string
|
||||||
OwnerID uint32
|
OwnerID uint32
|
||||||
ServerExpireTime time.Time
|
ServerExpireTime time.Time
|
||||||
CDKExpireTime time.Time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseServerNamingCDK 使用服务器冠名类型CDK,并原子化更新服务器归属和到期时间。
|
// UseServerNamingCDK 使用服务器冠名类型CDK,并原子化更新服务器归属和到期时间。
|
||||||
@@ -175,7 +175,7 @@ func (s *CdkService) UseServerNamingCDK(ctx context.Context, code string, ownerI
|
|||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
serverService := NewServerService()
|
serverService := NewServerService()
|
||||||
var updated model.ServerList
|
var updated model.ServerShow
|
||||||
|
|
||||||
err := g.DB(s.Model.GroupName()).Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
err := g.DB(s.Model.GroupName()).Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||||
var cfg model.CDKConfig
|
var cfg model.CDKConfig
|
||||||
@@ -196,13 +196,13 @@ func (s *CdkService) UseServerNamingCDK(ctx context.Context, code string, ownerI
|
|||||||
}
|
}
|
||||||
|
|
||||||
var server model.ServerList
|
var server model.ServerList
|
||||||
if err := tx.Model(model.NewServerList()).Where("online_id", serverID).Scan(&server); err != nil {
|
if err := tx.Model(model.NewServerList()).With(model.ServerShow{}).Where("online_id", serverID).Scan(&server); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if server.OnlineID == 0 {
|
if server.OnlineID == 0 {
|
||||||
return gerror.New("服务器不存在")
|
return gerror.New("服务器不存在")
|
||||||
}
|
}
|
||||||
if server.Owner != ownerID && !serverService.CanUseDonationName(server, now) {
|
if !serverService.CanUseDonationName(server, ownerID, now) {
|
||||||
return gerror.New("服务器不可冠名")
|
return gerror.New("服务器不可冠名")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,23 +215,40 @@ func (s *CdkService) UseServerNamingCDK(ctx context.Context, code string, ownerI
|
|||||||
return gerror.New("cdk已被使用")
|
return gerror.New("cdk已被使用")
|
||||||
}
|
}
|
||||||
|
|
||||||
updated = server
|
var currentShow model.ServerShow
|
||||||
|
if server.ServerShow != nil {
|
||||||
|
currentShow = *server.ServerShow
|
||||||
|
}
|
||||||
|
|
||||||
|
updated = currentShow
|
||||||
|
updated.ServerID = serverID
|
||||||
updated.Name = serverName
|
updated.Name = serverName
|
||||||
updated.Owner = ownerID
|
updated.Owner = ownerID
|
||||||
if server.Owner != ownerID {
|
|
||||||
updated.CDKExpireTime = now.AddDate(0, 1, 0)
|
if currentShow.ServerID == 0 || !serverService.isActiveServerShow(¤tShow, now) || currentShow.Owner != ownerID {
|
||||||
|
updated.ExpireTime = now.AddDate(0, 1, 0)
|
||||||
} else {
|
} else {
|
||||||
baseTime := server.CDKExpireTime
|
baseTime := currentShow.ExpireTime
|
||||||
if baseTime.IsZero() {
|
if baseTime.IsZero() {
|
||||||
baseTime = now
|
baseTime = now
|
||||||
}
|
}
|
||||||
updated.CDKExpireTime = baseTime.AddDate(0, 1, 0)
|
updated.ExpireTime = baseTime.AddDate(0, 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Model(model.NewServerList()).Where("online_id", serverID).Data(g.Map{
|
if currentShow.ServerID == 0 {
|
||||||
|
_, err = tx.Model(model.NewServerShow()).Data(g.Map{
|
||||||
|
"server_id": updated.ServerID,
|
||||||
"name": updated.Name,
|
"name": updated.Name,
|
||||||
"owner": updated.Owner,
|
"owner": updated.Owner,
|
||||||
"cdk_expire_time": updated.CDKExpireTime,
|
"expire_time": updated.ExpireTime,
|
||||||
|
}).Insert()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = tx.Model(model.NewServerShow()).Where("server_id", serverID).Data(g.Map{
|
||||||
|
"name": updated.Name,
|
||||||
|
"owner": updated.Owner,
|
||||||
|
"expire_time": updated.ExpireTime,
|
||||||
}).Update()
|
}).Update()
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
@@ -241,12 +258,12 @@ func (s *CdkService) UseServerNamingCDK(ctx context.Context, code string, ownerI
|
|||||||
|
|
||||||
g.DB(s.Model.GroupName()).GetCore().ClearCache(context.TODO(), s.Model.TableName())
|
g.DB(s.Model.GroupName()).GetCore().ClearCache(context.TODO(), s.Model.TableName())
|
||||||
g.DB(model.NewServerList().GroupName()).GetCore().ClearCache(context.TODO(), model.NewServerList().TableName())
|
g.DB(model.NewServerList().GroupName()).GetCore().ClearCache(context.TODO(), model.NewServerList().TableName())
|
||||||
|
g.DB(model.NewServerShow().GroupName()).GetCore().ClearCache(context.TODO(), model.NewServerShow().TableName())
|
||||||
return &ServerNamingCDKResult{
|
return &ServerNamingCDKResult{
|
||||||
ServerID: updated.OnlineID,
|
ServerID: updated.ServerID,
|
||||||
ServerName: updated.Name,
|
ServerName: updated.Name,
|
||||||
OwnerID: updated.Owner,
|
OwnerID: updated.Owner,
|
||||||
ServerExpireTime: updated.ExpireTime,
|
ServerExpireTime: updated.ExpireTime,
|
||||||
CDKExpireTime: updated.CDKExpireTime,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,6 +280,18 @@ func (s *CdkService) BatchGenerate(ctx context.Context, count int) (interface{},
|
|||||||
delete(requestData, "cdk_code")
|
delete(requestData, "cdk_code")
|
||||||
delete(requestData, "id")
|
delete(requestData, "id")
|
||||||
|
|
||||||
|
cdkType := gconv.Uint32(requestData["type"])
|
||||||
|
if cdkType != CDKTypeReward && cdkType != CDKTypeServerNaming {
|
||||||
|
return nil, gerror.New("CDK类型非法")
|
||||||
|
}
|
||||||
|
requestData["type"] = cdkType
|
||||||
|
if cdkType == CDKTypeServerNaming {
|
||||||
|
requestData["exchange_remain_count"] = int64(1)
|
||||||
|
requestData["item_reward_ids"] = []uint32{}
|
||||||
|
requestData["elf_reward_ids"] = []uint32{}
|
||||||
|
requestData["title_reward_ids"] = uint32(0)
|
||||||
|
}
|
||||||
|
|
||||||
codes, err := s.generateAvailableCodes(count)
|
codes, err := s.generateAvailableCodes(count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/container/gmap"
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
@@ -21,32 +22,54 @@ type ServerService struct {
|
|||||||
bucket string
|
bucket string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ServerShowInfo struct {
|
||||||
|
OnlineID uint32 `json:"online_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
IP string `json:"ip"`
|
||||||
|
Port uint32 `json:"port"`
|
||||||
|
IsVip uint32 `json:"is_vip"`
|
||||||
|
IsDebug uint8 `json:"is_debug"`
|
||||||
|
IsOpen uint8 `json:"is_open"`
|
||||||
|
Owner uint32 `json:"owner"`
|
||||||
|
ExpireTime time.Time `json:"expire_time"`
|
||||||
|
ServerShow *model.ServerShow `json:"servershow,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
func NewServerService() *ServerService {
|
func NewServerService() *ServerService {
|
||||||
cf := &ServerService{
|
cf := &ServerService{
|
||||||
Service: &cool.Service{
|
Service: &cool.Service{
|
||||||
Model: model.NewServerList(),
|
Model: model.NewServerList(),
|
||||||
PageQueryOp: &cool.QueryOp{
|
},
|
||||||
|
}
|
||||||
|
cf.PageQueryOp = &cool.QueryOp{
|
||||||
ModifyResult: func(ctx g.Ctx, data interface{}) interface{} {
|
ModifyResult: func(ctx g.Ctx, data interface{}) interface{} {
|
||||||
var rr []g.MapStrAny
|
var rr []g.MapStrAny
|
||||||
r, _ := gconv.Map(data)["list"].(gdb.Result)
|
r, _ := gconv.Map(data)["list"].(gdb.Result)
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
serverIDs := make([]uint32, 0, len(r))
|
||||||
|
for i := 0; i < len(r); i++ {
|
||||||
|
serverID := gconv.Uint32(r[i].Map()["online_id"])
|
||||||
|
if serverID == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
serverIDs = append(serverIDs, serverID)
|
||||||
|
}
|
||||||
|
showMap := cf.getActiveServerShowMap(serverIDs, now)
|
||||||
|
|
||||||
for i := 0; i < len(r); i++ {
|
for i := 0; i < len(r); i++ {
|
||||||
t, ok := cool.GetClient(gconv.Uint32(r[i].Map()["online_id"]), gconv.Uint32(r[i].Map()["port"]))
|
t, ok := cool.GetClient(gconv.Uint32(r[i].Map()["online_id"]), gconv.Uint32(r[i].Map()["port"]))
|
||||||
// tt.Friends = v.Friends
|
|
||||||
subm := r[i].GMap()
|
subm := r[i].GMap()
|
||||||
|
cf.applyServerShowMap(subm, gconv.Uint32(r[i].Map()["online_id"]), showMap)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
|
|
||||||
err := t.KickPerson(0) //实现指定服务器踢人
|
err := t.KickPerson(0) //实现指定服务器踢人
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
r, _ := utils.TcpPing(fmt.Sprintf("%s:%d", r[i].Map()["ip"], r[i].Map()["port"]))
|
r, _ := utils.TcpPing(fmt.Sprintf("%s:%d", r[i].Map()["ip"], r[i].Map()["port"]))
|
||||||
|
|
||||||
subm.Set("isonline", r)
|
subm.Set("isonline", r)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
subm.Set("isonline", 0)
|
subm.Set("isonline", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
subm.Set("isonline", 0)
|
subm.Set("isonline", 0)
|
||||||
}
|
}
|
||||||
@@ -54,12 +77,10 @@ func NewServerService() *ServerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.(map[string]interface{})["list"] = rr
|
data.(map[string]interface{})["list"] = rr
|
||||||
|
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := storage.Config{
|
cfg := storage.Config{
|
||||||
Zone: &storage.ZoneHuadong,
|
Zone: &storage.ZoneHuadong,
|
||||||
UseHTTPS: true,
|
UseHTTPS: true,
|
||||||
@@ -67,107 +88,106 @@ func NewServerService() *ServerService {
|
|||||||
}
|
}
|
||||||
mac := qbox.NewMac("DzMpomnPxqBHkIcvxTbC-hl_8LjVB0LXZuhCky_u", "bhoxrpG1s7MBmSS2I1k5t9zMpuiderpBDZoIPQKU")
|
mac := qbox.NewMac("DzMpomnPxqBHkIcvxTbC-hl_8LjVB0LXZuhCky_u", "bhoxrpG1s7MBmSS2I1k5t9zMpuiderpBDZoIPQKU")
|
||||||
cf.bucket = "blazingt"
|
cf.bucket = "blazingt"
|
||||||
|
|
||||||
cf.manager = storage.NewBucketManager(mac, &cfg)
|
cf.manager = storage.NewBucketManager(mac, &cfg)
|
||||||
return cf
|
return cf
|
||||||
}
|
}
|
||||||
func (s *ServerService) GetPort(DepartmentID uint) gdb.List {
|
|
||||||
var res gdb.Result
|
|
||||||
m := cool.DBM(s.Model).Where("is_open", 1).Fields("ip", "port", "online_id", "is_vip", "name")
|
|
||||||
if DepartmentID != 1 {
|
|
||||||
|
|
||||||
res, _ = m.All()
|
|
||||||
|
|
||||||
} else {
|
|
||||||
res, _ = m.Where("is_debug", 0).All()
|
|
||||||
|
|
||||||
|
func (s *ServerService) GetPort(DepartmentID uint) []ServerShowInfo {
|
||||||
|
servers := s.GetServer()
|
||||||
|
items := make([]ServerShowInfo, 0, len(servers))
|
||||||
|
for _, server := range servers {
|
||||||
|
if server.IsOpen != 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if DepartmentID == 1 && server.IsDebug != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
items = append(items, ServerShowInfo{
|
||||||
|
OnlineID: server.OnlineID,
|
||||||
|
Name: server.Name,
|
||||||
|
IP: server.IP,
|
||||||
|
Port: server.Port,
|
||||||
|
IsVip: server.IsVip,
|
||||||
|
IsDebug: server.IsDebug,
|
||||||
|
IsOpen: server.IsOpen,
|
||||||
|
Owner: server.Owner,
|
||||||
|
ExpireTime: server.ExpireTime,
|
||||||
|
ServerShow: server.ServerShow,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.List()
|
|
||||||
|
|
||||||
}
|
|
||||||
func (s *ServerService) GetServer() []model.ServerList {
|
func (s *ServerService) GetServer() []model.ServerList {
|
||||||
var item []model.ServerList
|
var item []model.ServerList
|
||||||
cool.DBM(s.Model).Scan(&item)
|
dbm_nocache_noenable(s.Model).With(model.ServerShow{}).Scan(&item)
|
||||||
|
s.applyServerShowList(item, time.Now())
|
||||||
return item
|
return item
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerService) StartUPdate(OnlineID uint16, isinstall int) model.ServerList {
|
func (s *ServerService) StartUPdate(OnlineID uint16, isinstall int) model.ServerList {
|
||||||
|
|
||||||
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
||||||
|
|
||||||
var tttt model.ServerList
|
var tttt model.ServerList
|
||||||
m.Scan(&tttt)
|
m.Scan(&tttt)
|
||||||
if isinstall == 1 {
|
if isinstall == 1 {
|
||||||
tttt.IsOpen = uint8(0)
|
tttt.IsOpen = uint8(0)
|
||||||
m.Save(tttt)
|
m.Save(tttt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// s.CleanCache()
|
|
||||||
return tttt
|
return tttt
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerService) SetServerID(OnlineID uint32, Port uint32) error {
|
func (s *ServerService) SetServerID(OnlineID uint32, Port uint32) error {
|
||||||
|
|
||||||
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
||||||
|
|
||||||
var tttt model.ServerList
|
var tttt model.ServerList
|
||||||
m.Scan(&tttt)
|
m.Scan(&tttt)
|
||||||
tttt.Port = Port
|
tttt.Port = Port
|
||||||
tttt.OnlineID = OnlineID
|
tttt.OnlineID = OnlineID
|
||||||
tttt.IsOpen = 1
|
tttt.IsOpen = 1
|
||||||
|
|
||||||
m.Save(tttt)
|
m.Save(tttt)
|
||||||
// s.CleanCache()
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerService) GetServerID(OnlineID uint32) model.ServerList {
|
func (s *ServerService) GetServerID(OnlineID uint32) model.ServerList {
|
||||||
var tttt model.ServerList
|
var tttt model.ServerList
|
||||||
cool.DBM(s.Model).Where("online_id", OnlineID).Scan(&tttt)
|
dbm_nocache_noenable(s.Model).With(model.ServerShow{}).Where("online_id", OnlineID).Scan(&tttt)
|
||||||
|
s.applyServerShow(&tttt, time.Now())
|
||||||
return tttt
|
return tttt
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDonationAvailableServerIDs 返回当前可被冠名占用的服务器ID列表。
|
// GetDonationAvailableServerIDs 返回当前可被冠名占用的服务器ID列表。
|
||||||
func (s *ServerService) GetDonationAvailableServerIDs() []uint32 {
|
func (s *ServerService) GetDonationAvailableServerIDs() []uint32 {
|
||||||
|
servers := s.GetServer()
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
builder := dbm_nocache_noenable(s.Model).Builder().Where("owner", 0).WhereOr("cdk_expire_time <= ?", now)
|
ids := make([]uint32, 0, len(servers))
|
||||||
|
for _, server := range servers {
|
||||||
var rows []struct {
|
if server.OnlineID == 0 {
|
||||||
OnlineID uint32 `json:"online_id"`
|
|
||||||
}
|
|
||||||
dbm_nocache_noenable(s.Model).Fields("online_id").Where(builder).OrderAsc("online_id").Scan(&rows)
|
|
||||||
|
|
||||||
ids := make([]uint32, 0, len(rows))
|
|
||||||
for _, row := range rows {
|
|
||||||
if row.OnlineID == 0 {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ids = append(ids, row.OnlineID)
|
if s.isActiveServerShow(server.ServerShow, now) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
ids = append(ids, server.OnlineID)
|
||||||
|
}
|
||||||
|
sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
|
||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
// CanUseDonationName 校验目标服务器在当前时间点是否允许被冠名。
|
// CanUseDonationName 校验目标服务器在当前时间点是否允许被冠名。
|
||||||
func (s *ServerService) CanUseDonationName(server model.ServerList, now time.Time) bool {
|
func (s *ServerService) CanUseDonationName(server model.ServerList, ownerID uint32, now time.Time) bool {
|
||||||
if server.OnlineID == 0 {
|
if server.OnlineID == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if server.Owner == 0 {
|
if !s.isActiveServerShow(server.ServerShow, now) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return !server.CDKExpireTime.After(now)
|
return server.ServerShow.Owner == ownerID
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存版本号
|
// 保存版本号
|
||||||
func (s *ServerService) SetServerScreen(id uint32, name string) {
|
func (s *ServerService) SetServerScreen(id uint32, name string) {
|
||||||
|
|
||||||
cool.DBM(s.Model).Where("online_id", id).Data("old_screen", name).Update()
|
cool.DBM(s.Model).Where("online_id", id).Data("old_screen", name).Update()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerService) GetFile() string {
|
func (s *ServerService) GetFile() string {
|
||||||
var files []File
|
var files []File
|
||||||
prefix := "logic"
|
prefix := "logic"
|
||||||
@@ -178,7 +198,6 @@ func (s *ServerService) GetFile() string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
// 添加文件到结果列表
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
files = append(files, File{
|
files = append(files, File{
|
||||||
Name: entry.Key,
|
Name: entry.Key,
|
||||||
@@ -187,22 +206,19 @@ func (s *ServerService) GetFile() string {
|
|||||||
Time: entry.PutTime,
|
Time: entry.PutTime,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果没有更多文件,结束循环
|
|
||||||
if !hasNext {
|
if !hasNext {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新标记,继续下一页
|
|
||||||
marker = nextMarker
|
marker = nextMarker
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(files, func(i, j int) bool {
|
sort.Slice(files, func(i, j int) bool {
|
||||||
return files[i].Time > files[j].Time
|
return files[i].Time > files[j].Time
|
||||||
})
|
})
|
||||||
|
if len(files) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return files[0].Name
|
return files[0].Name
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
@@ -213,3 +229,74 @@ type File struct {
|
|||||||
Modified string `json:"modified"`
|
Modified string `json:"modified"`
|
||||||
Time int64 `json:"time"`
|
Time int64 `json:"time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) isActiveServerShow(show *model.ServerShow, now time.Time) bool {
|
||||||
|
if show == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if show.ServerID == 0 || show.Owner == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if show.ExpireTime.IsZero() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return show.ExpireTime.After(now)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) applyServerShowList(servers []model.ServerList, now time.Time) {
|
||||||
|
for i := range servers {
|
||||||
|
s.applyServerShow(&servers[i], now)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) applyServerShow(server *model.ServerList, now time.Time) {
|
||||||
|
if server == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
server.Owner = 0
|
||||||
|
server.ExpireTime = time.Time{}
|
||||||
|
if !s.isActiveServerShow(server.ServerShow, now) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if server.ServerShow.Name != "" {
|
||||||
|
server.Name = server.ServerShow.Name
|
||||||
|
}
|
||||||
|
server.Owner = server.ServerShow.Owner
|
||||||
|
server.ExpireTime = server.ServerShow.ExpireTime
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) getActiveServerShowMap(serverIDs []uint32, now time.Time) map[uint32]*model.ServerShow {
|
||||||
|
showMap := make(map[uint32]*model.ServerShow, len(serverIDs))
|
||||||
|
if len(serverIDs) == 0 {
|
||||||
|
return showMap
|
||||||
|
}
|
||||||
|
var shows []model.ServerShow
|
||||||
|
dbm_nocache_noenable(model.NewServerShow()).WhereIn("server_id", serverIDs).Scan(&shows)
|
||||||
|
for i := range shows {
|
||||||
|
show := &shows[i]
|
||||||
|
if !s.isActiveServerShow(show, now) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
showMap[show.ServerID] = show
|
||||||
|
}
|
||||||
|
return showMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) applyServerShowMap(serverMap *gmap.StrAnyMap, serverID uint32, showMap map[uint32]*model.ServerShow) {
|
||||||
|
if serverMap == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
serverMap.Set("owner", uint32(0))
|
||||||
|
serverMap.Set("expire_time", time.Time{})
|
||||||
|
show, ok := showMap[serverID]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if show.Name != "" {
|
||||||
|
serverMap.Set("name", show.Name)
|
||||||
|
}
|
||||||
|
serverMap.Set("owner", show.Owner)
|
||||||
|
serverMap.Set("expire_time", show.ExpireTime)
|
||||||
|
serverMap.Set("servershow", show)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,17 @@ type DonationServerListReq struct {
|
|||||||
g.Meta `path:"/donation/serverIds" method:"GET"`
|
g.Meta `path:"/donation/serverIds" method:"GET"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DonationServerInfoReq struct {
|
||||||
|
g.Meta `path:"/donation/serverInfo" method:"GET"`
|
||||||
|
ServerID uint32 `json:"server_id" v:"required|min:1#服务器ID不能为空|服务器ID非法"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DonationServerInfoRes struct {
|
||||||
|
ServerID uint32 `json:"server_id"`
|
||||||
|
ServerName string `json:"server_name"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
}
|
||||||
|
|
||||||
type DonationRedeemReq struct {
|
type DonationRedeemReq struct {
|
||||||
g.Meta `path:"/donation/redeem" method:"POST"`
|
g.Meta `path:"/donation/redeem" method:"POST"`
|
||||||
CDKCode string `json:"cdk_code" v:"required#CDK不能为空"`
|
CDKCode string `json:"cdk_code" v:"required#CDK不能为空"`
|
||||||
@@ -43,7 +54,6 @@ type DonationRedeemRes struct {
|
|||||||
ServerName string `json:"server_name"`
|
ServerName string `json:"server_name"`
|
||||||
OwnerID uint32 `json:"owner_id"`
|
OwnerID uint32 `json:"owner_id"`
|
||||||
ServerExpireTime time.Time `json:"server_expire_time"`
|
ServerExpireTime time.Time `json:"server_expire_time"`
|
||||||
CDKExpireTime time.Time `json:"cdk_expire_time"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DonationServerIDs 查询当前可用于服务器绑定CDK的服务器ID列表。
|
// DonationServerIDs 查询当前可用于服务器绑定CDK的服务器ID列表。
|
||||||
@@ -58,6 +68,29 @@ func (c *CdkController) DonationServerIDs(ctx context.Context, req *DonationServ
|
|||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DonationServerInfo 查询冠名兑换前展示的服务器名称与备注。
|
||||||
|
func (c *CdkController) DonationServerInfo(ctx context.Context, req *DonationServerInfoReq) (res *cool.BaseRes, err error) {
|
||||||
|
if err = g.Validator().Data(req).Run(ctx); err != nil {
|
||||||
|
return cool.Fail(err.Error()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
admin := cool.GetAdmin(ctx)
|
||||||
|
if admin == nil || admin.UserId == 0 {
|
||||||
|
return cool.Fail("未登录或登录已失效"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
server := configservice.NewServerService().GetServerID(req.ServerID)
|
||||||
|
if server.OnlineID == 0 {
|
||||||
|
return cool.Fail("服务器不存在"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return cool.Ok(&DonationServerInfoRes{
|
||||||
|
ServerID: server.OnlineID,
|
||||||
|
ServerName: server.Name,
|
||||||
|
Remark: server.Desc,
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
|
||||||
// DonationRedeem 兑换服务器绑定类型CDK并完成冠名写入。
|
// DonationRedeem 兑换服务器绑定类型CDK并完成冠名写入。
|
||||||
func (c *CdkController) DonationRedeem(ctx context.Context, req *DonationRedeemReq) (res *cool.BaseRes, err error) {
|
func (c *CdkController) DonationRedeem(ctx context.Context, req *DonationRedeemReq) (res *cool.BaseRes, err error) {
|
||||||
if err = g.Validator().Data(req).Run(ctx); err != nil {
|
if err = g.Validator().Data(req).Run(ctx); err != nil {
|
||||||
@@ -112,6 +145,5 @@ func (c *CdkController) DonationRedeem(ctx context.Context, req *DonationRedeemR
|
|||||||
ServerName: serverInfo.ServerName,
|
ServerName: serverInfo.ServerName,
|
||||||
OwnerID: serverInfo.OwnerID,
|
OwnerID: serverInfo.OwnerID,
|
||||||
ServerExpireTime: serverInfo.ServerExpireTime,
|
ServerExpireTime: serverInfo.ServerExpireTime,
|
||||||
CDKExpireTime: serverInfo.CDKExpireTime,
|
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|||||||
10
skills-lock.json
Normal file
10
skills-lock.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"skills": {
|
||||||
|
"goframe-v2": {
|
||||||
|
"source": "gogf/skills",
|
||||||
|
"sourceType": "github",
|
||||||
|
"computedHash": "c734f4670650e9b7c7c318c8374987ffed61c4782c11aa4e65fac9f3d6275889"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user