team.go 2.4 KB

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