web_data.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/creative/model/data"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/metadata"
  8. )
  9. func webVideoQuitPoints(c *bm.Context) {
  10. params := c.Request.Form
  11. cidStr := params.Get("cid")
  12. tmidStr := params.Get("tmid")
  13. ip := metadata.String(c, metadata.RemoteIP)
  14. // check params
  15. cid, err := strconv.ParseInt(cidStr, 10, 64)
  16. if err != nil {
  17. c.JSON(nil, ecode.RequestErr)
  18. return
  19. }
  20. // check user
  21. midI, ok := c.Get("mid")
  22. if !ok {
  23. c.JSON(nil, ecode.NoLogin)
  24. return
  25. }
  26. mid, _ := midI.(int64)
  27. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  28. if tmid > 0 && dataSvc.IsWhite(mid) {
  29. mid = tmid
  30. }
  31. data, err := dataSvc.VideoQuitPoints(c, cid, mid, ip)
  32. if err != nil {
  33. c.JSON(nil, err)
  34. return
  35. }
  36. c.JSON(data, nil)
  37. }
  38. func webArchive(c *bm.Context) {
  39. params := c.Request.Form
  40. aidStr := params.Get("aid")
  41. ip := metadata.String(c, metadata.RemoteIP)
  42. // check params
  43. aid, err := strconv.ParseInt(aidStr, 10, 64)
  44. if err != nil {
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. midI, ok := c.Get("mid")
  49. if !ok {
  50. c.JSON(nil, ecode.NoLogin)
  51. return
  52. }
  53. mid, _ := midI.(int64)
  54. data, err := dataSvc.ArchiveStat(c, aid, mid, ip)
  55. if err != nil {
  56. c.JSON(nil, err)
  57. return
  58. }
  59. c.JSON(data, nil)
  60. }
  61. func webArticleData(c *bm.Context) {
  62. ip := metadata.String(c, metadata.RemoteIP)
  63. // check params
  64. midI, ok := c.Get("mid")
  65. if !ok {
  66. c.JSON(nil, ecode.NoLogin)
  67. return
  68. }
  69. mid, _ := midI.(int64)
  70. data, err := artSvc.ArticleStat(c, mid, ip)
  71. if err != nil {
  72. c.JSON(nil, err)
  73. return
  74. }
  75. c.JSON(data, nil)
  76. }
  77. func base(c *bm.Context) {
  78. params := c.Request.Form
  79. tmidStr := params.Get("tmid")
  80. // check params
  81. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  82. // check user
  83. midI, ok := c.Get("mid")
  84. if !ok {
  85. c.JSON(nil, ecode.NoLogin)
  86. return
  87. }
  88. mid, _ := midI.(int64)
  89. if tmid > 0 && dataSvc.IsWhite(mid) {
  90. mid = tmid
  91. }
  92. // get data
  93. uv, _ := dataSvc.ViewerBase(c, mid)
  94. ua, _ := dataSvc.ViewerArea(c, mid)
  95. if len(uv) == 0 {
  96. uv = nil
  97. }
  98. if len(ua) == 0 {
  99. ua = nil
  100. }
  101. c.JSON(map[string]interface{}{
  102. "viewer_base": uv,
  103. "viewer_area": ua,
  104. "period": data.Tip(),
  105. }, nil)
  106. }
  107. func trend(c *bm.Context) {
  108. params := c.Request.Form
  109. tmidStr := params.Get("tmid")
  110. // check params
  111. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  112. // check user
  113. midI, ok := c.Get("mid")
  114. if !ok {
  115. c.JSON(nil, ecode.NoLogin)
  116. return
  117. }
  118. mid, _ := midI.(int64)
  119. if tmid > 0 && dataSvc.IsWhite(mid) {
  120. mid = tmid
  121. }
  122. // get data
  123. ut, _ := dataSvc.CacheTrend(c, mid)
  124. if len(ut) == 0 {
  125. ut = nil
  126. }
  127. c.JSON(ut, nil)
  128. }
  129. func action(c *bm.Context) {
  130. params := c.Request.Form
  131. month := params.Get("month")
  132. tmidStr := params.Get("tmid")
  133. // check params
  134. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  135. // check user
  136. midI, ok := c.Get("mid")
  137. if !ok {
  138. c.JSON(nil, ecode.NoLogin)
  139. return
  140. }
  141. mid, _ := midI.(int64)
  142. if tmid > 0 && dataSvc.IsWhite(mid) {
  143. mid = tmid
  144. }
  145. // get data
  146. rfd, _ := dataSvc.RelationFansDay(c, mid)
  147. rfdh, _ := dataSvc.RelationFansHistory(c, mid, month)
  148. rfm, _ := dataSvc.RelationFansMonth(c, mid)
  149. uah, _ := dataSvc.ViewerActionHour(c, mid)
  150. if len(rfd) == 0 {
  151. rfd = nil
  152. }
  153. if len(rfdh) == 0 {
  154. rfdh = nil
  155. }
  156. if len(rfm) == 0 {
  157. rfm = nil
  158. }
  159. if len(uah) == 0 {
  160. uah = nil
  161. }
  162. c.JSON(map[string]interface{}{
  163. "relation_fans_day": rfd,
  164. "relation_fans_history": rfdh,
  165. "relation_fans_month": rfm,
  166. "viewer_action_hour": uah,
  167. }, nil)
  168. }
  169. func survey(c *bm.Context) {
  170. params := c.Request.Form
  171. tyStr := params.Get("type")
  172. tmidStr := params.Get("tmid")
  173. ip := metadata.String(c, metadata.RemoteIP)
  174. // check params
  175. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  176. ty, err := strconv.Atoi(tyStr)
  177. if err != nil {
  178. c.JSON(nil, ecode.RequestErr)
  179. return
  180. }
  181. if _, ok := data.IncrTy(int8(ty)); !ok {
  182. c.JSON(nil, ecode.RequestErr)
  183. return
  184. }
  185. // check user
  186. midI, ok := c.Get("mid")
  187. if !ok {
  188. c.JSON(nil, ecode.NoLogin)
  189. return
  190. }
  191. mid, _ := midI.(int64)
  192. if tmid > 0 && dataSvc.IsWhite(mid) {
  193. mid = tmid
  194. }
  195. data, _ := dataSvc.UpIncr(c, mid, int8(ty), ip)
  196. if len(data) == 0 {
  197. data = nil
  198. }
  199. c.JSON(data, nil)
  200. }
  201. func pandect(c *bm.Context) {
  202. params := c.Request.Form
  203. tyStr := params.Get("type")
  204. tmidStr := params.Get("tmid")
  205. // check params
  206. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  207. ty, err := strconv.Atoi(tyStr)
  208. if err != nil {
  209. c.JSON(nil, ecode.RequestErr)
  210. return
  211. }
  212. if _, ok := data.IncrTy(int8(ty)); !ok {
  213. c.JSON(nil, ecode.RequestErr)
  214. return
  215. }
  216. // check user
  217. midI, ok := c.Get("mid")
  218. if !ok {
  219. c.JSON(nil, ecode.NoLogin)
  220. return
  221. }
  222. mid, _ := midI.(int64)
  223. if tmid > 0 && dataSvc.IsWhite(mid) {
  224. mid = tmid
  225. }
  226. data, _ := dataSvc.ThirtyDayArchive(c, mid, int8(ty))
  227. if len(data) == 0 {
  228. data = nil
  229. }
  230. c.JSON(data, nil)
  231. }
  232. func webFan(c *bm.Context) {
  233. params := c.Request.Form
  234. tmidStr := params.Get("tmid")
  235. ip := metadata.String(c, metadata.RemoteIP)
  236. // check user
  237. midI, ok := c.Get("mid")
  238. if !ok {
  239. c.JSON(nil, ecode.NoLogin)
  240. return
  241. }
  242. // check params
  243. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  244. mid, _ := midI.(int64)
  245. if tmid > 0 && dataSvc.IsWhite(mid) {
  246. mid = tmid
  247. }
  248. data, err := dataSvc.UpFansAnalysisForWeb(c, mid, ip)
  249. if err != nil {
  250. c.JSON(nil, err)
  251. return
  252. }
  253. c.JSON(data, nil)
  254. }
  255. func webPlaySource(c *bm.Context) {
  256. params := c.Request.Form
  257. tmidStr := params.Get("tmid")
  258. midI, ok := c.Get("mid")
  259. if !ok {
  260. c.JSON(nil, ecode.NoLogin)
  261. return
  262. }
  263. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  264. mid, _ := midI.(int64)
  265. if tmid > 0 && dataSvc.IsWhite(mid) {
  266. mid = tmid
  267. }
  268. data, err := dataSvc.UpPlaySourceAnalysis(c, mid)
  269. if err != nil {
  270. c.JSON(nil, err)
  271. return
  272. }
  273. c.JSON(data, nil)
  274. }
  275. func webArcPlayAnalysis(c *bm.Context) {
  276. params := c.Request.Form
  277. tmidStr := params.Get("tmid")
  278. cpStr := params.Get("copyright")
  279. midI, ok := c.Get("mid")
  280. ip := metadata.String(c, metadata.RemoteIP)
  281. if !ok {
  282. c.JSON(nil, ecode.NoLogin)
  283. return
  284. }
  285. cp, err := strconv.Atoi(cpStr)
  286. if err != nil {
  287. c.JSON(nil, ecode.RequestErr)
  288. return
  289. }
  290. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  291. mid, _ := midI.(int64)
  292. if tmid > 0 && dataSvc.IsWhite(mid) {
  293. mid = tmid
  294. }
  295. data, err := dataSvc.UpArcPlayAnalysis(c, mid, cp, ip)
  296. if err != nil {
  297. c.JSON(nil, err)
  298. return
  299. }
  300. c.JSON(data, nil)
  301. }
  302. func webArtThirtyDay(c *bm.Context) {
  303. params := c.Request.Form
  304. tmidStr := params.Get("tmid")
  305. tyStr := params.Get("type")
  306. midI, ok := c.Get("mid")
  307. if !ok {
  308. c.JSON(nil, ecode.NoLogin)
  309. return
  310. }
  311. ty, err := strconv.Atoi(tyStr)
  312. if err != nil {
  313. c.JSON(nil, ecode.RequestErr)
  314. return
  315. }
  316. if ok := data.CheckType(byte(ty)); !ok {
  317. c.JSON(nil, ecode.RequestErr)
  318. return
  319. }
  320. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  321. mid, _ := midI.(int64)
  322. if tmid > 0 && dataSvc.IsWhite(mid) {
  323. mid = tmid
  324. }
  325. data, err := dataSvc.ArtThirtyDay(c, mid, byte(ty))
  326. if err != nil {
  327. c.JSON(nil, err)
  328. return
  329. }
  330. c.JSON(data, nil)
  331. }
  332. func webArtRank(c *bm.Context) {
  333. params := c.Request.Form
  334. tmidStr := params.Get("tmid")
  335. tyStr := params.Get("type")
  336. midI, ok := c.Get("mid")
  337. if !ok {
  338. c.JSON(nil, ecode.NoLogin)
  339. return
  340. }
  341. ty, err := strconv.Atoi(tyStr)
  342. if err != nil {
  343. c.JSON(nil, ecode.RequestErr)
  344. return
  345. }
  346. if ok := data.CheckType(byte(ty)); !ok {
  347. c.JSON(nil, ecode.RequestErr)
  348. return
  349. }
  350. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  351. mid, _ := midI.(int64)
  352. if tmid > 0 && dataSvc.IsWhite(mid) {
  353. mid = tmid
  354. }
  355. data, err := dataSvc.ArtRank(c, mid, byte(ty))
  356. if err != nil {
  357. c.JSON(nil, err)
  358. return
  359. }
  360. c.JSON(data, nil)
  361. }
  362. func webArtReadAnalysis(c *bm.Context) {
  363. params := c.Request.Form
  364. tmidStr := params.Get("tmid")
  365. midI, ok := c.Get("mid")
  366. if !ok {
  367. c.JSON(nil, ecode.NoLogin)
  368. return
  369. }
  370. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  371. mid, _ := midI.(int64)
  372. if tmid > 0 && dataSvc.IsWhite(mid) {
  373. mid = tmid
  374. }
  375. data, err := dataSvc.ArtReadAnalysis(c, mid)
  376. if err != nil {
  377. c.JSON(nil, err)
  378. return
  379. }
  380. c.JSON(data, nil)
  381. }