view.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/app-intl/model"
  6. "go-common/app/interface/main/app-intl/model/view"
  7. "go-common/library/ecode"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/metadata"
  10. )
  11. const (
  12. _viewPath = "/x/intl/view"
  13. _viewPagePath = "/x/intl/view/page"
  14. )
  15. var (
  16. // _dislike is.
  17. _dislike = []*view.Dislike{
  18. {
  19. ID: 5,
  20. Name: "标题党/封面党",
  21. },
  22. {
  23. ID: 6,
  24. Name: "内容质量差",
  25. },
  26. {
  27. ID: 7,
  28. Name: "内容/封面令人不适",
  29. },
  30. {
  31. ID: 8,
  32. Name: "营销广告",
  33. },
  34. }
  35. )
  36. // viewIndex view handler
  37. func viewIndex(c *bm.Context) {
  38. var (
  39. mid, aid, movieID int64
  40. err error
  41. )
  42. params := c.Request.Form
  43. header := c.Request.Header
  44. // get params
  45. aidStr := params.Get("aid")
  46. movieidStr := params.Get("movie_id")
  47. mobiApp := params.Get("mobi_app")
  48. device := params.Get("device")
  49. ak := params.Get("access_key")
  50. buildStr := params.Get("build")
  51. from := params.Get("from")
  52. trackid := params.Get("trackid")
  53. network := params.Get("network")
  54. adExtra := params.Get("ad_extra")
  55. locale := params.Get("locale")
  56. // check params
  57. if aidStr == "" && movieidStr == "" {
  58. c.JSON(nil, ecode.RequestErr)
  59. return
  60. }
  61. if aidStr != "" && aidStr != "0" {
  62. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  63. c.JSON(nil, ecode.RequestErr)
  64. return
  65. }
  66. } else if movieidStr != "" && movieidStr != "0" {
  67. if movieID, err = strconv.ParseInt(movieidStr, 10, 64); err != nil {
  68. c.JSON(nil, ecode.RequestErr)
  69. return
  70. }
  71. }
  72. if aid < 1 && movieID < 1 {
  73. c.JSON(nil, ecode.RequestErr)
  74. return
  75. }
  76. build, err := strconv.Atoi(buildStr)
  77. if err != nil {
  78. c.JSON(nil, ecode.RequestErr)
  79. return
  80. }
  81. plat := model.Plat(mobiApp, device)
  82. buvid := header.Get("Buvid")
  83. disid := header.Get("Display-ID")
  84. cdnIP := header.Get("X-Cache-Server-Addr")
  85. if midInter, ok := c.Get("mid"); ok {
  86. mid = midInter.(int64)
  87. }
  88. autoplay, _ := strconv.Atoi(params.Get("autoplay"))
  89. now := time.Now()
  90. // view
  91. ip := metadata.String(c, metadata.RemoteIP)
  92. viewSvc.ViewInfoc(mid, int(plat), trackid, aidStr, ip, _viewPath, buildStr, buvid, disid, from, now, err, autoplay)
  93. data, err := viewSvc.View(c, mid, aid, movieID, plat, build, ak, mobiApp, device, buvid, cdnIP, network, adExtra, from, now, locale)
  94. if err != nil {
  95. c.JSON(nil, err)
  96. return
  97. }
  98. data.Dislikes = _dislike
  99. c.JSON(data, nil)
  100. viewSvc.RelateInfoc(mid, aid, int(plat), trackid, buildStr, buvid, disid, ip, _viewPath, data.ReturnCode, data.UserFeature, from, data.Relates, now, data.IsRec)
  101. }
  102. // viewPage view page handler.
  103. func viewPage(c *bm.Context) {
  104. var (
  105. mid, aid int64
  106. build int
  107. err error
  108. )
  109. params := c.Request.Form
  110. header := c.Request.Header
  111. // get params
  112. aidStr := params.Get("aid")
  113. mobiApp := params.Get("mobi_app")
  114. device := params.Get("device")
  115. ak := params.Get("access_key")
  116. buildStr := params.Get("build")
  117. from := params.Get("from")
  118. trackid := params.Get("trackid")
  119. locale := params.Get("locale")
  120. // check params
  121. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  122. c.JSON(nil, ecode.RequestErr)
  123. return
  124. }
  125. if aid < 1 {
  126. c.JSON(nil, ecode.RequestErr)
  127. return
  128. }
  129. if build, err = strconv.Atoi(buildStr); err != nil {
  130. c.JSON(nil, ecode.RequestErr)
  131. return
  132. }
  133. plat := model.Plat(mobiApp, device)
  134. buvid := header.Get("Buvid")
  135. disid := header.Get("Display-ID")
  136. cdnIP := header.Get("X-Cache-Server-Addr")
  137. if midInter, ok := c.Get("mid"); ok {
  138. mid = midInter.(int64)
  139. }
  140. autoplay, _ := strconv.Atoi(params.Get("autoplay"))
  141. ip := metadata.String(c, metadata.RemoteIP)
  142. now := time.Now()
  143. // view page
  144. viewSvc.ViewInfoc(mid, int(plat), trackid, aidStr, ip, _viewPagePath, buildStr, buvid, disid, from, now, err, autoplay)
  145. data, err := viewSvc.ViewPage(c, mid, aid, 0, plat, build, ak, mobiApp, device, cdnIP, false, now, locale)
  146. if err != nil {
  147. c.JSON(nil, err)
  148. return
  149. }
  150. c.JSON(data, nil)
  151. }