This commit is contained in:
@@ -33,24 +33,29 @@ type GetPVPReq struct {
|
||||
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
|
||||
weekIndex uint32
|
||||
prevWeekIndex uint32
|
||||
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(); err != nil {
|
||||
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,
|
||||
@@ -63,6 +68,7 @@ func (c *PVPController) Get(ctx context.Context, req *GetPVPReq) (res *cool.Base
|
||||
"tianxuan_vote_pool": votePool,
|
||||
"tianxuan_prev_week_pool": prevWeekPool,
|
||||
"current_tianxuan_pool": currentPool,
|
||||
"my_tianxuan_vote_pet_id": playerVotePetID,
|
||||
}
|
||||
return
|
||||
|
||||
@@ -77,9 +83,13 @@ func (c *PVPController) SaveTianxuanVote(ctx context.Context, req *SaveTianxuanV
|
||||
res = &cool.BaseRes{}
|
||||
|
||||
var (
|
||||
admin = cool.GetAdmin(ctx)
|
||||
petID uint32
|
||||
saved uint32
|
||||
admin = cool.GetAdmin(ctx)
|
||||
tianxuanSv = configService.NewPeakTianxuanService()
|
||||
petID uint32
|
||||
saved uint32
|
||||
votePool []g.Map
|
||||
weekIndex uint32
|
||||
prevWeekIndex uint32
|
||||
)
|
||||
|
||||
for _, item := range req.PetIDs {
|
||||
@@ -90,13 +100,34 @@ func (c *PVPController) SaveTianxuanVote(ctx context.Context, req *SaveTianxuanV
|
||||
break
|
||||
}
|
||||
|
||||
if saved, err = configService.NewPeakTianxuanService().SaveVote(uint32(admin.UserId), petID); err != nil {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user