contest.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package http
  2. import (
  3. "go-common/app/admin/main/esports/model"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/xstr"
  7. )
  8. const _special = 1
  9. func contestInfo(c *bm.Context) {
  10. v := new(struct {
  11. ID int64 `form:"id" validate:"min=1"`
  12. })
  13. if err := c.Bind(v); err != nil {
  14. return
  15. }
  16. c.JSON(esSvc.ContestInfo(c, v.ID))
  17. }
  18. func contestList(c *bm.Context) {
  19. var (
  20. list []*model.ContestInfo
  21. cnt int64
  22. err error
  23. )
  24. v := new(struct {
  25. Pn int64 `form:"pn" validate:"min=0"`
  26. Ps int64 `form:"ps" validate:"min=0,max=50"`
  27. Mid int64 `form:"mid"`
  28. Sid int64 `form:"sid"`
  29. Sort int64 `form:"sort"`
  30. })
  31. if err = c.Bind(v); err != nil {
  32. return
  33. }
  34. if v.Pn == 0 {
  35. v.Pn = 1
  36. }
  37. if v.Ps == 0 {
  38. v.Ps = 20
  39. }
  40. if list, cnt, err = esSvc.ContestList(c, v.Mid, v.Sid, v.Pn, v.Ps, v.Sort); err != nil {
  41. c.JSON(nil, err)
  42. return
  43. }
  44. data := make(map[string]interface{}, 2)
  45. page := map[string]int64{
  46. "num": v.Pn,
  47. "size": v.Ps,
  48. "total": cnt,
  49. }
  50. data["page"] = page
  51. data["list"] = list
  52. c.JSON(data, nil)
  53. }
  54. func addContest(c *bm.Context) {
  55. var (
  56. err error
  57. tmpGids, gids []int64
  58. )
  59. v := new(model.Contest)
  60. if err = c.Bind(v); err != nil {
  61. return
  62. }
  63. if v.Special == _special && v.SpecialName == "" {
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. gidStr := c.Request.Form.Get("gids")
  68. if gidStr == "" {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. if tmpGids, err = xstr.SplitInts(gidStr); err != nil {
  73. c.JSON(nil, ecode.RequestErr)
  74. return
  75. }
  76. for _, v := range tmpGids {
  77. if v > 0 {
  78. gids = append(gids, v)
  79. }
  80. }
  81. if len(gids) == 0 {
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. if v.DataType > 0 && v.MatchID == 0 {
  86. c.JSON(nil, ecode.RequestErr)
  87. return
  88. }
  89. c.JSON(nil, esSvc.AddContest(c, v, gids))
  90. }
  91. func editContest(c *bm.Context) {
  92. var (
  93. err error
  94. tmpGids, gids []int64
  95. )
  96. v := new(model.Contest)
  97. if err = c.Bind(v); err != nil {
  98. return
  99. }
  100. if v.ID <= 0 {
  101. c.JSON(nil, ecode.RequestErr)
  102. return
  103. }
  104. if v.Special == _special && v.SpecialName == "" {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. gidStr := c.Request.Form.Get("gids")
  109. if gidStr == "" {
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. if tmpGids, err = xstr.SplitInts(gidStr); err != nil {
  114. c.JSON(nil, ecode.RequestErr)
  115. return
  116. }
  117. for _, v := range tmpGids {
  118. if v > 0 {
  119. gids = append(gids, v)
  120. }
  121. }
  122. if len(gids) == 0 {
  123. c.JSON(nil, ecode.RequestErr)
  124. return
  125. }
  126. if v.DataType > 0 && v.MatchID == 0 {
  127. c.JSON(nil, ecode.RequestErr)
  128. return
  129. }
  130. c.JSON(nil, esSvc.EditContest(c, v, gids))
  131. }
  132. func forbidContest(c *bm.Context) {
  133. v := new(struct {
  134. ID int64 `form:"id" validate:"min=1"`
  135. State int `form:"state" validate:"min=0,max=1"`
  136. })
  137. if err := c.Bind(v); err != nil {
  138. return
  139. }
  140. c.JSON(nil, esSvc.ForbidContest(c, v.ID, v.State))
  141. }