123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- package http
- import (
- "context"
- "strconv"
- "go-common/app/interface/main/creative/model/data"
- artmdl "go-common/app/interface/openplatform/article/model"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/metadata"
- "go-common/library/sync/errgroup"
- )
- func converTmid(c *bm.Context, mid int64) (retMid int64) {
- tmidStr := c.Request.Form.Get("tmid")
- tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
- if tmid > 0 && dataSvc.IsWhite(mid) {
- retMid = tmid
- } else {
- retMid = mid
- }
- return
- }
- func appDataArc(c *bm.Context) {
- params := c.Request.Form
- aidStr := params.Get("aid")
- ip := metadata.String(c, metadata.RemoteIP)
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- // check params
- aid, err := strconv.ParseInt(aidStr, 10, 64)
- if err != nil {
- log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- mid = converTmid(c, mid)
- arcStat, err := dataSvc.ArchiveStat(c, aid, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- _, vds, _ := arcSvc.Videos(c, mid, aid, ip)
- arcStat.Videos = vds
- c.JSON(arcStat, nil)
- }
- func appDataVideoQuit(c *bm.Context) {
- params := c.Request.Form
- cidStr := params.Get("cid")
- ip := metadata.String(c, metadata.RemoteIP)
- // check user
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- // check params
- cid, err := strconv.ParseInt(cidStr, 10, 64)
- if err != nil {
- log.Error("strconv.ParseInt(%s) error(%v)", cidStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- mid = converTmid(c, mid)
- pts, err := dataSvc.AppVideoQuitPoints(c, cid, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(pts, nil)
- }
- func appFan(c *bm.Context) {
- req := c.Request
- params := req.Form
- tyStr := params.Get("type")
- ip := metadata.String(c, metadata.RemoteIP)
- // check user
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- var (
- err error
- ty int
- fan *data.AppFan
- )
- ty, err = strconv.Atoi(tyStr)
- if err != nil {
- log.Error("strconv.Atoi(%s) error(%v)", tyStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- mid = converTmid(c, mid)
- fan, err = dataSvc.UpFansAnalysisForApp(c, mid, ty, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(fan, nil)
- }
- func appFanRank(c *bm.Context) {
- req := c.Request
- params := req.Form
- tyStr := params.Get("type")
- ip := metadata.String(c, metadata.RemoteIP)
- // check user
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- var (
- err error
- ty int
- rk map[string][]*data.RankInfo
- )
- ty, err = strconv.Atoi(tyStr)
- if err != nil {
- log.Error("strconv.Atoi(%s) error(%v)", tyStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- mid = converTmid(c, mid)
- rk, err = dataSvc.FanRankApp(c, mid, ty, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(rk, nil)
- }
- func appOverView(c *bm.Context) {
- req := c.Request
- params := req.Form
- tyStr := params.Get("type")
- ip := metadata.String(c, metadata.RemoteIP)
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- var (
- err error
- ty int
- ao *data.AppOverView
- )
- ty, err = strconv.Atoi(tyStr)
- if err != nil {
- log.Error("strconv.Atoi(%s) error(%v)", tyStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- mid = converTmid(c, mid)
- ao, err = dataSvc.OverView(c, mid, int8(ty), ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(ao, nil)
- }
- func appArchiveAnalyze(c *bm.Context) {
- params := c.Request.Form
- aidStr := params.Get("aid")
- ip := metadata.String(c, metadata.RemoteIP)
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- aid, err := strconv.ParseInt(aidStr, 10, 64)
- if err != nil {
- log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- mid = converTmid(c, mid)
- arcStat, err := dataSvc.ArchiveAnalyze(c, aid, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- _, vds, _ := arcSvc.Videos(c, mid, aid, ip)
- arcStat.Videos = vds
- c.JSON(arcStat, nil)
- }
- func appVideoRetention(c *bm.Context) {
- params := c.Request.Form
- cidStr := params.Get("cid")
- ip := metadata.String(c, metadata.RemoteIP)
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- cid, err := strconv.ParseInt(cidStr, 10, 64)
- if err != nil {
- log.Error("strconv.ParseInt(%s) error(%v)", cidStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- mid = converTmid(c, mid)
- pts, err := dataSvc.VideoRetention(c, cid, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(pts, nil)
- }
- func appDataArticle(c *bm.Context) {
- ip := metadata.String(c, metadata.RemoteIP)
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- var (
- artStat artmdl.UpStat
- artIncr []*artmdl.ThirtyDayArticle
- g = &errgroup.Group{}
- ctx = context.TODO()
- )
- mid = converTmid(c, mid)
- g.Go(func() error {
- artStat, _ = artSvc.ArticleStat(ctx, mid, ip)
- return nil
- })
- g.Go(func() error {
- artIncr, _ = dataSvc.ThirtyDayArticle(ctx, mid, ip)
- return nil
- })
- g.Wait()
- c.JSON(map[string]interface{}{
- "stat": artStat,
- "incr": artIncr,
- }, nil)
- }
|