123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- package http
- import (
- "strconv"
- "go-common/app/interface/main/creative/model/data"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/metadata"
- )
- func webVideoQuitPoints(c *bm.Context) {
- params := c.Request.Form
- cidStr := params.Get("cid")
- tmidStr := params.Get("tmid")
- ip := metadata.String(c, metadata.RemoteIP)
- // check params
- cid, err := strconv.ParseInt(cidStr, 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, err := dataSvc.VideoQuitPoints(c, cid, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webArchive(c *bm.Context) {
- params := c.Request.Form
- aidStr := params.Get("aid")
- ip := metadata.String(c, metadata.RemoteIP)
- // check params
- aid, err := strconv.ParseInt(aidStr, 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- data, err := dataSvc.ArchiveStat(c, aid, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webArticleData(c *bm.Context) {
- ip := metadata.String(c, metadata.RemoteIP)
- // check params
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- data, err := artSvc.ArticleStat(c, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func base(c *bm.Context) {
- params := c.Request.Form
- tmidStr := params.Get("tmid")
- // check params
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- // get data
- uv, _ := dataSvc.ViewerBase(c, mid)
- ua, _ := dataSvc.ViewerArea(c, mid)
- if len(uv) == 0 {
- uv = nil
- }
- if len(ua) == 0 {
- ua = nil
- }
- c.JSON(map[string]interface{}{
- "viewer_base": uv,
- "viewer_area": ua,
- "period": data.Tip(),
- }, nil)
- }
- func trend(c *bm.Context) {
- params := c.Request.Form
- tmidStr := params.Get("tmid")
- // check params
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- // get data
- ut, _ := dataSvc.CacheTrend(c, mid)
- if len(ut) == 0 {
- ut = nil
- }
- c.JSON(ut, nil)
- }
- func action(c *bm.Context) {
- params := c.Request.Form
- month := params.Get("month")
- tmidStr := params.Get("tmid")
- // check params
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- // get data
- rfd, _ := dataSvc.RelationFansDay(c, mid)
- rfdh, _ := dataSvc.RelationFansHistory(c, mid, month)
- rfm, _ := dataSvc.RelationFansMonth(c, mid)
- uah, _ := dataSvc.ViewerActionHour(c, mid)
- if len(rfd) == 0 {
- rfd = nil
- }
- if len(rfdh) == 0 {
- rfdh = nil
- }
- if len(rfm) == 0 {
- rfm = nil
- }
- if len(uah) == 0 {
- uah = nil
- }
- c.JSON(map[string]interface{}{
- "relation_fans_day": rfd,
- "relation_fans_history": rfdh,
- "relation_fans_month": rfm,
- "viewer_action_hour": uah,
- }, nil)
- }
- func survey(c *bm.Context) {
- params := c.Request.Form
- tyStr := params.Get("type")
- tmidStr := params.Get("tmid")
- ip := metadata.String(c, metadata.RemoteIP)
- // check params
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- ty, err := strconv.Atoi(tyStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if _, ok := data.IncrTy(int8(ty)); !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, _ := dataSvc.UpIncr(c, mid, int8(ty), ip)
- if len(data) == 0 {
- data = nil
- }
- c.JSON(data, nil)
- }
- func pandect(c *bm.Context) {
- params := c.Request.Form
- tyStr := params.Get("type")
- tmidStr := params.Get("tmid")
- // check params
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- ty, err := strconv.Atoi(tyStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if _, ok := data.IncrTy(int8(ty)); !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, _ := dataSvc.ThirtyDayArchive(c, mid, int8(ty))
- if len(data) == 0 {
- data = nil
- }
- c.JSON(data, nil)
- }
- func webFan(c *bm.Context) {
- params := c.Request.Form
- tmidStr := params.Get("tmid")
- ip := metadata.String(c, metadata.RemoteIP)
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- // check params
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, err := dataSvc.UpFansAnalysisForWeb(c, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webPlaySource(c *bm.Context) {
- params := c.Request.Form
- tmidStr := params.Get("tmid")
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, err := dataSvc.UpPlaySourceAnalysis(c, mid)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webArcPlayAnalysis(c *bm.Context) {
- params := c.Request.Form
- tmidStr := params.Get("tmid")
- cpStr := params.Get("copyright")
- midI, ok := c.Get("mid")
- ip := metadata.String(c, metadata.RemoteIP)
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- cp, err := strconv.Atoi(cpStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, err := dataSvc.UpArcPlayAnalysis(c, mid, cp, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webArtThirtyDay(c *bm.Context) {
- params := c.Request.Form
- tmidStr := params.Get("tmid")
- tyStr := params.Get("type")
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- ty, err := strconv.Atoi(tyStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := data.CheckType(byte(ty)); !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, err := dataSvc.ArtThirtyDay(c, mid, byte(ty))
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webArtRank(c *bm.Context) {
- params := c.Request.Form
- tmidStr := params.Get("tmid")
- tyStr := params.Get("type")
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- ty, err := strconv.Atoi(tyStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := data.CheckType(byte(ty)); !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, err := dataSvc.ArtRank(c, mid, byte(ty))
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webArtReadAnalysis(c *bm.Context) {
- params := c.Request.Form
- tmidStr := params.Get("tmid")
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- mid, _ := midI.(int64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- mid = tmid
- }
- data, err := dataSvc.ArtReadAnalysis(c, mid)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
|