game_task.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. package task
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "go.uber.org/zap"
  5. "log-server/global"
  6. "log-server/model/common/response"
  7. "log-server/model/task/request"
  8. taskResponse "log-server/model/task/response"
  9. "log-server/utils"
  10. "net/http"
  11. "time"
  12. )
  13. type GameTaskApi struct {
  14. }
  15. // @Tags gameTask
  16. // @Summary 创建游戏任务
  17. // @Security ApiKeyAuth
  18. // @accept application/json
  19. // @Produce application/json
  20. // @Param data body request.GameTaskRequest true
  21. // @Success 200 {object} response.Response{msg=string} "创建游戏任务"
  22. // @Router /gameTask/create [post]
  23. func (s *GameTaskApi) CreateGameTask(c *gin.Context) {
  24. var api request.GameTaskRequest
  25. _ = c.ShouldBindJSON(&api)
  26. if err := utils.Verify(api, utils.GameTaskVerify); err != nil {
  27. response.FailWithMessage(err.Error(), c)
  28. return
  29. }
  30. if err := taskService.CreateGameTask(api); err != nil {
  31. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  32. response.FailWithMessage("创建失败 "+err.Error(), c)
  33. } else {
  34. response.OkWithMessage("创建成功", c)
  35. }
  36. }
  37. // @Tags gameTask
  38. // @Summary 游戏任务列表
  39. // @Security ApiKeyAuth
  40. // @accept application/json
  41. // @Produce application/json
  42. // @Param data body request.GetCardListRequest true "游戏任务列表"
  43. // @Success 200 {object} response.Response{data=response.GetGameTaskListReply,msg=string} "分页游戏任务列表,返回包括列表,总数,页码,每页数量"
  44. // @Router /gameTask/getGameTaskList [post]
  45. func (s *GameTaskApi) GetGameTaskList(c *gin.Context) {
  46. var paramsInfo request.GetGameTaskListRequest
  47. _ = c.ShouldBindJSON(&paramsInfo)
  48. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  49. response.FailWithMessage(err.Error(), c)
  50. return
  51. }
  52. if list, option, total, err := taskService.GetGameTaskInfoList(paramsInfo.GameTask, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc); err != nil {
  53. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  54. response.FailWithMessage("获取失败"+err.Error(), c)
  55. } else {
  56. response.OkWithDetailed(taskResponse.GameTaskPageResult{
  57. List: list,
  58. OptionList: option,
  59. Total: total,
  60. Page: paramsInfo.Page,
  61. PageSize: paramsInfo.PageSize,
  62. }, "获取成功", c)
  63. }
  64. }
  65. //获取启用状态的任务
  66. func (s *GameTaskApi) GetUsedGameTaskList(c *gin.Context) {
  67. var paramsInfo request.GetGameTaskListRequest
  68. _ = c.ShouldBindJSON(&paramsInfo)
  69. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  70. response.FailWithMessage(err.Error(), c)
  71. return
  72. }
  73. if list, option, total, err := taskService.GetUsedGameTaskInfoList(paramsInfo.GameTask, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc); err != nil {
  74. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  75. response.FailWithMessage("获取失败"+err.Error(), c)
  76. } else {
  77. response.OkWithDetailed(taskResponse.GameTaskPageResult{
  78. List: list,
  79. OptionList: option,
  80. Total: total,
  81. Page: paramsInfo.Page,
  82. PageSize: paramsInfo.PageSize,
  83. }, "获取成功", c)
  84. }
  85. }
  86. // @Tags gameTask
  87. // @Summary 根据id获取游戏任务信息
  88. // @Security ApiKeyAuth
  89. // @accept application/json
  90. // @Produce application/json
  91. // @Param data body request.GetById true "根据id获取游戏任务信息"
  92. // @Success 200 {object} response.Response{data=systemRes.GameTaskRequest} "根据id获取游戏任务信息,返回包括游戏任务信息详情"
  93. // @Router /gameTask/getGameTaskById [post]
  94. func (s *GameTaskApi) GetGameTaskById(c *gin.Context) {
  95. var idInfo request.GetById
  96. _ = c.ShouldBindJSON(&idInfo)
  97. if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
  98. response.FailWithMessage(err.Error(), c)
  99. return
  100. }
  101. api, err := taskService.GetGameTaskById(idInfo.ID)
  102. if err != nil {
  103. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  104. response.FailWithMessage("获取失败 "+err.Error(), c)
  105. } else {
  106. response.OkWithDetailed(api, "获取成功", c)
  107. }
  108. }
  109. // @Tags GameTask
  110. // @Summary 游戏任务信息状态
  111. // @Security ApiKeyAuth
  112. // @accept application/json
  113. // @Produce application/json
  114. // @Param data body request.UpdateGameTaskStatusRequest true "id, 状态"
  115. // @Success 200 {object} response.Response{msg=string} "修改游戏任务信息状态"
  116. // @Router /gameTask/statusOperation [post]
  117. func (s *GameTaskApi) StatusOperation(c *gin.Context) {
  118. var paramsInfo request.UpdateGameTaskStatusRequest
  119. _ = c.ShouldBindJSON(&paramsInfo)
  120. if paramsInfo.TaskId == 0 {
  121. response.FailWithMessage("Id不能为空", c)
  122. return
  123. }
  124. if paramsInfo.Status == 0 {
  125. response.FailWithMessage("状态值不能为空", c)
  126. return
  127. }
  128. if err := taskService.UpdateGameTaskStatus(paramsInfo); err != nil {
  129. global.GVA_LOG.Error("修改失败!", zap.Error(err))
  130. response.FailWithMessage(err.Error(), c)
  131. } else {
  132. response.OkWithMessage("修改成功", c)
  133. }
  134. }
  135. // @Tags gameTask
  136. // @Summary 更新游戏任务
  137. // @Security ApiKeyAuth
  138. // @accept application/json
  139. // @Produce application/json
  140. // @Param data body request.GameTaskRequest true
  141. // @Success 200 {object} response.Response{msg=string} "更新游戏任务"
  142. // @Router /gameTask/update [post]
  143. func (s *GameTaskApi) UpdateGameTask(c *gin.Context) {
  144. var api request.GameTaskRequest
  145. _ = c.ShouldBindJSON(&api)
  146. if err := utils.Verify(api, utils.GameTaskVerify); err != nil {
  147. response.FailWithMessage(err.Error(), c)
  148. return
  149. }
  150. if err := taskService.UpdateGameTask(api); err != nil {
  151. global.GVA_LOG.Error("更新失败!", zap.Error(err))
  152. response.FailWithMessage("更新失败 "+err.Error(), c)
  153. } else {
  154. response.OkWithMessage("更新成功", c)
  155. }
  156. }
  157. // @Tags gameTask
  158. // @Summary 删除gameTask
  159. // @Security ApiKeyAuth
  160. // @accept application/json
  161. // @Produce application/json
  162. // @Param data body task.GameTask true "ID"
  163. // @Success 200 {object} response.Response{msg=string} "删除gameTask"
  164. // @Router /gameTask/delete [post]
  165. func (s *GameTaskApi) DeleteGameTask(c *gin.Context) {
  166. var api request.GameTaskRequest
  167. _ = c.ShouldBindJSON(&api)
  168. if err := utils.Verify(api, utils.TaskIdVerify); err != nil {
  169. response.FailWithMessage(err.Error(), c)
  170. return
  171. }
  172. if err := taskService.DeleteGameTask(api); err != nil {
  173. global.GVA_LOG.Error("删除失败!", zap.Error(err))
  174. response.FailWithMessage("删除失败 "+err.Error(), c)
  175. } else {
  176. response.OkWithMessage("删除成功", c)
  177. }
  178. }
  179. // @Tags gameTask
  180. // @Summary 游戏任务列表
  181. // @Security ApiKeyAuth
  182. // @accept application/json
  183. // @Produce application/json
  184. // @Param data body request.GetCardListRequest true "游戏任务列表"
  185. // @Success 200 {object} response.Response{data=response.GetGameTaskListReply,msg=string} "分页游戏任务列表,返回包括列表,总数,页码,每页数量"
  186. // @Router /gameTask/getGameTaskTargetList [post]
  187. func (s *GameTaskApi) GetGameTaskTargetList(c *gin.Context) {
  188. var paramsInfo request.GetGameTaskListTargetRequest
  189. _ = c.ShouldBindJSON(&paramsInfo)
  190. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  191. response.FailWithMessage(err.Error(), c)
  192. return
  193. }
  194. if list, total, err := taskService.GetGameTaskTargetInfoList(paramsInfo.GameTargetCompleteRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc, false); err != nil {
  195. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  196. response.FailWithMessage("获取失败 "+err.Error(), c)
  197. } else {
  198. response.OkWithDetailed(response.PageResult{
  199. List: list,
  200. Total: total,
  201. Page: paramsInfo.Page,
  202. PageSize: paramsInfo.PageSize,
  203. }, "获取成功", c)
  204. }
  205. }
  206. // @Tags gameTask
  207. // @Summary 腾讯游戏任务列表
  208. // @Security ApiKeyAuth
  209. // @accept application/json
  210. // @Produce application/json
  211. // @Param data body request.GetCardListRequest true "腾讯游戏任务列表"
  212. // @Success 200 {object} response.Response{data=response.GetGameTaskListReply,msg=string} "分页游戏任务列表,返回包括列表,总数,页码,每页数量"
  213. // @Router /gameTask/getGameTxTaskList [post]
  214. func (s *GameTaskApi) GetGameTxTaskList(c *gin.Context) {
  215. var paramsInfo request.GetGameTaskListTargetRequest
  216. _ = c.ShouldBindJSON(&paramsInfo)
  217. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  218. response.FailWithMessage(err.Error(), c)
  219. return
  220. }
  221. if list, total, err := taskService.GetGameTaskTargetInfoList(paramsInfo.GameTargetCompleteRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc, true); err != nil {
  222. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  223. response.FailWithMessage("获取失败 "+err.Error(), c)
  224. } else {
  225. response.OkWithDetailed(response.PageResult{
  226. List: list,
  227. Total: total,
  228. Page: paramsInfo.Page,
  229. PageSize: paramsInfo.PageSize,
  230. }, "获取成功", c)
  231. }
  232. }
  233. // @Tags gameTask
  234. // @Summary 根据id获取游戏任务信息
  235. // @Security ApiKeyAuth
  236. // @accept application/json
  237. // @Produce application/json
  238. // @Param data body request.GetById true "根据id获取游戏任务目标信息"
  239. // @Success 200 {object} response.Response{data=response.GetGameTargetComplete} "根据id获取游戏任务信息,返回包括游戏任务信息详情"
  240. // @Router /gameTask/getGameTaskTargetById [post]
  241. func (s *GameTaskApi) GetGameTaskTargetById(c *gin.Context) {
  242. var idInfo request.GetGameTaskTargetByIdRequest
  243. _ = c.ShouldBindJSON(&idInfo)
  244. if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
  245. response.FailWithMessage(err.Error(), c)
  246. return
  247. }
  248. date := time.Now().Format("2006-01-02")
  249. if idInfo.CreateDate != date {
  250. response.FailWithMessage("只能修改当天的任务", c)
  251. return
  252. }
  253. api, err := taskService.GetGameTaskTargetById(idInfo.ID, date)
  254. if err != nil {
  255. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  256. response.FailWithMessage("获取失败 "+err.Error(), c)
  257. } else {
  258. response.OkWithDetailed(api, "获取成功", c)
  259. }
  260. }
  261. // @Tags gameTask
  262. // @Summary 更新游戏任务目标
  263. // @Security ApiKeyAuth
  264. // @accept application/json
  265. // @Produce application/json
  266. // @Param data body request.GameTaskRequest true
  267. // @Success 200 {object} response.Response{msg=string} "更新游戏任务目标"
  268. // @Router /gameTask/updateTarget [post]
  269. func (s *GameTaskApi) UpdateGameTaskTarget(c *gin.Context) {
  270. var api request.UpdateGameTaskTargetRequest
  271. _ = c.ShouldBindJSON(&api)
  272. if err := utils.Verify(api, utils.UpdateTargetVerify); err != nil {
  273. response.FailWithMessage(err.Error(), c)
  274. return
  275. }
  276. if err := taskService.UpdateGameTaskTarget(api); err != nil {
  277. global.GVA_LOG.Error("更新失败!", zap.Error(err))
  278. response.FailWithMessage("更新失败 "+err.Error(), c)
  279. } else {
  280. response.OkWithMessage("更新成功", c)
  281. }
  282. }
  283. // @Tags gameTask
  284. // @Summary 群控任务目标
  285. // @Security ApiKeyAuth
  286. // @accept application/json
  287. // @Produce application/json
  288. // @Param data Query new_date true
  289. // @Success 200 {object} []control.TargetStatisticsReply "更新游戏任务目标"
  290. // @Router /gameTask/targetStatistics [get]
  291. func (s *GameTaskApi) TargetStatistics(c *gin.Context) {
  292. date := c.Query("new_date")
  293. if date == "" {
  294. response.FailWithMessage("获取失败!参数错误!", c)
  295. return
  296. }
  297. if list, err := taskService.TargetStatistics(date); err != nil {
  298. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  299. response.FailWithMessage("获取失败 "+err.Error(), c)
  300. } else {
  301. c.JSON(http.StatusOK, response.ControlResult{
  302. Data: list,
  303. Message: "获取成功",
  304. Code: 1000,
  305. Date: date,
  306. })
  307. return
  308. }
  309. }
  310. // @Tags gameTask
  311. // @Summary 数优每日统计
  312. // @Security ApiKeyAuth
  313. // @accept application/json
  314. // @Produce application/json
  315. // @Param data Query create_date true
  316. // @Success 200 {object} []response.GameTargetStatistics "数优每日统计数据"
  317. // @Router /gameTask/everyDayStatistics [post]
  318. func (s *GameTaskApi) EveryDayStatistics(c *gin.Context) {
  319. var paramsInfo request.GameTaskStatisticsRequest
  320. _ = c.ShouldBindJSON(&paramsInfo)
  321. if data, err := taskService.DayStatisticsData(paramsInfo); err != nil {
  322. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  323. response.FailWithMessage("获取失败 "+err.Error(), c)
  324. } else {
  325. response.OkWithDetailed(response.PageResult{
  326. List: data,
  327. Total: 0,
  328. Page: 1,
  329. PageSize: 10,
  330. }, "获取成功", c)
  331. }
  332. }
  333. // @Tags gameTask
  334. // @Summary 数优每月统计
  335. // @Security ApiKeyAuth
  336. // @accept application/json
  337. // @Produce application/json
  338. // @Param data Query create_date true
  339. // @Success 200 {object} []response.GameTargetStatistics "数优每月统计数据"
  340. // @Router /gameTask/monthStatistics [post]
  341. func (s *GameTaskApi) MonthStatistics(c *gin.Context) {
  342. if data, err := taskService.MonthStatisticsData(); err != nil {
  343. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  344. response.FailWithMessage("获取失败 "+err.Error(), c)
  345. } else {
  346. response.OkWithDetailed(response.PageResult{
  347. List: data,
  348. Total: 0,
  349. Page: 1,
  350. PageSize: 10,
  351. }, "获取成功", c)
  352. }
  353. }
  354. // @Tags gameTask
  355. // @Summary 数优游戏统计
  356. // @Security ApiKeyAuth
  357. // @accept application/json
  358. // @Produce application/json
  359. // @Param data Query create_date true
  360. // @Success 200 {object} []response.GameTargetStatistics "数优游戏统计数据"
  361. // @Router /gameTask/gameStatistics [post]
  362. func (s *GameTaskApi) GameStatistics(c *gin.Context) {
  363. var paramsInfo request.CreateDateReply
  364. _ = c.ShouldBindJSON(&paramsInfo)
  365. if data, err := taskService.GameStatisticsData(paramsInfo.CreateDate); err != nil {
  366. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  367. response.FailWithMessage("获取失败 "+err.Error(), c)
  368. } else {
  369. response.OkWithDetailed(response.PageResult{
  370. List: data,
  371. Total: 10,
  372. Page: 1,
  373. PageSize: 10,
  374. }, "获取成功", c)
  375. }
  376. }
  377. // @Tags gameTask
  378. // @Summary 负责人端口游戏列表
  379. // @Security ApiKeyAuth
  380. // @accept application/json
  381. // @Produce application/json
  382. // @Param data Query create_date true
  383. // @Success 200 {object} []response.GameTargetStatistics "负责人端口游戏列表"
  384. // @Router /gameTask/gameList [post]
  385. func (s *GameTaskApi) GameList(c *gin.Context) {
  386. var paramsInfo request.GameListRequest
  387. _ = c.ShouldBindJSON(&paramsInfo)
  388. if data, err := taskService.GameStatisticsList(paramsInfo); err != nil {
  389. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  390. response.FailWithMessage("获取失败 "+err.Error(), c)
  391. } else {
  392. response.OkWithDetailed(response.PageResult{
  393. List: data,
  394. Total: 10,
  395. Page: 1,
  396. PageSize: 10,
  397. }, "获取成功", c)
  398. }
  399. }
  400. // @Tags gameTask
  401. // @Summary 重置付费
  402. // @Security ApiKeyAuth
  403. // @accept application/json
  404. // @Produce application/json
  405. // @Param data body request.GameTaskRequest true
  406. // @Success 200 {object} response.Response{msg=string} "更新游戏任务目标"
  407. // @Router /gameTask/taskResetFee [post]
  408. func (s *GameTaskApi) TaskResetFee(c *gin.Context) {
  409. var api request.GameTaskRequest
  410. _ = c.ShouldBindJSON(&api)
  411. if err := utils.Verify(api, utils.TaskIdVerify); err != nil {
  412. response.FailWithMessage(err.Error(), c)
  413. return
  414. }
  415. if err := taskService.TaskResetFee(api); err != nil {
  416. global.GVA_LOG.Error("重置付费失败!", zap.Error(err))
  417. response.FailWithMessage("重置付费失败 "+err.Error(), c)
  418. } else {
  419. response.OkWithMessage("重置付费成功", c)
  420. }
  421. }
  422. // @Tags gameTask
  423. // @Summary 根据id获取游戏可付费账号
  424. // @Security ApiKeyAuth
  425. // @accept application/json
  426. // @Produce application/json
  427. // @Param data body request.GetById true "根据id获取可付费账号列表"
  428. // @Success 200 {object} response.Response{data=response.GetGameTargetComplete} "根据id获取可付费账号列表"
  429. // @Router /gameTask/getFeeAccountList [post]
  430. func (s *GameTaskApi) GetFeeAccountList(c *gin.Context) {
  431. var idInfo request.GetGameTaskTargetByIdRequest
  432. _ = c.ShouldBindJSON(&idInfo)
  433. if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
  434. response.FailWithMessage(err.Error(), c)
  435. return
  436. }
  437. date := time.Now().Format("2006-01-02")
  438. if idInfo.CreateDate != date {
  439. response.FailWithMessage("只能获取当天的任务", c)
  440. return
  441. }
  442. api, err := taskService.GetFeeAccountList(idInfo.ID)
  443. if err != nil {
  444. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  445. response.FailWithMessage("获取失败 "+err.Error(), c)
  446. } else {
  447. response.OkWithDetailed(api, "获取成功", c)
  448. }
  449. }
  450. // @Tags gameTask
  451. // @Summary 导出任务目标Excel
  452. // @Security ApiKeyAuth
  453. // @accept application/json
  454. // @Produce application/octet-stream
  455. // @Param data body request.GameTargetCompleteRequest true "导出Excel文件信息"
  456. // @Success 200
  457. // @Router /gameTask/taskTargetExport [post]
  458. func (e *GameTaskApi) TaskTargetExport(c *gin.Context) {
  459. var excelInfo request.ExcelInfo
  460. _ = c.ShouldBindJSON(&excelInfo)
  461. paramsInfo := excelInfo.InfoList
  462. paramsInfo.PageSize = 300
  463. paramsInfo.Page = 1
  464. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  465. response.FailWithMessage(err.Error(), c)
  466. return
  467. }
  468. list, _, err := taskService.GetGameTaskTargetInfoList(paramsInfo.GameTargetCompleteRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc, false)
  469. if err != nil {
  470. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  471. response.FailWithMessage("获取失败 "+err.Error(), c)
  472. }
  473. filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
  474. err = taskService.TaskStatisticsList2Excel(list, filePath)
  475. if err != nil {
  476. global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
  477. response.FailWithMessage("转换Excel失败", c)
  478. return
  479. }
  480. c.Writer.Header().Add("success", "true")
  481. c.File(filePath)
  482. }