web_academy.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/creative/model/academy"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/metadata"
  9. "go-common/library/xstr"
  10. )
  11. func webAcademyTags(c *bm.Context) {
  12. // check user
  13. _, ok := c.Get("mid")
  14. if !ok {
  15. c.JSON(nil, ecode.NoLogin)
  16. return
  17. }
  18. // check params
  19. tgs, _ := acaSvc.TagList(c)
  20. c.JSON(tgs, nil)
  21. }
  22. func webAcademyArchives(c *bm.Context) {
  23. params := c.Request.Form
  24. tidsStr := params.Get("tids")
  25. bsStr := params.Get("business")
  26. pageStr := params.Get("pn")
  27. psStr := params.Get("ps")
  28. keyword := params.Get("keyword")
  29. order := params.Get("order")
  30. ip := metadata.String(c, metadata.RemoteIP)
  31. // check user
  32. _, ok := c.Get("mid")
  33. if !ok {
  34. c.JSON(nil, ecode.NoLogin)
  35. return
  36. }
  37. var (
  38. tids []int64
  39. err error
  40. )
  41. // check params
  42. if tidsStr != "" {
  43. if tids, err = xstr.SplitInts(tidsStr); err != nil {
  44. log.Error("strconv.ParseInt(%s) error(%v)", tidsStr, err)
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. }
  49. bs, err := strconv.Atoi(bsStr)
  50. if err != nil {
  51. log.Error("strconv.Atoi(%s) error(%v)", bsStr, err)
  52. c.JSON(nil, ecode.RequestErr)
  53. return
  54. }
  55. pn, err := strconv.Atoi(pageStr)
  56. if err != nil {
  57. log.Error("strconv.Atoi(%s) error(%v)", pageStr, err)
  58. c.JSON(nil, ecode.RequestErr)
  59. return
  60. }
  61. ps, err := strconv.Atoi(psStr)
  62. if err != nil {
  63. log.Error("strconv.Atoi(%s) error(%v)", psStr, err)
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. if pn == 0 {
  68. pn = 1
  69. }
  70. if ps > 20 {
  71. ps = 20
  72. }
  73. aca := &academy.EsParam{
  74. Tid: tids,
  75. Business: bs,
  76. Pn: pn,
  77. Ps: ps,
  78. Keyword: keyword,
  79. Order: order,
  80. IP: ip,
  81. }
  82. arcs, err := acaSvc.ArchivesWithES(c, aca)
  83. if err != nil {
  84. c.JSON(nil, err)
  85. return
  86. }
  87. c.JSON(arcs, nil)
  88. }
  89. func webAddFeedBack(c *bm.Context) {
  90. params := c.Request.Form
  91. category := params.Get("category")
  92. course := params.Get("course")
  93. suggest := params.Get("suggest")
  94. // check user
  95. midI, ok := c.Get("mid")
  96. if !ok {
  97. c.JSON(nil, ecode.NoLogin)
  98. return
  99. }
  100. mid, _ := midI.(int64)
  101. id, err := acaSvc.AddFeedBack(c, category, course, suggest, mid)
  102. if err != nil {
  103. c.JSON(nil, err)
  104. return
  105. }
  106. c.JSON(map[string]interface{}{
  107. "id": id,
  108. }, nil)
  109. }