ranking.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/web/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func ranking(c *bm.Context) {
  9. var (
  10. rid int64
  11. rankType, day, arcType int
  12. err error
  13. )
  14. params := c.Request.Form
  15. ridStr := params.Get("rid")
  16. rankTypeStr := params.Get("type")
  17. dayStr := params.Get("day")
  18. arcTypeStr := params.Get("arc_type")
  19. if rid, err = strconv.ParseInt(ridStr, 10, 64); err != nil || rid < 0 {
  20. rid = 0
  21. }
  22. if rankType, err = strconv.Atoi(rankTypeStr); err != nil {
  23. rankType = 1
  24. }
  25. if day, err = strconv.Atoi(dayStr); err != nil {
  26. day = 3
  27. }
  28. if arcType, err = strconv.Atoi(arcTypeStr); err != nil {
  29. arcType = 0
  30. }
  31. if err = checkType(rid, rankType, day, arcType); err != nil {
  32. c.JSON(nil, err)
  33. return
  34. }
  35. c.JSON(webSvc.Ranking(c, int16(rid), rankType, model.DayType[day], model.ArcType[arcType]))
  36. }
  37. func checkType(rid int64, rankType, day, arcType int) (err error) {
  38. if _, ok := model.RankType[rankType]; !ok {
  39. err = ecode.RequestErr
  40. return
  41. }
  42. if _, ok := model.DayType[day]; !ok {
  43. err = ecode.RequestErr
  44. return
  45. }
  46. if _, ok := model.ArcType[arcType]; !ok {
  47. err = ecode.RequestErr
  48. }
  49. // bangumi and rookie not have recent contribution
  50. if (rid == 33 || rankType == 3) && arcType == 1 {
  51. err = ecode.RequestErr
  52. }
  53. return
  54. }
  55. func rankingIndex(c *bm.Context) {
  56. var (
  57. day int
  58. err error
  59. )
  60. params := c.Request.Form
  61. dayStr := params.Get("day")
  62. if day, err = strconv.Atoi(dayStr); err != nil {
  63. day = 3
  64. }
  65. if err = checkIndexDay(day); err != nil {
  66. c.JSON(nil, err)
  67. return
  68. }
  69. c.JSON(webSvc.RankingIndex(c, day))
  70. }
  71. func rankingRegion(c *bm.Context) {
  72. var (
  73. day, original int
  74. rid int64
  75. err error
  76. )
  77. params := c.Request.Form
  78. ridStr := params.Get("rid")
  79. dayStr := params.Get("day")
  80. originalStr := params.Get("original")
  81. if rid, err = strconv.ParseInt(ridStr, 10, 64); err != nil || rid <= 0 {
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. if day, err = strconv.Atoi(dayStr); err != nil {
  86. day = 3
  87. }
  88. if _, ok := model.DayType[day]; !ok {
  89. c.JSON(nil, ecode.RequestErr)
  90. return
  91. }
  92. if original, err = strconv.Atoi(originalStr); err != nil {
  93. original = 0
  94. } else if original != 1 && original != 0 {
  95. original = 0
  96. }
  97. c.JSON(webSvc.RankingRegion(c, int16(rid), day, original))
  98. }
  99. func rankingRecommend(c *bm.Context) {
  100. var (
  101. rid int64
  102. err error
  103. )
  104. params := c.Request.Form
  105. ridStr := params.Get("rid")
  106. if rid, err = strconv.ParseInt(ridStr, 10, 64); err != nil || rid <= 0 {
  107. c.JSON(nil, ecode.RequestErr)
  108. return
  109. }
  110. c.JSON(webSvc.RankingRecommend(c, int16(rid)))
  111. }
  112. func rankingTag(c *bm.Context) {
  113. var (
  114. rid, tagID int64
  115. err error
  116. )
  117. params := c.Request.Form
  118. ridStr := params.Get("rid")
  119. tagIDStr := params.Get("tag_id")
  120. if rid, err = strconv.ParseInt(ridStr, 10, 64); err != nil || rid <= 0 {
  121. c.JSON(nil, ecode.RequestErr)
  122. return
  123. }
  124. if tagID, err = strconv.ParseInt(tagIDStr, 10, 64); err != nil || tagID <= 0 {
  125. c.JSON(nil, ecode.RequestErr)
  126. return
  127. }
  128. c.JSON(webSvc.RankingTag(c, int16(rid), tagID))
  129. }
  130. func regionCustom(c *bm.Context) {
  131. c.JSON(webSvc.RegionCustom(c))
  132. }
  133. func checkIndexDay(day int) (err error) {
  134. err = ecode.RequestErr
  135. for _, dayItem := range model.IndexDayType {
  136. if day == dayItem {
  137. err = nil
  138. return
  139. }
  140. }
  141. return
  142. }