channel.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/app-channel/model"
  6. "go-common/app/interface/main/app-channel/model/channel"
  7. "go-common/library/ecode"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/metadata"
  10. )
  11. const (
  12. _headerBuvid = "Buvid"
  13. )
  14. func index(c *bm.Context) {
  15. var (
  16. params = c.Request.Form
  17. mid int64
  18. cidInt int64
  19. header = c.Request.Header
  20. )
  21. mobiApp := params.Get("mobi_app")
  22. device := params.Get("device")
  23. buildStr := params.Get("build")
  24. idxStr := params.Get("idx")
  25. pullStr := params.Get("pull")
  26. loginEventStr := params.Get("login_event")
  27. cidStr := params.Get("channel_id")
  28. displayIDStr := params.Get("display_id")
  29. cname := params.Get("channel_name")
  30. qn, _ := strconv.Atoi(params.Get("qn"))
  31. fnver, _ := strconv.Atoi(params.Get("fnver"))
  32. fnval, _ := strconv.Atoi(params.Get("fnval"))
  33. build, err := strconv.Atoi(buildStr)
  34. if err != nil {
  35. c.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. displayID, err := strconv.Atoi(displayIDStr)
  39. if err != nil {
  40. c.JSON(nil, ecode.RequestErr)
  41. return
  42. }
  43. plat := model.Plat(mobiApp, device)
  44. buvid := header.Get(_headerBuvid)
  45. // disid := header.Get(_headerDisplayID)
  46. pull, err := strconv.ParseBool(pullStr)
  47. if err != nil {
  48. pull = true
  49. }
  50. loginEvent, err := strconv.Atoi(loginEventStr)
  51. if err != nil {
  52. loginEvent = 0
  53. }
  54. idx, err := strconv.ParseInt(idxStr, 10, 64)
  55. if err != nil || idx < 0 {
  56. idx = 0
  57. }
  58. if cidInt, _ = strconv.ParseInt(cidStr, 10, 64); cidInt == 0 && cname == "" {
  59. c.JSON(nil, ecode.RequestErr)
  60. return
  61. }
  62. now := time.Now()
  63. if midInter, ok := c.Get("mid"); ok {
  64. mid = midInter.(int64)
  65. }
  66. data, err := channelSvc.Index(c, mid, cidInt, idx, plat, mobiApp, device, buvid, cname, build, loginEvent, displayID, qn, fnver, fnval, pull, now)
  67. c.JSON(data, err)
  68. }
  69. func index2(c *bm.Context) {
  70. var (
  71. params = c.Request.Form
  72. mid int64
  73. cidInt int64
  74. header = c.Request.Header
  75. )
  76. mobiApp := params.Get("mobi_app")
  77. device := params.Get("device")
  78. buildStr := params.Get("build")
  79. idxStr := params.Get("idx")
  80. pullStr := params.Get("pull")
  81. loginEventStr := params.Get("login_event")
  82. cidStr := params.Get("channel_id")
  83. displayIDStr := params.Get("display_id")
  84. cname := params.Get("channel_name")
  85. qn, _ := strconv.Atoi(params.Get("qn"))
  86. fnver, _ := strconv.Atoi(params.Get("fnver"))
  87. fnval, _ := strconv.Atoi(params.Get("fnval"))
  88. build, err := strconv.Atoi(buildStr)
  89. if err != nil {
  90. c.JSON(nil, ecode.RequestErr)
  91. return
  92. }
  93. displayID, err := strconv.Atoi(displayIDStr)
  94. if err != nil {
  95. c.JSON(nil, ecode.RequestErr)
  96. return
  97. }
  98. plat := model.Plat(mobiApp, device)
  99. buvid := header.Get(_headerBuvid)
  100. // disid := header.Get(_headerDisplayID)
  101. pull, err := strconv.ParseBool(pullStr)
  102. if err != nil {
  103. pull = true
  104. }
  105. loginEvent, err := strconv.Atoi(loginEventStr)
  106. if err != nil {
  107. loginEvent = 0
  108. }
  109. idx, err := strconv.ParseInt(idxStr, 10, 64)
  110. if err != nil || idx < 0 {
  111. idx = 0
  112. }
  113. if cidInt, _ = strconv.ParseInt(cidStr, 10, 64); cidInt == 0 && cname == "" {
  114. c.JSON(nil, ecode.RequestErr)
  115. return
  116. }
  117. now := time.Now()
  118. if midInter, ok := c.Get("mid"); ok {
  119. mid = midInter.(int64)
  120. }
  121. data, err := channelSvc.Index2(c, mid, cidInt, idx, plat, mobiApp, device, buvid, cname, metadata.String(c, metadata.RemoteIP), build, loginEvent, displayID, qn, fnver, fnval, pull, now)
  122. c.JSON(data, err)
  123. }
  124. func tab(c *bm.Context) {
  125. var (
  126. params = c.Request.Form
  127. mid int64
  128. cidInt int64
  129. )
  130. cidStr := params.Get("channel_id")
  131. cname := params.Get("channel_name")
  132. if midInter, ok := c.Get("mid"); ok {
  133. mid = midInter.(int64)
  134. }
  135. if cidInt, _ = strconv.ParseInt(cidStr, 10, 64); cidInt == 0 && cname == "" {
  136. c.JSON(nil, ecode.RequestErr)
  137. return
  138. }
  139. mobiApp := params.Get("mobi_app")
  140. device := params.Get("device")
  141. plat := model.Plat(mobiApp, device)
  142. c.JSON(channelSvc.Tab(c, cidInt, mid, cname, plat))
  143. }
  144. func subscribeAdd(c *bm.Context) {
  145. var (
  146. params = c.Request.Form
  147. mid int64
  148. cidInt int64
  149. err error
  150. fromInt int
  151. now = time.Now()
  152. )
  153. mobiApp := params.Get("mobi_app")
  154. device := params.Get("device")
  155. buildStr := params.Get("build")
  156. cidStr := params.Get("channel_id")
  157. fromStr := params.Get("from")
  158. build, err := strconv.Atoi(buildStr)
  159. if err != nil {
  160. c.JSON(nil, ecode.RequestErr)
  161. return
  162. }
  163. if midInter, ok := c.Get("mid"); ok {
  164. mid = midInter.(int64)
  165. }
  166. if cidInt, err = strconv.ParseInt(cidStr, 10, 64); err != nil {
  167. c.JSON(nil, ecode.RequestErr)
  168. return
  169. }
  170. fromInt, _ = strconv.Atoi(fromStr)
  171. c.JSON(nil, channelSvc.SubscribeAdd(c, mid, cidInt, now))
  172. channelSvc.OperationInfoc(mobiApp, device, "add", build, fromInt, cidInt, mid, now)
  173. }
  174. func subscribeCancel(c *bm.Context) {
  175. var (
  176. params = c.Request.Form
  177. mid int64
  178. cidInt int64
  179. err error
  180. fromInt int
  181. now = time.Now()
  182. )
  183. mobiApp := params.Get("mobi_app")
  184. device := params.Get("device")
  185. buildStr := params.Get("build")
  186. cidStr := params.Get("channel_id")
  187. fromStr := params.Get("from")
  188. build, err := strconv.Atoi(buildStr)
  189. if err != nil {
  190. c.JSON(nil, ecode.RequestErr)
  191. return
  192. }
  193. if midInter, ok := c.Get("mid"); ok {
  194. mid = midInter.(int64)
  195. }
  196. if cidInt, err = strconv.ParseInt(cidStr, 10, 64); err != nil {
  197. c.JSON(nil, ecode.RequestErr)
  198. return
  199. }
  200. fromInt, _ = strconv.Atoi(fromStr)
  201. c.JSON(nil, channelSvc.SubscribeCancel(c, mid, cidInt, now))
  202. channelSvc.OperationInfoc(mobiApp, device, "cannel", build, fromInt, cidInt, mid, now)
  203. }
  204. func subscribeUpdate(c *bm.Context) {
  205. var (
  206. params = c.Request.Form
  207. mid int64
  208. )
  209. cidStr := params.Get("channel_ids")
  210. if cidStr == "" {
  211. c.JSON(nil, ecode.RequestErr)
  212. return
  213. }
  214. if midInter, ok := c.Get("mid"); ok {
  215. mid = midInter.(int64)
  216. }
  217. c.JSON(nil, channelSvc.SubscribeUpdate(c, mid, cidStr))
  218. }
  219. func list(c *bm.Context) {
  220. param := &channel.Param{}
  221. if err := c.Bind(param); err != nil {
  222. return
  223. }
  224. if midInter, ok := c.Get("mid"); ok {
  225. param.MID = midInter.(int64)
  226. }
  227. plat := model.Plat(param.MobiApp, param.Device)
  228. limit := 18 //频道聚合页需要展示最多18个我的订阅
  229. c.JSON(channelSvc.List(c, param.MID, plat, param.Build, limit, param.Ver, param.MobiApp, param.Device, param.Lang))
  230. }
  231. func subscribe(c *bm.Context) {
  232. param := &channel.Param{}
  233. if err := c.Bind(param); err != nil {
  234. return
  235. }
  236. if midInter, ok := c.Get("mid"); ok {
  237. param.MID = midInter.(int64)
  238. }
  239. c.JSON(channelSvc.Subscribe(c, param.MID, 0))
  240. }
  241. func discover(c *bm.Context) {
  242. param := &channel.Param{}
  243. if err := c.Bind(param); err != nil {
  244. return
  245. }
  246. if midInter, ok := c.Get("mid"); ok {
  247. param.MID = midInter.(int64)
  248. }
  249. plat := model.Plat(param.MobiApp, param.Device)
  250. c.JSON(channelSvc.Discover(c, param.ID, param.MID, plat))
  251. }
  252. func category(c *bm.Context) {
  253. param := &channel.Param{}
  254. if err := c.Bind(param); err != nil {
  255. return
  256. }
  257. plat := model.Plat(param.MobiApp, param.Device)
  258. c.JSON(channelSvc.Category(c, plat))
  259. }
  260. func square(c *bm.Context) {
  261. param := &channel.ParamSquare{}
  262. if err := c.Bind(param); err != nil {
  263. return
  264. }
  265. if midInter, ok := c.Get("mid"); ok {
  266. param.MID = midInter.(int64)
  267. }
  268. buvid := c.Request.Header.Get(_headerBuvid)
  269. plat := model.Plat(param.MobiApp, param.Device)
  270. c.JSON(channelSvc.Square(c, param.MID, plat, param.Build, param.LoginEvent, param.MobiApp, param.Device, param.Lang, buvid))
  271. }
  272. func mysub(c *bm.Context) {
  273. param := &channel.Param{}
  274. if err := c.Bind(param); err != nil {
  275. return
  276. }
  277. if midInter, ok := c.Get("mid"); ok {
  278. param.MID = midInter.(int64)
  279. }
  280. c.JSON(channelSvc.Mysub(c, param.MID, 0))
  281. }
  282. func tablist(c *bm.Context) {
  283. var (
  284. params = c.Request.Form
  285. mid int64
  286. )
  287. mobiApp := params.Get("mobi_app")
  288. device := params.Get("device")
  289. buildStr := params.Get("build")
  290. cidStr := params.Get("channel_id")
  291. displayIDStr := params.Get("display_id")
  292. cname := params.Get("channel_name")
  293. fromStr := params.Get("display_id")
  294. build, err := strconv.Atoi(buildStr)
  295. if err != nil {
  296. c.JSON(nil, ecode.RequestErr)
  297. return
  298. }
  299. displayID, err := strconv.Atoi(displayIDStr)
  300. if err != nil {
  301. c.JSON(nil, ecode.RequestErr)
  302. return
  303. }
  304. plat := model.Plat(mobiApp, device)
  305. cidInt, _ := strconv.ParseInt(cidStr, 10, 64)
  306. if cidInt == 0 && cname == "" {
  307. c.JSON(nil, ecode.RequestErr)
  308. return
  309. }
  310. fromInt, err := strconv.Atoi(fromStr)
  311. if err != nil {
  312. c.JSON(nil, ecode.RequestErr)
  313. return
  314. }
  315. now := time.Now()
  316. if midInter, ok := c.Get("mid"); ok {
  317. mid = midInter.(int64)
  318. }
  319. data, err := channelSvc.TabList(c, cidInt, mid, cname, mobiApp, displayID, build, fromInt, plat, now)
  320. c.JSON(data, err)
  321. }