match.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. package http
  2. import (
  3. "time"
  4. "go-common/app/interface/main/esports/model"
  5. arcmdl "go-common/app/service/main/archive/api"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func filterMatch(c *bm.Context) {
  10. p := new(model.ParamFilter)
  11. if err := c.Bind(p); err != nil {
  12. return
  13. }
  14. if p.Stime != "" {
  15. if _, err := time.Parse("2006-01-02", p.Stime); err != nil {
  16. c.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. }
  20. c.JSON(eSvc.FilterMatch(c, p))
  21. }
  22. func listContest(c *bm.Context) {
  23. var (
  24. mid int64
  25. err error
  26. total int
  27. list []*model.Contest
  28. )
  29. if midStr, ok := c.Get("mid"); ok {
  30. mid = midStr.(int64)
  31. }
  32. p := new(model.ParamContest)
  33. if err = c.Bind(p); err != nil {
  34. return
  35. }
  36. if p.Stime != "" {
  37. if _, err = time.Parse("2006-01-02", p.Stime); err != nil {
  38. c.JSON(nil, ecode.RequestErr)
  39. return
  40. }
  41. }
  42. if p.Etime != "" {
  43. if _, err = time.Parse("2006-01-02", p.Etime); err != nil {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. }
  48. if list, total, err = eSvc.ListContest(c, mid, p); err != nil {
  49. c.JSON(nil, err)
  50. return
  51. }
  52. data := make(map[string]interface{}, 2)
  53. page := map[string]int{
  54. "num": p.Pn,
  55. "size": p.Ps,
  56. "total": total,
  57. }
  58. data["page"] = page
  59. data["list"] = list
  60. c.JSON(data, nil)
  61. }
  62. func appContest(c *bm.Context) {
  63. var (
  64. mid int64
  65. err error
  66. total int
  67. list []*model.Contest
  68. )
  69. if midStr, ok := c.Get("mid"); ok {
  70. mid = midStr.(int64)
  71. }
  72. p := new(model.ParamContest)
  73. if err = c.Bind(p); err != nil {
  74. return
  75. }
  76. if p.Stime != "" {
  77. if _, err = time.Parse("2006-01-02", p.Stime); err != nil {
  78. c.JSON(nil, ecode.RequestErr)
  79. return
  80. }
  81. p.Etime = p.Stime
  82. }
  83. if list, total, err = eSvc.ListContest(c, mid, p); err != nil {
  84. c.JSON(nil, err)
  85. return
  86. }
  87. data := make(map[string]interface{}, 2)
  88. page := map[string]int{
  89. "num": p.Pn,
  90. "size": p.Ps,
  91. "total": total,
  92. }
  93. data["page"] = page
  94. data["list"] = list
  95. c.JSON(data, nil)
  96. }
  97. func calendar(c *bm.Context) {
  98. var err error
  99. p := new(model.ParamFilter)
  100. if err = c.Bind(p); err != nil {
  101. return
  102. }
  103. if _, err = time.Parse("2006-01-02", p.Stime); err != nil {
  104. c.JSON(nil, ecode.RequestErr)
  105. return
  106. }
  107. if _, err = time.Parse("2006-01-02", p.Etime); err != nil {
  108. c.JSON(nil, ecode.RequestErr)
  109. return
  110. }
  111. c.JSON(eSvc.Calendar(c, p))
  112. }
  113. func filterVideo(c *bm.Context) {
  114. p := new(model.ParamFilter)
  115. if err := c.Bind(p); err != nil {
  116. return
  117. }
  118. c.JSON(eSvc.FilterVideo(c, p))
  119. }
  120. func listVideo(c *bm.Context) {
  121. var (
  122. err error
  123. total int
  124. list []*arcmdl.Arc
  125. )
  126. p := new(model.ParamVideo)
  127. if err = c.Bind(p); err != nil {
  128. return
  129. }
  130. if list, total, err = eSvc.ListVideo(c, p); err != nil {
  131. c.JSON(nil, err)
  132. return
  133. }
  134. data := make(map[string]interface{}, 2)
  135. page := map[string]int{
  136. "num": p.Pn,
  137. "size": p.Ps,
  138. "total": total,
  139. }
  140. data["page"] = page
  141. data["list"] = list
  142. c.JSON(data, nil)
  143. }
  144. func actVideos(c *bm.Context) {
  145. var (
  146. err error
  147. )
  148. param := new(struct {
  149. MmID int64 `form:"mm_id" validate:"gt=0"`
  150. })
  151. if err = c.Bind(param); err != nil {
  152. return
  153. }
  154. c.JSON(eSvc.ActModules(c, param.MmID))
  155. }
  156. func active(c *bm.Context) {
  157. var (
  158. err error
  159. )
  160. param := new(struct {
  161. Aid int64 `form:"aid" validate:"gt=0"`
  162. })
  163. if err = c.Bind(param); err != nil {
  164. return
  165. }
  166. c.JSON(eSvc.ActPage(c, param.Aid))
  167. }
  168. func actPoints(c *bm.Context) {
  169. var (
  170. mid int64
  171. err error
  172. total int
  173. list []*model.Contest
  174. )
  175. if midStr, ok := c.Get("mid"); ok {
  176. mid = midStr.(int64)
  177. }
  178. p := new(model.ParamActPoint)
  179. if err = c.Bind(p); err != nil {
  180. return
  181. }
  182. if list, total, err = eSvc.ActPoints(c, mid, p); err != nil {
  183. c.JSON(nil, err)
  184. return
  185. }
  186. data := make(map[string]interface{}, 2)
  187. page := map[string]int{
  188. "num": p.Pn,
  189. "size": p.Ps,
  190. "total": total,
  191. }
  192. data["page"] = page
  193. data["list"] = list
  194. c.JSON(data, nil)
  195. }
  196. func actKnockout(c *bm.Context) {
  197. var (
  198. err error
  199. )
  200. param := new(struct {
  201. MdID int64 `form:"md_id" validate:"gt=0"`
  202. })
  203. if err = c.Bind(param); err != nil {
  204. return
  205. }
  206. c.JSON(eSvc.ActKnockout(c, param.MdID))
  207. }
  208. func actTop(c *bm.Context) {
  209. var (
  210. mid int64
  211. err error
  212. total int
  213. list []*model.Contest
  214. )
  215. if midStr, ok := c.Get("mid"); ok {
  216. mid = midStr.(int64)
  217. }
  218. p := new(model.ParamActTop)
  219. if err = c.Bind(p); err != nil {
  220. return
  221. }
  222. if p.Stime != "" {
  223. if _, err = time.Parse("2006-01-02", p.Stime); err != nil {
  224. c.JSON(nil, ecode.RequestErr)
  225. return
  226. }
  227. }
  228. if p.Etime != "" {
  229. if _, err = time.Parse("2006-01-02", p.Etime); err != nil {
  230. c.JSON(nil, ecode.RequestErr)
  231. return
  232. }
  233. }
  234. if list, total, err = eSvc.ActTop(c, mid, p); err != nil {
  235. c.JSON(nil, err)
  236. return
  237. }
  238. data := make(map[string]interface{}, 2)
  239. page := map[string]int{
  240. "num": p.Pn,
  241. "size": p.Ps,
  242. "total": total,
  243. }
  244. data["page"] = page
  245. data["list"] = list
  246. c.JSON(data, nil)
  247. }
  248. func search(c *bm.Context) {
  249. var (
  250. mid int64
  251. buvid string
  252. err error
  253. )
  254. p := new(model.ParamSearch)
  255. if err = c.Bind(p); err != nil {
  256. return
  257. }
  258. if ck, err := c.Request.Cookie("buvid3"); err == nil {
  259. buvid = ck.Value
  260. }
  261. if midInter, ok := c.Get("mid"); ok {
  262. mid = midInter.(int64)
  263. }
  264. c.JSON(eSvc.Search(c, mid, p, buvid))
  265. }
  266. func season(c *bm.Context) {
  267. var (
  268. err error
  269. total int
  270. list []*model.Season
  271. )
  272. p := new(model.ParamSeason)
  273. if err = c.Bind(p); err != nil {
  274. return
  275. }
  276. if list, total, err = eSvc.Season(c, p); err != nil {
  277. c.JSON(nil, err)
  278. return
  279. }
  280. data := make(map[string]interface{}, 2)
  281. page := map[string]int{
  282. "num": p.Pn,
  283. "size": p.Ps,
  284. "total": total,
  285. }
  286. data["page"] = page
  287. data["list"] = list
  288. c.JSON(data, nil)
  289. }
  290. func appSeason(c *bm.Context) {
  291. var (
  292. err error
  293. total int
  294. list []*model.Season
  295. )
  296. p := new(model.ParamSeason)
  297. if err = c.Bind(p); err != nil {
  298. return
  299. }
  300. if list, total, err = eSvc.AppSeason(c, p); err != nil {
  301. c.JSON(nil, err)
  302. return
  303. }
  304. data := make(map[string]interface{}, 2)
  305. page := map[string]int{
  306. "num": p.Pn,
  307. "size": p.Ps,
  308. "total": total,
  309. }
  310. data["page"] = page
  311. data["list"] = list
  312. c.JSON(data, nil)
  313. }
  314. func contest(c *bm.Context) {
  315. var (
  316. mid int64
  317. err error
  318. )
  319. if midStr, ok := c.Get("mid"); ok {
  320. mid = midStr.(int64)
  321. }
  322. param := new(struct {
  323. Cid int64 `form:"cid" validate:"gt=0"`
  324. })
  325. if err = c.Bind(param); err != nil {
  326. return
  327. }
  328. c.JSON(eSvc.Contest(c, mid, param.Cid))
  329. }
  330. func recent(c *bm.Context) {
  331. var (
  332. mid int64
  333. err error
  334. )
  335. if midStr, ok := c.Get("mid"); ok {
  336. mid = midStr.(int64)
  337. }
  338. param := &model.ParamCDRecent{}
  339. if err = c.Bind(param); err != nil {
  340. return
  341. }
  342. c.JSON(eSvc.Recent(c, mid, param))
  343. }