123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- package http
- import (
- "strconv"
- "time"
- "go-common/app/interface/main/app-channel/model"
- "go-common/app/interface/main/app-channel/model/channel"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/metadata"
- )
- const (
- _headerBuvid = "Buvid"
- )
- func index(c *bm.Context) {
- var (
- params = c.Request.Form
- mid int64
- cidInt int64
- header = c.Request.Header
- )
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- buildStr := params.Get("build")
- idxStr := params.Get("idx")
- pullStr := params.Get("pull")
- loginEventStr := params.Get("login_event")
- cidStr := params.Get("channel_id")
- displayIDStr := params.Get("display_id")
- cname := params.Get("channel_name")
- qn, _ := strconv.Atoi(params.Get("qn"))
- fnver, _ := strconv.Atoi(params.Get("fnver"))
- fnval, _ := strconv.Atoi(params.Get("fnval"))
- build, err := strconv.Atoi(buildStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- displayID, err := strconv.Atoi(displayIDStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- plat := model.Plat(mobiApp, device)
- buvid := header.Get(_headerBuvid)
- // disid := header.Get(_headerDisplayID)
- pull, err := strconv.ParseBool(pullStr)
- if err != nil {
- pull = true
- }
- loginEvent, err := strconv.Atoi(loginEventStr)
- if err != nil {
- loginEvent = 0
- }
- idx, err := strconv.ParseInt(idxStr, 10, 64)
- if err != nil || idx < 0 {
- idx = 0
- }
- if cidInt, _ = strconv.ParseInt(cidStr, 10, 64); cidInt == 0 && cname == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- now := time.Now()
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- data, err := channelSvc.Index(c, mid, cidInt, idx, plat, mobiApp, device, buvid, cname, build, loginEvent, displayID, qn, fnver, fnval, pull, now)
- c.JSON(data, err)
- }
- func index2(c *bm.Context) {
- var (
- params = c.Request.Form
- mid int64
- cidInt int64
- header = c.Request.Header
- )
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- buildStr := params.Get("build")
- idxStr := params.Get("idx")
- pullStr := params.Get("pull")
- loginEventStr := params.Get("login_event")
- cidStr := params.Get("channel_id")
- displayIDStr := params.Get("display_id")
- cname := params.Get("channel_name")
- qn, _ := strconv.Atoi(params.Get("qn"))
- fnver, _ := strconv.Atoi(params.Get("fnver"))
- fnval, _ := strconv.Atoi(params.Get("fnval"))
- build, err := strconv.Atoi(buildStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- displayID, err := strconv.Atoi(displayIDStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- plat := model.Plat(mobiApp, device)
- buvid := header.Get(_headerBuvid)
- // disid := header.Get(_headerDisplayID)
- pull, err := strconv.ParseBool(pullStr)
- if err != nil {
- pull = true
- }
- loginEvent, err := strconv.Atoi(loginEventStr)
- if err != nil {
- loginEvent = 0
- }
- idx, err := strconv.ParseInt(idxStr, 10, 64)
- if err != nil || idx < 0 {
- idx = 0
- }
- if cidInt, _ = strconv.ParseInt(cidStr, 10, 64); cidInt == 0 && cname == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- now := time.Now()
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- 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)
- c.JSON(data, err)
- }
- func tab(c *bm.Context) {
- var (
- params = c.Request.Form
- mid int64
- cidInt int64
- )
- cidStr := params.Get("channel_id")
- cname := params.Get("channel_name")
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- if cidInt, _ = strconv.ParseInt(cidStr, 10, 64); cidInt == 0 && cname == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- plat := model.Plat(mobiApp, device)
- c.JSON(channelSvc.Tab(c, cidInt, mid, cname, plat))
- }
- func subscribeAdd(c *bm.Context) {
- var (
- params = c.Request.Form
- mid int64
- cidInt int64
- err error
- fromInt int
- now = time.Now()
- )
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- buildStr := params.Get("build")
- cidStr := params.Get("channel_id")
- fromStr := params.Get("from")
- build, err := strconv.Atoi(buildStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- if cidInt, err = strconv.ParseInt(cidStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- fromInt, _ = strconv.Atoi(fromStr)
- c.JSON(nil, channelSvc.SubscribeAdd(c, mid, cidInt, now))
- channelSvc.OperationInfoc(mobiApp, device, "add", build, fromInt, cidInt, mid, now)
- }
- func subscribeCancel(c *bm.Context) {
- var (
- params = c.Request.Form
- mid int64
- cidInt int64
- err error
- fromInt int
- now = time.Now()
- )
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- buildStr := params.Get("build")
- cidStr := params.Get("channel_id")
- fromStr := params.Get("from")
- build, err := strconv.Atoi(buildStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- if cidInt, err = strconv.ParseInt(cidStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- fromInt, _ = strconv.Atoi(fromStr)
- c.JSON(nil, channelSvc.SubscribeCancel(c, mid, cidInt, now))
- channelSvc.OperationInfoc(mobiApp, device, "cannel", build, fromInt, cidInt, mid, now)
- }
- func subscribeUpdate(c *bm.Context) {
- var (
- params = c.Request.Form
- mid int64
- )
- cidStr := params.Get("channel_ids")
- if cidStr == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- c.JSON(nil, channelSvc.SubscribeUpdate(c, mid, cidStr))
- }
- func list(c *bm.Context) {
- param := &channel.Param{}
- if err := c.Bind(param); err != nil {
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- param.MID = midInter.(int64)
- }
- plat := model.Plat(param.MobiApp, param.Device)
- limit := 18 //频道聚合页需要展示最多18个我的订阅
- c.JSON(channelSvc.List(c, param.MID, plat, param.Build, limit, param.Ver, param.MobiApp, param.Device, param.Lang))
- }
- func subscribe(c *bm.Context) {
- param := &channel.Param{}
- if err := c.Bind(param); err != nil {
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- param.MID = midInter.(int64)
- }
- c.JSON(channelSvc.Subscribe(c, param.MID, 0))
- }
- func discover(c *bm.Context) {
- param := &channel.Param{}
- if err := c.Bind(param); err != nil {
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- param.MID = midInter.(int64)
- }
- plat := model.Plat(param.MobiApp, param.Device)
- c.JSON(channelSvc.Discover(c, param.ID, param.MID, plat))
- }
- func category(c *bm.Context) {
- param := &channel.Param{}
- if err := c.Bind(param); err != nil {
- return
- }
- plat := model.Plat(param.MobiApp, param.Device)
- c.JSON(channelSvc.Category(c, plat))
- }
- func square(c *bm.Context) {
- param := &channel.ParamSquare{}
- if err := c.Bind(param); err != nil {
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- param.MID = midInter.(int64)
- }
- buvid := c.Request.Header.Get(_headerBuvid)
- plat := model.Plat(param.MobiApp, param.Device)
- c.JSON(channelSvc.Square(c, param.MID, plat, param.Build, param.LoginEvent, param.MobiApp, param.Device, param.Lang, buvid))
- }
- func mysub(c *bm.Context) {
- param := &channel.Param{}
- if err := c.Bind(param); err != nil {
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- param.MID = midInter.(int64)
- }
- c.JSON(channelSvc.Mysub(c, param.MID, 0))
- }
- func tablist(c *bm.Context) {
- var (
- params = c.Request.Form
- mid int64
- )
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- buildStr := params.Get("build")
- cidStr := params.Get("channel_id")
- displayIDStr := params.Get("display_id")
- cname := params.Get("channel_name")
- fromStr := params.Get("display_id")
- build, err := strconv.Atoi(buildStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- displayID, err := strconv.Atoi(displayIDStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- plat := model.Plat(mobiApp, device)
- cidInt, _ := strconv.ParseInt(cidStr, 10, 64)
- if cidInt == 0 && cname == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- fromInt, err := strconv.Atoi(fromStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- now := time.Now()
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- data, err := channelSvc.TabList(c, cidInt, mid, cname, mobiApp, displayID, build, fromInt, plat, now)
- c.JSON(data, err)
- }
|