123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 |
- package http
- import (
- "strconv"
- "go-common/app/interface/main/creative/model/academy"
- "go-common/app/interface/main/creative/model/archive"
- whmdl "go-common/app/interface/main/creative/model/weeklyhonor"
- "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"
- "go-common/library/xstr"
- )
- func appH5ArcTags(c *bm.Context) {
- params := c.Request.Form
- tidStr := params.Get("typeid")
- title := params.Get("title")
- filename := params.Get("filename")
- desc := params.Get("desc")
- cover := params.Get("cover")
- midStr, ok := c.Get("mid")
- mid := midStr.(int64)
- if !ok {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- tid, _ := strconv.ParseInt(tidStr, 10, 16)
- if tid <= 0 {
- tid = 0
- }
- tags, _ := dataSvc.TagsWithChecked(c, mid, uint16(tid), title, filename, desc, cover, archive.TagPredictFromAPP)
- c.JSON(tags, nil)
- }
- func appH5ArcTagInfo(c *bm.Context) {
- params := c.Request.Form
- tagNameStr := params.Get("tag_name")
- midStr, ok := c.Get("mid")
- mid := midStr.(int64)
- if !ok {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- if len(tagNameStr) == 0 {
- log.Error("tagNameStr len zero (%s)", tagNameStr)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- code, msg := arcSvc.TagCheck(c, mid, tagNameStr)
- c.JSON(map[string]interface{}{
- "code": code,
- "msg": msg,
- }, nil)
- }
- func appH5Pre(c *bm.Context) {
- midStr, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- mid := midStr.(int64)
- c.JSON(map[string]interface{}{
- "activities": arcSvc.Activities(c),
- "fav": arcSvc.Fav(c, mid),
- }, nil)
- }
- func appH5MissionByType(c *bm.Context) {
- params := c.Request.Form
- tidStr := params.Get("tid")
- _, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- tid, _ := strconv.Atoi(tidStr)
- actWithTP, _ := arcSvc.MissionOnlineByTid(c, int16(tid), 1)
- c.JSON(actWithTP, nil)
- }
- func toInt(s string) (i int, err error) {
- if s == "" {
- return 0, nil
- }
- i, err = strconv.Atoi(s)
- if err != nil {
- log.Error("strconv.Atoi s(%s) error(%v)", s, err)
- err = ecode.RequestErr
- }
- return
- }
- func toInt64(s string) (i int64, err error) {
- if s == "" {
- return 0, nil
- }
- i, err = strconv.ParseInt(s, 10, 64)
- if err != nil {
- log.Error("strconv.Atoi s(%s) error(%v)", s, err)
- err = ecode.RequestErr
- }
- return
- }
- func h5ViewPlay(c *bm.Context) {
- params := c.Request.Form
- aidStr := params.Get("aid")
- busStr := params.Get("business")
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- mid, ok := midI.(int64)
- if !ok || mid == 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- aid, err := toInt64(aidStr)
- if err != nil || aid <= 0 {
- c.JSON(nil, err)
- return
- }
- bus, err := toInt(busStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- if aid == 0 || bus == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- pl, err := acaSvc.ViewPlay(c, mid, aid, int8(bus))
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(pl, nil)
- }
- func h5AddPlay(c *bm.Context) {
- params := c.Request.Form
- aidStr := params.Get("aid")
- busStr := params.Get("business")
- watchStr := params.Get("watch")
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- mid, ok := midI.(int64)
- if !ok || mid == 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- aid, err := toInt64(aidStr)
- if err != nil || aid <= 0 {
- c.JSON(nil, err)
- return
- }
- bus, err := toInt(busStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- watch, err := toInt(watchStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- if aid == 0 || bus == 0 || watch == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- id, err := acaSvc.PlayAdd(c, mid, aid, int8(bus), int8(watch))
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(map[string]interface{}{
- "id": id,
- }, nil)
- }
- func h5DelPlay(c *bm.Context) {
- params := c.Request.Form
- aidStr := params.Get("aid")
- busStr := params.Get("business")
- // check user
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- mid, ok := midI.(int64)
- if !ok || mid == 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- aid, err := toInt64(aidStr)
- if err != nil || aid <= 0 {
- c.JSON(nil, err)
- return
- }
- bus, err := toInt(busStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- if aid == 0 || bus == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- id, err := acaSvc.PlayDel(c, mid, aid, int8(bus))
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(map[string]interface{}{
- "id": id,
- }, nil)
- }
- func h5PlayList(c *bm.Context) {
- params := c.Request.Form
- pnStr := params.Get("pn")
- psStr := params.Get("ps")
- // check user
- midStr, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- mid, ok := midStr.(int64)
- if !ok || mid == 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- pn, err := toInt(pnStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- ps, err := toInt(psStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- if pn <= 0 {
- pn = 1
- }
- if ps > 20 || ps <= 0 {
- ps = 20
- }
- arcs, err := acaSvc.PlayList(c, mid, pn, ps)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(arcs, nil)
- }
- func h5ThemeDir(c *bm.Context) {
- occs, err := acaSvc.Occupations(c)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(occs, nil)
- }
- func h5NewbCourse(c *bm.Context) {
- nc, err := acaSvc.NewbCourse(c)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nc, nil)
- }
- func h5Tags(c *bm.Context) {
- c.JSON(acaSvc.Tags(c), nil)
- }
- func h5Archive(c *bm.Context) {
- params := c.Request.Form
- tidsStr := params.Get("tids")
- bsStr := params.Get("business")
- pageStr := params.Get("pn")
- psStr := params.Get("ps")
- keyword := params.Get("keyword")
- order := params.Get("order")
- drStr := params.Get("duration")
- ip := metadata.String(c, metadata.RemoteIP)
- var (
- tids []int64
- err error
- )
- // check params
- if tidsStr != "" {
- if tids, err = xstr.SplitInts(tidsStr); err != nil {
- log.Error("strconv.ParseInt(%s) error(%v)", tidsStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- bs, err := toInt(bsStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- dr, err := toInt(drStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- pn, err := toInt(pageStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- ps, err := toInt(psStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- if pn <= 0 {
- pn = 1
- }
- if ps > 20 || ps <= 0 {
- ps = 20
- }
- aca := &academy.EsParam{
- Tid: tids,
- Business: bs,
- Pn: pn,
- Ps: ps,
- Keyword: keyword,
- Order: order,
- IP: ip,
- Duration: dr,
- }
- var arcs *academy.ArchiveList
- arcs, err = acaSvc.Archives(c, aca)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(arcs, nil)
- }
- func h5Feature(c *bm.Context) {
- ip := metadata.String(c, metadata.RemoteIP)
- // check params
- aca := &academy.EsParam{
- Pn: 1,
- Ps: 50,
- Keyword: "",
- Order: "",
- IP: ip,
- }
- aca2 := &academy.EsParam{
- Pn: 1,
- Ps: 50,
- Keyword: "",
- Order: "",
- IP: ip,
- }
- var (
- g = &errgroup.Group{}
- offArcs, chArcs *academy.ArchiveList
- )
- g.Go(func() error {
- aca.Tid = []int64{acaSvc.OfficialID} //官方课程
- offArcs, _ = acaSvc.ArchivesWithES(c, aca)
- return nil
- })
- g.Go(func() error {
- aca2.Tid = []int64{acaSvc.EditorChoiceID} //编辑精选
- chArcs, _ = acaSvc.ArchivesWithES(c, aca2)
- return nil
- })
- g.Wait()
- c.JSON(map[string]interface{}{
- "official_course": offArcs,
- "editor_choice": chArcs,
- }, nil)
- }
- func weeklyHonor(c *bm.Context) {
- midStr, _ := c.Get("mid")
- var mid int64
- uid, ok := midStr.(int64)
- if ok {
- mid = uid
- }
- arg := new(struct {
- UID int64 `form:"uid"`
- Token string `form:"token"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- if mid == 0 && arg.UID == 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- rec, err := honorSvc.WeeklyHonor(c, mid, arg.UID, arg.Token)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(rec, nil)
- }
- func weeklyHonorSubSwitch(c *bm.Context) {
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- if mid <= 0 {
- c.JSON(nil, ecode.CreativeNotLogin)
- return
- }
- params := c.Request.Form
- stateStr := params.Get("state")
- st, err := strconv.Atoi(stateStr)
- state := uint8(st)
- if err != nil || (state != whmdl.HonorSub && state != whmdl.HonorUnSub) {
- c.JSON(nil, ecode.ReqParamErr)
- }
- err = honorSvc.ChangeSubState(c, mid, state)
- c.JSON(nil, err)
- }
- func h5RecommendV2(c *bm.Context) {
- midStr, _ := c.Get("mid")
- var mid int64
- uid, ok := midStr.(int64)
- if ok {
- mid = uid
- }
- rec, err := acaSvc.RecommendV2(c, mid)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(rec, nil)
- }
- func h5ThemeCousreV2(c *bm.Context) {
- params := c.Request.Form
- pnStr := params.Get("pn")
- psStr := params.Get("ps")
- pidStr := params.Get("pid")
- skidStr := params.Get("skid")
- sidStr := params.Get("sid")
- pn, err := toInt(pnStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- ps, err := toInt(psStr)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- if pn <= 0 {
- pn = 1
- }
- if ps > 20 || ps <= 0 {
- ps = 20
- }
- var pids, skids, sids []int64
- if pidStr != "" {
- if pids, err = xstr.SplitInts(pidStr); err != nil {
- log.Error("strconv.ParseInt pidStr(%s) error(%v)", pidStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- if skidStr != "" {
- if skids, err = xstr.SplitInts(skidStr); err != nil {
- log.Error("strconv.ParseInt skidStr(%s) error(%v)", skidStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- if sidStr != "" {
- if sids, err = xstr.SplitInts(sidStr); err != nil {
- log.Error("strconv.ParseInt sidStr(%s) error(%v)", sidStr, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- arcs, err := acaSvc.ProfessionSkill(c, pids, skids, sids, pn, ps, false)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(arcs, nil)
- }
- func h5Keywords(c *bm.Context) {
- c.JSON(acaSvc.Keywords(c), nil)
- }
|