match.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package http
  2. import (
  3. "fmt"
  4. "go-common/app/admin/main/activity/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. // addMatch 增加赛程
  10. func addMatch(c *bm.Context) {
  11. arg := new(model.ActMatchs)
  12. if err := c.Bind(arg); err != nil {
  13. return
  14. }
  15. if err := actSrv.DB.Create(arg).Error; err != nil {
  16. log.Error("addMatch(%v) error(%v)", arg, err)
  17. c.JSON(nil, err)
  18. return
  19. }
  20. c.JSON(nil, nil)
  21. }
  22. // saveMatch 存储赛程
  23. func saveMatch(c *bm.Context) {
  24. arg := new(model.ActMatchs)
  25. if err := c.Bind(arg); err != nil {
  26. return
  27. }
  28. if err := actSrv.DB.Model(&model.ActMatchs{ID: arg.ID}).Update(arg).Error; err != nil {
  29. log.Error("saveMatch(%v) error(%v)", arg, err)
  30. c.JSON(nil, err)
  31. return
  32. }
  33. c.JSON(nil, nil)
  34. }
  35. // matchInfo 赛程信息
  36. func matchInfo(c *bm.Context) {
  37. arg := new(model.ActMatchs)
  38. if err := c.Bind(arg); err != nil {
  39. return
  40. }
  41. if arg.ID == 0 {
  42. c.JSON(nil, ecode.RequestErr)
  43. return
  44. }
  45. if err := actSrv.DB.First(arg, arg.ID).Error; err != nil {
  46. log.Error("matcInfo(%d) error(%v)", arg.ID, err)
  47. c.JSON(nil, err)
  48. return
  49. }
  50. c.JSON(arg, nil)
  51. }
  52. // matchList 比赛对象列表
  53. func matchList(c *bm.Context) {
  54. var (
  55. err error
  56. count int
  57. list []*model.ActMatchs
  58. )
  59. v := new(struct {
  60. SID int64 `form:"sid" default:"-1"`
  61. Status int8 `form:"status" default:"-1"`
  62. Page int `form:"pn" default:"1"`
  63. Size int `form:"ps" default:"20"`
  64. })
  65. if err = c.Bind(v); err != nil {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. db := actSrv.DB
  70. if v.Page == 0 {
  71. v.Page = 1
  72. }
  73. if v.Size == 0 {
  74. v.Size = 20
  75. }
  76. if v.Status != -1 {
  77. db = db.Where("status = ?", v.Status)
  78. }
  79. if v.SID != -1 {
  80. db = db.Where("sid = ?", v.SID)
  81. }
  82. db = db.Where("status = ?", 0)
  83. if err = db.
  84. Offset((v.Page - 1) * v.Size).Limit(v.Size).
  85. Find(&list).Error; err != nil {
  86. log.Error("businessList(%d,%d) error(%v)", v.Page, v.Size, err)
  87. c.JSON(nil, err)
  88. return
  89. }
  90. if err = db.Model(&model.ActMatchs{}).Count(&count).Error; err != nil {
  91. log.Error("businessList count error(%v)", err)
  92. c.JSON(nil, err)
  93. return
  94. }
  95. data := map[string]interface{}{
  96. "data": list,
  97. "pn": v.Page,
  98. "ps": v.Size,
  99. "total": count,
  100. }
  101. c.JSONMap(data, nil)
  102. }
  103. // addMatchObject 比赛对象
  104. func addMatchObject(c *bm.Context) {
  105. arg := new(model.ActMatchsObject)
  106. if err := c.Bind(arg); err != nil {
  107. return
  108. }
  109. if err := actSrv.DB.Create(arg).Error; err != nil {
  110. log.Error("addMatch(%v) error(%v)", arg, err)
  111. c.JSON(nil, err)
  112. return
  113. }
  114. c.JSON(nil, nil)
  115. }
  116. // saveMatchObject 更新比赛对象
  117. func saveMatchObject(c *bm.Context) {
  118. arg := new(model.ActMatchsObject)
  119. if err := c.Bind(arg); err != nil {
  120. return
  121. }
  122. fmt.Println(arg.AwayName)
  123. fmt.Println(arg.HomeLogo)
  124. if err := actSrv.DB.Model(&model.ActMatchsObject{ID: arg.ID}).Update(arg).Error; err != nil {
  125. log.Error("saveMatch(%v) error(%v)", arg, err)
  126. c.JSON(nil, err)
  127. return
  128. }
  129. c.JSON(nil, nil)
  130. }
  131. // matchObjectInfo 比赛对象信息
  132. func matchObjectInfo(c *bm.Context) {
  133. arg := new(model.ActMatchsObject)
  134. if err := c.Bind(arg); err != nil {
  135. return
  136. }
  137. if arg.ID == 0 {
  138. c.JSON(nil, ecode.RequestErr)
  139. return
  140. }
  141. if err := actSrv.DB.First(arg, arg.ID).Error; err != nil {
  142. log.Error("matcInfo(%d) error(%v)", arg.ID, err)
  143. c.JSON(nil, err)
  144. return
  145. }
  146. c.JSON(arg, nil)
  147. }
  148. // matchObjectList 比赛对象列表
  149. func matchObjectList(c *bm.Context) {
  150. var (
  151. err error
  152. count int
  153. list []*model.ActMatchsObject
  154. )
  155. v := new(struct {
  156. SID int64 `form:"sid" default:"-1"`
  157. Status int8 `form:"status" default:"-1"`
  158. Page int `form:"pn" default:"1"`
  159. Size int `form:"ps" default:"20"`
  160. MatchID int `form:"match_id"`
  161. })
  162. if err = c.Bind(v); err != nil {
  163. c.JSON(nil, ecode.RequestErr)
  164. return
  165. }
  166. db := actSrv.DB
  167. if v.Page == 0 {
  168. v.Page = 1
  169. }
  170. if v.Size == 0 {
  171. v.Size = 20
  172. }
  173. if v.Status != -1 {
  174. db = db.Where("status = ?", v.Status)
  175. }
  176. if v.SID != -1 {
  177. db = db.Where("sid = ?", v.SID)
  178. }
  179. if v.MatchID != 0 {
  180. db = db.Where("match_id = ?", v.MatchID)
  181. }
  182. db = db.Where("status = ?", 0)
  183. if err = db.
  184. Offset((v.Page - 1) * v.Size).Limit(v.Size).
  185. Find(&list).Error; err != nil {
  186. log.Error("businessList(%d,%d) error(%v)", v.Page, v.Size, err)
  187. c.JSON(nil, err)
  188. return
  189. }
  190. if err = db.Model(&model.ActMatchsObject{}).Count(&count).Error; err != nil {
  191. log.Error("businessList count error(%v)", err)
  192. c.JSON(nil, err)
  193. return
  194. }
  195. data := map[string]interface{}{
  196. "data": list,
  197. "pn": v.Page,
  198. "ps": v.Size,
  199. "total": count,
  200. }
  201. c.JSONMap(data, nil)
  202. }