wild.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package http
  2. import (
  3. mdlSearch "go-common/app/interface/main/tv/model/search"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. const (
  8. _headerBuvid = "Buvid"
  9. _keyWordLen = 50
  10. )
  11. // searchAll all search .
  12. func searchAll(c *bm.Context) {
  13. var (
  14. err error
  15. v = new(mdlSearch.UserSearch)
  16. header = c.Request.Header
  17. )
  18. if err = c.Bind(v); err != nil {
  19. return
  20. }
  21. if v.Keyword == "" || len([]rune(v.Keyword)) > _keyWordLen {
  22. c.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. if v.Order == "" {
  26. v.Order = "totalrank"
  27. }
  28. if v.Page < 1 {
  29. v.Page = 1
  30. }
  31. if v.Pagesize < 1 || v.Pagesize > 20 {
  32. v.Pagesize = 20
  33. }
  34. if midInter, ok := c.Get("mid"); ok {
  35. v.MID = midInter.(int64)
  36. }
  37. v.Buvid = header.Get(_headerBuvid)
  38. c.JSON(secSvc.SearchAll(c, v))
  39. }
  40. // userSearch search by user .
  41. func userSearch(c *bm.Context) {
  42. var (
  43. err error
  44. v = new(mdlSearch.UserSearch)
  45. header = c.Request.Header
  46. )
  47. if err = c.Bind(v); err != nil {
  48. return
  49. }
  50. if v.Order == "" {
  51. v.Order = "totalrank"
  52. }
  53. if v.Order != "totalrank" && v.Order != "fans" && v.Order != "level" {
  54. c.JSON(nil, ecode.RequestErr)
  55. return
  56. }
  57. if v.OrderSort != 1 {
  58. v.OrderSort = 0
  59. }
  60. if v.FromSource == "" {
  61. v.FromSource = "app_search"
  62. }
  63. if v.Page < 1 {
  64. v.Page = 1
  65. }
  66. if v.Pagesize < 1 || v.Pagesize > 20 {
  67. v.Pagesize = 20
  68. }
  69. if midInter, ok := c.Get("mid"); ok {
  70. v.MID = midInter.(int64)
  71. }
  72. v.Buvid = header.Get(_headerBuvid)
  73. c.JSON(secSvc.UserSearch(c, v))
  74. }
  75. // pgcSearch search pgc opera and film .
  76. func pgcSearch(c *bm.Context) {
  77. var (
  78. err error
  79. v = new(mdlSearch.UserSearch)
  80. header = c.Request.Header
  81. )
  82. if err = c.Bind(v); err != nil {
  83. return
  84. }
  85. if v.Keyword == "" || len([]rune(v.Keyword)) > _keyWordLen {
  86. c.JSON(nil, ecode.RequestErr)
  87. return
  88. }
  89. if v.Page < 1 {
  90. v.Page = 1
  91. }
  92. if v.Pagesize < 1 || v.Pagesize > 20 {
  93. v.Pagesize = 20
  94. }
  95. if midInter, ok := c.Get("mid"); ok {
  96. v.MID = midInter.(int64)
  97. }
  98. v.Buvid = header.Get(_headerBuvid)
  99. c.JSON(secSvc.PgcSearch(c, v))
  100. }