season.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. func seasonInfo(c *bm.Context) {
  9. v := new(struct {
  10. ID int64 `form:"id" validate:"min=1"`
  11. })
  12. if err := c.Bind(v); err != nil {
  13. return
  14. }
  15. c.JSON(esSvc.SeasonInfo(c, v.ID))
  16. }
  17. func seasonList(c *bm.Context) {
  18. var (
  19. list []*model.SeasonInfo
  20. cnt int64
  21. err error
  22. )
  23. v := new(struct {
  24. Mid int64 `form:"mid"`
  25. Pn int64 `form:"pn" validate:"min=0"`
  26. Ps int64 `form:"ps" validate:"min=0,max=30"`
  27. })
  28. if err = c.Bind(v); err != nil {
  29. return
  30. }
  31. if v.Pn == 0 {
  32. v.Pn = 1
  33. }
  34. if v.Ps == 0 {
  35. v.Ps = 20
  36. }
  37. if list, cnt, err = esSvc.SeasonList(c, v.Mid, v.Pn, v.Ps); err != nil {
  38. c.JSON(nil, err)
  39. return
  40. }
  41. data := make(map[string]interface{}, 2)
  42. page := map[string]int64{
  43. "num": v.Pn,
  44. "size": v.Ps,
  45. "count": cnt,
  46. }
  47. data["page"] = page
  48. data["list"] = list
  49. c.JSON(data, nil)
  50. }
  51. func addSeason(c *bm.Context) {
  52. var (
  53. err error
  54. tmpGids, gids []int64
  55. )
  56. v := new(model.Season)
  57. if err = c.Bind(v); err != nil {
  58. return
  59. }
  60. gidStr := c.Request.Form.Get("gids")
  61. if gidStr == "" {
  62. c.JSON(nil, ecode.RequestErr)
  63. return
  64. }
  65. if tmpGids, err = xstr.SplitInts(gidStr); err != nil {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. for _, v := range tmpGids {
  70. if v > 0 {
  71. gids = append(gids, v)
  72. }
  73. }
  74. if len(gids) == 0 {
  75. c.JSON(nil, ecode.RequestErr)
  76. return
  77. }
  78. c.JSON(nil, esSvc.AddSeason(c, v, gids))
  79. }
  80. func editSeason(c *bm.Context) {
  81. var (
  82. err error
  83. tmpGids, gids []int64
  84. )
  85. v := new(model.Season)
  86. if err = c.Bind(v); err != nil {
  87. return
  88. }
  89. if v.ID <= 0 {
  90. c.JSON(nil, ecode.RequestErr)
  91. return
  92. }
  93. gidStr := c.Request.Form.Get("gids")
  94. if gidStr == "" {
  95. c.JSON(nil, ecode.RequestErr)
  96. return
  97. }
  98. if tmpGids, err = xstr.SplitInts(gidStr); err != nil {
  99. c.JSON(nil, ecode.RequestErr)
  100. return
  101. }
  102. for _, v := range tmpGids {
  103. if v > 0 {
  104. gids = append(gids, v)
  105. }
  106. }
  107. if len(gids) == 0 {
  108. c.JSON(nil, ecode.RequestErr)
  109. return
  110. }
  111. c.JSON(nil, esSvc.EditSeason(c, v, gids))
  112. }
  113. func forbidSeason(c *bm.Context) {
  114. v := new(struct {
  115. ID int64 `form:"id" validate:"min=1"`
  116. State int `form:"state" validate:"min=0,max=1"`
  117. })
  118. if err := c.Bind(v); err != nil {
  119. return
  120. }
  121. c.JSON(nil, esSvc.ForbidSeason(c, v.ID, v.State))
  122. }