region.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/app-feed/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/metadata"
  10. )
  11. func tags(c *bm.Context) {
  12. var mid int64
  13. params := c.Request.Form
  14. if midInter, ok := c.Get("mid"); ok {
  15. mid = midInter.(int64)
  16. }
  17. // get params
  18. mobiApp := params.Get("mobi_app")
  19. device := params.Get("device")
  20. ridStr := params.Get("rid")
  21. ver := params.Get("ver")
  22. // check params
  23. rid, err := strconv.Atoi(ridStr)
  24. if err != nil {
  25. c.JSON(nil, ecode.RequestErr)
  26. return
  27. }
  28. plat := model.Plat(mobiApp, device)
  29. data, version, err := regionSvc.HotTags(c, mid, int16(rid), ver, plat, time.Now())
  30. c.JSONMap(map[string]interface{}{"data": data, "ver": version}, err)
  31. }
  32. func subTags(c *bm.Context) {
  33. var (
  34. mid int64
  35. pn, ps int
  36. err error
  37. )
  38. midInter, _ := c.Get("mid")
  39. mid = midInter.(int64)
  40. params := c.Request.Form
  41. // check params
  42. if pn, err = strconv.Atoi(params.Get("pn")); err != nil || pn < 1 {
  43. pn = 1
  44. }
  45. if ps, err = strconv.Atoi(params.Get("ps")); err != nil || ps < 1 {
  46. ps = 20
  47. }
  48. c.JSON(regionSvc.SubTags(c, mid, pn, ps), nil)
  49. }
  50. func addTag(c *bm.Context) {
  51. var mid int64
  52. params := c.Request.Form
  53. header := c.Request.Header
  54. midInter, _ := c.Get("mid")
  55. mid = midInter.(int64)
  56. // check params
  57. tid, _ := strconv.ParseInt(params.Get("tag_id"), 10, 64)
  58. if tid < 1 {
  59. c.JSON(nil, ecode.RequestErr)
  60. return
  61. }
  62. rid, _ := strconv.Atoi(params.Get("rid"))
  63. // get params
  64. mobiApp := params.Get("mobi_app")
  65. device := params.Get("device")
  66. buildStr := params.Get("build")
  67. // check params
  68. build, err := strconv.Atoi(buildStr)
  69. if err != nil {
  70. c.JSON(nil, ecode.RequestErr)
  71. return
  72. }
  73. plat := model.Plat(mobiApp, device)
  74. ip := metadata.String(c, metadata.RemoteIP)
  75. buvid := header.Get(_headerBuvid)
  76. disid := header.Get(_headerDisplayID)
  77. now := time.Now()
  78. err = regionSvc.AddTag(c, mid, tid, now)
  79. c.JSON(nil, err)
  80. if err != nil {
  81. return
  82. }
  83. regionSvc.AddTagInfoc(mid, plat, build, buvid, disid, ip, "/subscribe/tags/add", rid, tid, now)
  84. }
  85. func cancelTag(c *bm.Context) {
  86. var mid int64
  87. midInter, _ := c.Get("mid")
  88. mid = midInter.(int64)
  89. params := c.Request.Form
  90. header := c.Request.Header
  91. tidStr := params.Get("tag_id")
  92. ridStr := params.Get("rid")
  93. // check params
  94. tid, err := strconv.ParseInt(tidStr, 10, 64)
  95. if err != nil || tid < 1 {
  96. c.JSON(nil, ecode.RequestErr)
  97. return
  98. }
  99. rid, err := strconv.Atoi(ridStr)
  100. if err != nil {
  101. rid = 0
  102. }
  103. // get params
  104. mobiApp := params.Get("mobi_app")
  105. device := params.Get("device")
  106. buildStr := params.Get("build")
  107. // check params
  108. build, err := strconv.Atoi(buildStr)
  109. if err != nil {
  110. log.Error("strconv.Atoi(%s) error(%v)", buildStr, err)
  111. c.JSON(nil, ecode.RequestErr)
  112. return
  113. }
  114. plat := model.Plat(mobiApp, device)
  115. ip := metadata.String(c, metadata.RemoteIP)
  116. buvid := header.Get(_headerBuvid)
  117. disid := header.Get(_headerDisplayID)
  118. now := time.Now()
  119. err = regionSvc.CancelTag(c, mid, tid, now)
  120. c.JSON(nil, err)
  121. if err != nil {
  122. return
  123. }
  124. regionSvc.CancelTagInfoc(mid, plat, build, buvid, disid, ip, "/subscribe/tags/cancel", rid, tid, now)
  125. }