1
This commit is contained in:
@@ -2,10 +2,12 @@ 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 {
|
||||
@@ -30,14 +32,71 @@ type GetPVPReq struct {
|
||||
|
||||
func (c *PVPController) Get(ctx context.Context, req *GetPVPReq) (res *cool.BaseRes, err error) {
|
||||
res = &cool.BaseRes{}
|
||||
//var ret []TitleRes
|
||||
var (
|
||||
admin = cool.GetAdmin(ctx)
|
||||
//r = g.RequestFromCtx(ctx)
|
||||
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
|
||||
)
|
||||
alltitile := service.NewPVPService(uint32(admin.UserId)).Get(uint32(admin.UserId))
|
||||
if votePool, weekIndex, prevWeekIndex, err = tianxuanSv.BuildVoteCandidatePoolPayload(); err != nil {
|
||||
return
|
||||
}
|
||||
if currentPool, _, err = tianxuanSv.BuildCurrentTianxuanPayload(); err != nil {
|
||||
return
|
||||
}
|
||||
if prevWeekPool, err = tianxuanSv.BuildWeekTianxuanPayload(prevWeekIndex); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res.Data = alltitile
|
||||
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,
|
||||
}
|
||||
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)
|
||||
petID uint32
|
||||
saved uint32
|
||||
)
|
||||
|
||||
for _, item := range req.PetIDs {
|
||||
if item == 0 {
|
||||
continue
|
||||
}
|
||||
petID = gconv.Uint32(item)
|
||||
break
|
||||
}
|
||||
|
||||
if saved, err = configService.NewPeakTianxuanService().SaveVote(uint32(admin.UserId), petID); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res.Data = g.Map{
|
||||
"saved_pet_id": saved,
|
||||
"required_tianxuan_vote_count": 1,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,14 +3,36 @@ package model
|
||||
import (
|
||||
"blazing/common/data"
|
||||
"blazing/cool"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/tnnmigga/enum"
|
||||
)
|
||||
|
||||
// 表名常量
|
||||
const TableNamePlayerPVP = "player_pvp"
|
||||
const Curpvp = 0
|
||||
const DefaultPVPSeason = 0
|
||||
|
||||
const pvpConfigPath = "public/config/pvp.json"
|
||||
|
||||
type pvpConfig struct {
|
||||
CurrentSeason uint32 `json:"current_season"`
|
||||
}
|
||||
|
||||
func CurrentPVPSeason() uint32 {
|
||||
content := gfile.GetBytes(pvpConfigPath)
|
||||
if len(content) == 0 {
|
||||
return DefaultPVPSeason
|
||||
}
|
||||
|
||||
var config pvpConfig
|
||||
if err := json.Unmarshal(content, &config); err != nil {
|
||||
return DefaultPVPSeason
|
||||
}
|
||||
|
||||
return config.CurrentSeason
|
||||
}
|
||||
|
||||
// PVP 对应数据库表 player_pvp,用于记录用户PVP赛季数据及场次统计
|
||||
type PVP struct {
|
||||
|
||||
@@ -325,6 +325,13 @@ type PetService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func petFreeFilterQuery(ctx context.Context, m *gdb.Model) *gdb.Model {
|
||||
if !g.RequestFromCtx(ctx).Get("free_all").Bool() {
|
||||
m = m.WhereNot("free", 0)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func NewPetService(userid uint32) *PetService {
|
||||
return &PetService{
|
||||
BaseService: BaseService{
|
||||
@@ -336,20 +343,20 @@ func NewPetService(userid uint32) *PetService {
|
||||
FieldEQ: []string{"player_id", "free"},
|
||||
Where: func(ctx context.Context) [][]interface{} {
|
||||
return [][]interface{}{
|
||||
{"free", 0, false},
|
||||
{"is_vip", 0, true},
|
||||
}
|
||||
},
|
||||
Extend: petFreeFilterQuery,
|
||||
},
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
FieldEQ: []string{"player_id", "free"},
|
||||
DataFieldEQ: []string{"ID"},
|
||||
Where: func(ctx context.Context) [][]interface{} {
|
||||
return [][]interface{}{
|
||||
{"free", 0, false},
|
||||
{"is_vip", 0, true},
|
||||
}
|
||||
},
|
||||
Extend: petFreeFilterQuery,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -23,13 +23,14 @@ func (s *PVPService) Get(userid uint32) (ret *model.PVP) {
|
||||
|
||||
//todo待测试
|
||||
|
||||
m := s.dbm_fix(s.Model).Where("season", model.Curpvp)
|
||||
currentSeason := model.CurrentPVPSeason()
|
||||
m := s.dbm_fix(s.Model).Where("season", currentSeason)
|
||||
|
||||
m.Scan(&ret)
|
||||
if ret == nil {
|
||||
ret = &model.PVP{
|
||||
PlayerID: uint32(userid),
|
||||
Season: uint32(model.Curpvp),
|
||||
Season: currentSeason,
|
||||
RankInfo: model.PVPRankInfo{
|
||||
Score: 800,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user