archive.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package http
  2. import (
  3. "strings"
  4. "go-common/app/admin/main/search/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func archiveSearch(c *bm.Context) {
  10. form := c.Request.Form
  11. appidStr := form.Get("appid")
  12. switch appidStr {
  13. case "archive_check":
  14. archiveCheck(c)
  15. case "video":
  16. video(c)
  17. case "task_qa":
  18. taskQa(c)
  19. case "archive_commerce":
  20. archiveCommerce(c)
  21. default:
  22. c.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. }
  26. func archiveCheck(c *bm.Context) {
  27. var (
  28. err error
  29. sp = &model.ArchiveCheckParams{
  30. Bsp: &model.BasicSearchParams{},
  31. }
  32. form = c.Request.Form
  33. )
  34. if err = c.Bind(sp); err != nil {
  35. c.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. if err = c.Bind(sp.Bsp); err != nil {
  39. c.JSON(nil, ecode.RequestErr)
  40. return
  41. }
  42. orderStr := form.Get("order")
  43. if len(sp.Bsp.Order) == 1 && sp.Bsp.Order[0] == "" {
  44. sp.Bsp.Order = nil
  45. }
  46. if orderStr != "" {
  47. sp.Bsp.Order = strings.Split(orderStr, ",")
  48. }
  49. kwFieldsStr := form.Get("kw_fields")
  50. if kwFieldsStr == "" {
  51. sp.Bsp.KwFields = []string{"title", "content", "tag", "author"}
  52. } else {
  53. sp.Bsp.KwFields = strings.Split(kwFieldsStr, ",")
  54. }
  55. res, err := svr.ArchiveCheck(c, sp)
  56. if err != nil {
  57. log.Error("svr.ArchiveCheck(%v) error(%v)", sp, err)
  58. c.JSON(nil, err)
  59. return
  60. }
  61. c.JSON(res, err)
  62. }
  63. func video(c *bm.Context) {
  64. var (
  65. err error
  66. sp = &model.VideoParams{
  67. Bsp: &model.BasicSearchParams{},
  68. }
  69. form = c.Request.Form
  70. )
  71. if err = c.Bind(sp); err != nil {
  72. c.JSON(nil, ecode.RequestErr)
  73. return
  74. }
  75. if err = c.Bind(sp.Bsp); err != nil {
  76. c.JSON(nil, ecode.RequestErr)
  77. return
  78. }
  79. if form.Get("order_type") == "" {
  80. sp.OrderType = -1
  81. }
  82. if form.Get("kw_fields") == "" {
  83. sp.Bsp.KwFields = []string{"arc_title", "arc_author"}
  84. }
  85. res, err := svr.Video(c, sp)
  86. if err != nil {
  87. log.Error("svr.ArchiveCheck(%v) error(%v)", sp, err)
  88. c.JSON(nil, err)
  89. return
  90. }
  91. c.JSON(res, err)
  92. }
  93. func taskQa(c *bm.Context) {
  94. var (
  95. err error
  96. sp = &model.TaskQa{
  97. Bsp: &model.BasicSearchParams{},
  98. }
  99. )
  100. if err = c.Bind(sp); err != nil {
  101. c.JSON(nil, ecode.RequestErr)
  102. return
  103. }
  104. if err = c.Bind(sp.Bsp); err != nil {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. res, err := svr.TaskQa(c, sp)
  109. if err != nil {
  110. log.Error("svr.TaskQa(%v) error(%v)", sp, err)
  111. c.JSON(nil, err)
  112. return
  113. }
  114. c.JSON(res, err)
  115. }
  116. func archiveCommerce(c *bm.Context) {
  117. var (
  118. err error
  119. sp = &model.ArchiveCommerce{
  120. Bsp: &model.BasicSearchParams{},
  121. }
  122. )
  123. if err = c.Bind(sp); err != nil {
  124. c.JSON(nil, ecode.RequestErr)
  125. return
  126. }
  127. if err = c.Bind(sp.Bsp); err != nil {
  128. c.JSON(nil, ecode.RequestErr)
  129. return
  130. }
  131. res, err := svr.ArchiveCommerce(c, sp)
  132. if err != nil {
  133. log.Error("svr.ArchiveCommerce(%v) error(%v)", sp, err)
  134. c.JSON(nil, err)
  135. return
  136. }
  137. c.JSON(res, err)
  138. }