org_player.go 9.15 KB
Newer Older
haoyanbin's avatar
haoyanbin committed
1 2 3 4 5 6
package apis

import (
	"github.com/gin-gonic/gin"
	"github.com/go-admin-team/go-admin-core/sdk/api"
	_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
haoyanbin's avatar
haoyanbin committed
7 8
	"go-admin/app/mobile/service"
	"go-admin/app/mobile/service/dto"
haoyanbin's avatar
haoyanbin committed
9
	"go-admin/common/actions"
haoyanbin's avatar
haoyanbin committed
10
	"strconv"
haoyanbin's avatar
haoyanbin committed
11 12 13 14 15 16
)

type OrgPlayer struct {
	api.Api
}

haoyanbin's avatar
haoyanbin committed
17 18 19
// GetPage <手机端>获取球员列表
// @Summary <手机端>获取球员列表
// @Description <手机端>获取球员列表
haoyanbin's avatar
haoyanbin committed
20
// @Tags <手机端>球员数据
haoyanbin's avatar
haoyanbin committed
21 22 23 24
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Param data body dto.OrgPlayerGetPageReq true "body"
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
haoyanbin's avatar
haoyanbin committed
25
// @Router /mobile/v1/org-player [get]
haoyanbin's avatar
haoyanbin committed
26 27 28 29
// @Security Bearer
func (e OrgPlayer) GetPage(c *gin.Context) {
	req := dto.OrgPlayerGetPageReq{}
	s := service.OrgPlayer{}
haoyanbin's avatar
haoyanbin committed
30 31 32

	err := c.Bind(&req)
	err = e.MakeContext(c).
haoyanbin's avatar
haoyanbin committed
33 34 35 36 37 38 39 40 41 42 43 44 45
		MakeOrm().
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	p := actions.GetPermissionFromContext(c)
	list := make([]dto.OrgPlayerGetPageReply, 0)
	var count int64

haoyanbin's avatar
haoyanbin committed
46 47 48
	userId := c.GetInt64("userId")
	req.PlayerUserId = strconv.FormatInt(userId, 10)

haoyanbin's avatar
haoyanbin committed
49 50
	err = s.GetPage(&req, p, &list, &count)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
51
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
52 53 54 55 56 57
		return
	}

	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}

haoyanbin's avatar
haoyanbin committed
58 59 60
// Get <手机端>获取球员详情
// @Summary <手机端>获取球员详情
// @Description <手机端>获取球员详情
haoyanbin's avatar
haoyanbin committed
61
// @Tags <手机端>球员数据
haoyanbin's avatar
haoyanbin committed
62 63
// @Param id path string false "id"
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
haoyanbin's avatar
haoyanbin committed
64
// @Router /mobile/v1/org-player/{id} [get]
haoyanbin's avatar
haoyanbin committed
65 66 67 68
// @Security Bearer
func (e OrgPlayer) Get(c *gin.Context) {
	req := dto.OrgPlayerGetReq{}
	s := service.OrgPlayer{}
haoyanbin's avatar
1  
haoyanbin committed
69 70
	//err := c.Bind(&req)
	err := e.MakeContext(c).
haoyanbin's avatar
haoyanbin committed
71
		MakeOrm().
haoyanbin's avatar
1  
haoyanbin committed
72
		Bind(&req).
haoyanbin's avatar
haoyanbin committed
73 74 75 76 77 78 79 80 81 82 83 84
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}
	var object dto.OrgPlayerGetReply

	p := actions.GetPermissionFromContext(c)
	err = s.Get(&req, p, &object)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
85
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
86 87 88
		return
	}

haoyanbin's avatar
haoyanbin committed
89 90 91
	//总分
	var reqTotalScoringGetData dto.OrgPlayerDataGetReq
	reqTotalScoringGetData.PlayerId = strconv.Itoa(object.Id)
haoyanbin's avatar
haoyanbin committed
92

haoyanbin's avatar
haoyanbin committed
93 94
	var replyTotalScoringGetData dto.OrgPlayerDataGetReply
	err = s.GetData(&reqTotalScoringGetData, p, &replyTotalScoringGetData)
haoyanbin's avatar
haoyanbin committed
95
	if err != nil {
haoyanbin's avatar
1  
haoyanbin committed
96 97 98
		object.TotalScoring = "0"
	} else {
		object.TotalScoring = replyTotalScoringGetData.Scoring
haoyanbin's avatar
haoyanbin committed
99
	}
haoyanbin's avatar
haoyanbin committed
100

haoyanbin's avatar
haoyanbin committed
101 102 103 104 105 106 107 108
	//参加赛季
	var reqScoringGetData dto.OrgPlayerDataGetReq
	reqScoringGetData.PlayerId = strconv.Itoa(object.Id)
	reqScoringGetData.SeasonId = object.SeasonId

	var replyScoringGetData dto.OrgPlayerDataGetReply
	err = s.GetDataSeason(&reqScoringGetData, p, &replyScoringGetData)
	if err != nil {
haoyanbin's avatar
1  
haoyanbin committed
109 110 111
		object.SeasonScoring = "0"
	} else {
		object.SeasonScoring = replyScoringGetData.Scoring
haoyanbin's avatar
haoyanbin committed
112
	}
haoyanbin's avatar
haoyanbin committed
113 114 115 116 117 118 119

	//出赛次数
	var reqMatchGetData dto.OrgPlayerDataGetReq
	reqMatchGetData.PlayerId = strconv.Itoa(object.Id)

	var replyMatchGetData dto.OrgPlayerDataGetReply
	err = s.GetDataMatch(&reqMatchGetData, p, &replyMatchGetData)
haoyanbin's avatar
haoyanbin committed
120
	if err != nil {
haoyanbin's avatar
1  
haoyanbin committed
121 122 123
		object.CountMatch = "0"
	} else {
		object.CountMatch = replyMatchGetData.CountMatch
haoyanbin's avatar
haoyanbin committed
124 125
	}

haoyanbin's avatar
haoyanbin committed
126
	e.OK(object, "查询成功")
haoyanbin's avatar
haoyanbin committed
127
}
haoyanbin's avatar
haoyanbin committed
128 129 130 131

// Get <手机端>获取球员赛季数据
// @Summary <手机端>获取球员赛季数据
// @Description <手机端>获取球员赛季数据
haoyanbin's avatar
haoyanbin committed
132
// @Tags <手机端>球员数据
haoyanbin's avatar
haoyanbin committed
133
// @Param playerId path string false "playerId"
haoyanbin's avatar
haoyanbin committed
134
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
haoyanbin's avatar
haoyanbin committed
135
// @Router /mobile/v1/org-player/info [get]
haoyanbin's avatar
haoyanbin committed
136 137
// @Security Bearer
func (e OrgPlayer) GetInfo(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
138
	req := dto.OrgPlayerGetInfoReq{}
haoyanbin's avatar
haoyanbin committed
139
	s := service.OrgPlayer{}
haoyanbin's avatar
haoyanbin committed
140
	c.Bind(&req)
haoyanbin's avatar
1  
haoyanbin committed
141
	err := e.MakeContext(c).
haoyanbin's avatar
haoyanbin committed
142 143 144 145 146 147 148 149 150
		MakeOrm().
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}
	var object dto.OrgPlayerGetReply
haoyanbin's avatar
1  
haoyanbin committed
151
	reqGet := dto.OrgPlayerGetReq{PlayerId: req.PlayerId}
haoyanbin's avatar
haoyanbin committed
152 153

	p := actions.GetPermissionFromContext(c)
haoyanbin's avatar
1  
haoyanbin committed
154
	err = s.Get(&reqGet, p, &object)
haoyanbin's avatar
haoyanbin committed
155
	if err != nil {
haoyanbin's avatar
haoyanbin committed
156
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
157 158 159
		return
	}

haoyanbin's avatar
haoyanbin committed
160
	//获取当前时间范围的赛季id
haoyanbin's avatar
haoyanbin committed
161
	seasonId := s.GetNowSeasonId()
haoyanbin's avatar
haoyanbin committed
162 163 164 165
	if seasonId == "" {
		e.Error(109, err, "未获取到数据")
		return
	}
haoyanbin's avatar
haoyanbin committed
166

haoyanbin's avatar
haoyanbin committed
167
	reply := new(dto.OrgPlayerGetInfoReply)
haoyanbin's avatar
haoyanbin committed
168 169
	reply.OrgPlayerInfo = object

haoyanbin's avatar
1  
haoyanbin committed
170 171
	replyDataAvg := dto.OrgMatchInfo{}
	err = s.StatisticsScoringAvg("", seasonId, "avg", &replyDataAvg)
haoyanbin's avatar
haoyanbin committed
172
	if err != nil {
haoyanbin's avatar
haoyanbin committed
173
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
174 175
		return
	}
haoyanbin's avatar
1  
haoyanbin committed
176 177 178 179 180
	reply.DataAvg = replyDataAvg

	replyOrgMatchInfo := dto.OrgMatchInfo{}
	err = s.StatisticsScoringAvg(strconv.Itoa(req.PlayerId), seasonId, "avg", &replyOrgMatchInfo)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
181
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
1  
haoyanbin committed
182 183 184
		return
	}
	reply.OrgMatchInfo = replyOrgMatchInfo
haoyanbin's avatar
haoyanbin committed
185

haoyanbin's avatar
haoyanbin committed
186
	err, matchId := s.GetMatchId(strconv.Itoa(req.PlayerId), seasonId)
haoyanbin's avatar
haoyanbin committed
187
	var count int64
haoyanbin's avatar
haoyanbin committed
188 189

	replyGetRoundsScoring := make([]dto.OrgPlayerRoundsScoring, 0)
haoyanbin's avatar
haoyanbin committed
190
	err = s.GetRoundsScoring(&req, matchId, &replyGetRoundsScoring, &count)
haoyanbin's avatar
haoyanbin committed
191
	if err != nil {
haoyanbin's avatar
haoyanbin committed
192
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
193 194 195 196
		return
	}
	reply.RoundsScoring = replyGetRoundsScoring

haoyanbin's avatar
haoyanbin committed
197
	e.PageOK(reply, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
haoyanbin's avatar
haoyanbin committed
198 199 200 201 202 203
}

// Get <手机端>获取球员生涯数据
// @Summary <手机端>获取球员生涯数据
// @Description <手机端>获取球员生涯数据
// @Tags <手机端>球员数据
haoyanbin's avatar
haoyanbin committed
204
// @Param playerId path string false "playerId"
haoyanbin's avatar
haoyanbin committed
205
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
206
// @Router /mobile/v1/org-player/get-match-season [get]
haoyanbin's avatar
haoyanbin committed
207 208
// @Security Bearer
func (e OrgPlayer) GetOrgMatchSeason(c *gin.Context) {
haoyanbin's avatar
1  
haoyanbin committed
209
	req := dto.OrgPlayerGetInfoReq{}
haoyanbin's avatar
haoyanbin committed
210
	s := service.OrgPlayer{}
haoyanbin's avatar
1  
haoyanbin committed
211
	c.Bind(&req)
haoyanbin's avatar
1  
haoyanbin committed
212
	err := e.MakeContext(c).
haoyanbin's avatar
haoyanbin committed
213 214 215 216 217 218 219 220
		MakeOrm().
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}
haoyanbin's avatar
haoyanbin committed
221
	//生涯数据
haoyanbin's avatar
haoyanbin committed
222
	err, matchId2 := s.GetMatchId(strconv.Itoa(req.PlayerId), "")
haoyanbin's avatar
haoyanbin committed
223

haoyanbin's avatar
haoyanbin committed
224
	replyGetRoundsScoring := make([]dto.OrgPlayerRoundsScoring, 0)
haoyanbin's avatar
1  
haoyanbin committed
225 226
	var count int64
	err = s.GetSeasonRoundsScoring(&req, matchId2, &replyGetRoundsScoring, &count)
haoyanbin's avatar
haoyanbin committed
227
	if err != nil {
haoyanbin's avatar
haoyanbin committed
228
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
229 230
		return
	}
haoyanbin's avatar
1  
haoyanbin committed
231
	e.PageOK(replyGetRoundsScoring, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
haoyanbin's avatar
haoyanbin committed
232 233 234 235 236
}

// Get <手机端>获取球员精彩时刻
// @Summary <手机端>获取球员精彩时刻
// @Description <手机端>获取球员精彩时刻
haoyanbin's avatar
haoyanbin committed
237 238 239 240 241 242
// @Tags <手机端>球员数据
// @Param leagueId path string false "leagueId"
// @Param seasonId path string false "seasonId"
// @Param matchId path string false "matchId"
// @Param rounds path string false "rounds"
// @Param playerId path string false "playerId"
haoyanbin's avatar
haoyanbin committed
243
// @Param type path string false "type"
haoyanbin's avatar
haoyanbin committed
244 245 246 247 248 249
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
// @Router /mobile/v1/org-player/evaluate [get]
// @Security Bearer
func (e OrgPlayer) GetOrgMatchEvaluate(c *gin.Context) {
	req := dto.OrgPlayerGetOrgMatchEvaluateReq{}
	s := service.OrgPlayer{}
haoyanbin's avatar
haoyanbin committed
250 251
	err := c.Bind(&req)
	err = e.MakeContext(c).
haoyanbin's avatar
haoyanbin committed
252 253 254 255 256 257 258 259 260
		MakeOrm().
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

haoyanbin's avatar
haoyanbin committed
261
	list := make([]dto.OrgPlayerGetOrgMatchEvaluateReply, 0)
haoyanbin's avatar
haoyanbin committed
262 263 264 265
	var count int64

	err = s.GetOrgMatchEvaluate(&req, &list, &count)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
266
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
267 268 269
		return
	}

haoyanbin's avatar
haoyanbin committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}

// Get <手机端>获取球员评论
// @Summary <手机端>获取球员评论
// @Description <手机端>获取球员评论
// @Tags <手机端>球员数据
// @Param playerId path string false "playerId"
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
// @Router /mobile/v1/org-player/evaluate-content [get]
// @Security Bearer
func (e OrgPlayer) GetOrgMatchEvaluateContent(c *gin.Context) {
	req := dto.OrgPlayerGetOrgMatchEvaluateContentReq{}
	s := service.OrgPlayer{}
	err := c.Bind(&req)
	err = e.MakeContext(c).
		MakeOrm().
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
haoyanbin's avatar
haoyanbin committed
293 294
	}

haoyanbin's avatar
haoyanbin committed
295 296 297 298 299
	list := make([]dto.OrgPlayerGetOrgMatchEvaluateContentReply, 0)
	var count int64

	err = s.GetOrgMatchEvaluateContent(&req, &list, &count)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
300
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
301 302 303 304
		return
	}

	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
haoyanbin's avatar
haoyanbin committed
305
}
haoyanbin's avatar
haoyanbin committed
306

haoyanbin's avatar
haoyanbin committed
307 308 309
// Get <手机端>精彩时刻比赛轮次列表
// @Summary <手机端>精彩时刻比赛轮次列表
// @Description <手机端>精彩时刻比赛轮次列表
haoyanbin's avatar
haoyanbin committed
310 311 312
// @Tags <手机端>球员数据
// @Param playerId path string false "playerId"
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
haoyanbin's avatar
haoyanbin committed
313
// @Router /mobile/v1/org-player/get-rounds [get]
haoyanbin's avatar
haoyanbin committed
314 315 316 317
// @Security Bearer
func (e OrgPlayer) GetOrgRounds(c *gin.Context) {
	req := dto.GetRoundsReq{}
	s := service.OrgPlayer{}
haoyanbin's avatar
haoyanbin committed
318 319
	err := c.Bind(&req)
	err = e.MakeContext(c).
haoyanbin's avatar
haoyanbin committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333
		MakeOrm().
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	list := make([]dto.GetRoundsReply, 0)
	var count int64

	err = s.GetOrgRounds(&req, &list, &count)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
334
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
335 336 337 338 339
		return
	}

	e.OK(list, "查询成功")
}