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:
@@ -31,6 +31,17 @@ type DonationServerListReq struct {
|
||||
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 {
|
||||
g.Meta `path:"/donation/redeem" method:"POST"`
|
||||
CDKCode string `json:"cdk_code" v:"required#CDK不能为空"`
|
||||
@@ -43,7 +54,6 @@ type DonationRedeemRes struct {
|
||||
ServerName string `json:"server_name"`
|
||||
OwnerID uint32 `json:"owner_id"`
|
||||
ServerExpireTime time.Time `json:"server_expire_time"`
|
||||
CDKExpireTime time.Time `json:"cdk_expire_time"`
|
||||
}
|
||||
|
||||
// DonationServerIDs 查询当前可用于服务器绑定CDK的服务器ID列表。
|
||||
@@ -58,6 +68,29 @@ func (c *CdkController) DonationServerIDs(ctx context.Context, req *DonationServ
|
||||
}), 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并完成冠名写入。
|
||||
func (c *CdkController) DonationRedeem(ctx context.Context, req *DonationRedeemReq) (res *cool.BaseRes, err error) {
|
||||
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,
|
||||
OwnerID: serverInfo.OwnerID,
|
||||
ServerExpireTime: serverInfo.ServerExpireTime,
|
||||
CDKExpireTime: serverInfo.CDKExpireTime,
|
||||
}), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user