134 lines
3.5 KiB
Go
134 lines
3.5 KiB
Go
package admin
|
||
|
||
import (
|
||
"blazing/cool"
|
||
configService "blazing/modules/config/service"
|
||
"blazing/modules/player/service"
|
||
"context"
|
||
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
)
|
||
|
||
type PVPController struct {
|
||
*cool.Controller
|
||
}
|
||
|
||
func init() {
|
||
var task_info_controller = &PVPController{
|
||
&cool.Controller{
|
||
Prefix: "/admin/game/pvp",
|
||
Api: []string{"Delete", "Update", "Info", "List", "Page"},
|
||
Service: service.NewPVPService(0), //因为page已经过滤,所以这里需要改成0
|
||
},
|
||
}
|
||
// 注册路由
|
||
cool.RegisterController(task_info_controller)
|
||
}
|
||
|
||
type GetPVPReq struct {
|
||
g.Meta `path:"/get" method:"POST"`
|
||
}
|
||
|
||
func (c *PVPController) Get(ctx context.Context, req *GetPVPReq) (res *cool.BaseRes, err error) {
|
||
res = &cool.BaseRes{}
|
||
var (
|
||
admin = cool.GetAdmin(ctx)
|
||
pvpInfo = service.NewPVPService(uint32(admin.UserId)).Get(uint32(admin.UserId))
|
||
tianxuanSv = configService.NewPeakTianxuanService()
|
||
votePool []g.Map
|
||
currentPool []g.Map
|
||
prevWeekPool []g.Map
|
||
playerVotePetID uint32
|
||
weekIndex uint32
|
||
prevWeekIndex uint32
|
||
)
|
||
if votePool, weekIndex, prevWeekIndex, err = tianxuanSv.BuildVoteCandidatePoolPayload(); err != nil {
|
||
return
|
||
}
|
||
if currentPool, _, err = tianxuanSv.BuildCurrentTianxuanPayload(uint32(admin.UserId)); err != nil {
|
||
return
|
||
}
|
||
if prevWeekPool, err = tianxuanSv.BuildWeekTianxuanPayload(prevWeekIndex); err != nil {
|
||
return
|
||
}
|
||
if playerVotePetID, err = tianxuanSv.GetPlayerVote(uint32(admin.UserId)); err != nil {
|
||
return
|
||
}
|
||
markMyTianxuanVote(votePool, playerVotePetID)
|
||
|
||
res.Data = g.Map{
|
||
"id": pvpInfo.ID,
|
||
"player_id": pvpInfo.PlayerID,
|
||
"season": pvpInfo.Season,
|
||
"rank_info": pvpInfo.RankInfo,
|
||
"required_tianxuan_vote_count": 1,
|
||
"tianxuan_week_index": weekIndex,
|
||
"tianxuan_prev_week_index": prevWeekIndex,
|
||
"tianxuan_vote_pool": votePool,
|
||
"tianxuan_prev_week_pool": prevWeekPool,
|
||
"current_tianxuan_pool": currentPool,
|
||
"my_tianxuan_vote_pet_id": playerVotePetID,
|
||
}
|
||
return
|
||
|
||
}
|
||
|
||
type SaveTianxuanVoteReq struct {
|
||
g.Meta `path:"/save_tianxuan_vote" method:"POST"`
|
||
PetIDs []uint32 `json:"pet_ids"`
|
||
}
|
||
|
||
func (c *PVPController) SaveTianxuanVote(ctx context.Context, req *SaveTianxuanVoteReq) (res *cool.BaseRes, err error) {
|
||
res = &cool.BaseRes{}
|
||
|
||
var (
|
||
admin = cool.GetAdmin(ctx)
|
||
tianxuanSv = configService.NewPeakTianxuanService()
|
||
petID uint32
|
||
saved uint32
|
||
votePool []g.Map
|
||
weekIndex uint32
|
||
prevWeekIndex uint32
|
||
)
|
||
|
||
for _, item := range req.PetIDs {
|
||
if item == 0 {
|
||
continue
|
||
}
|
||
petID = gconv.Uint32(item)
|
||
break
|
||
}
|
||
|
||
if saved, err = tianxuanSv.SaveVote(uint32(admin.UserId), petID); err != nil {
|
||
return
|
||
}
|
||
if votePool, weekIndex, prevWeekIndex, err = tianxuanSv.BuildVoteCandidatePoolPayload(); err != nil {
|
||
return
|
||
}
|
||
markMyTianxuanVote(votePool, saved)
|
||
|
||
res.Data = g.Map{
|
||
"saved_pet_id": saved,
|
||
"my_tianxuan_vote_pet_id": saved,
|
||
"required_tianxuan_vote_count": 1,
|
||
"tianxuan_week_index": weekIndex,
|
||
"tianxuan_prev_week_index": prevWeekIndex,
|
||
"tianxuan_vote_pool": votePool,
|
||
}
|
||
return
|
||
}
|
||
|
||
func markMyTianxuanVote(votePool []g.Map, petID uint32) {
|
||
if petID == 0 {
|
||
return
|
||
}
|
||
for _, item := range votePool {
|
||
if gconv.Uint32(item["pet_id"]) == petID || gconv.Uint32(item["petId"]) == petID {
|
||
item["is_voted"] = true
|
||
item["isVoted"] = true
|
||
return
|
||
}
|
||
}
|
||
}
|