123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- package service
- import (
- "context"
- "strconv"
- "strings"
- "go-common/app/interface/openplatform/article/model"
- accmdl "go-common/app/service/main/account/model"
- "go-common/library/ecode"
- "go-common/library/log"
- )
- // CreativeSubArticle submit model.
- func (s *Service) CreativeSubArticle(c context.Context, mid int64, art *model.ArtParam, ak, ck, ip string) (aid int64, err error) {
- identified, _ := s.IdentifyInfo(c, mid, 0, ak, ck, ip)
- if err = s.CheckIdentify(identified); err != nil {
- log.Error("s.accountRPC.IdentifyInfo mid(%d),ip(%s)", mid, ip)
- return
- }
- var arg = &model.ArgArticle{
- Aid: art.AID,
- Mid: art.MID,
- Category: art.Category,
- State: art.State,
- Reprint: art.Reprint,
- TemplateID: art.TemplateID,
- Title: art.Title,
- BannerURL: art.BannerURL,
- Content: art.Content,
- Summary: art.Summary,
- RealIP: art.RealIP,
- Words: art.Words,
- DynamicIntro: art.DynamicIntro,
- ImageURLs: art.ImageURLs,
- OriginImageURLs: art.OriginImageURLs,
- ActivityID: art.ActivityID,
- ListID: art.ListID,
- MediaID: art.MediaID,
- Spoiler: art.Spoiler,
- }
- if art.Tags != "" {
- arg.Tags = strings.Split(art.Tags, ",")
- } else {
- arg.Tags = []string{}
- }
- var a = model.TransformArticle(arg)
- if aid, err = s.AddArticle(c, a, arg.ActivityID, arg.ListID, arg.RealIP); err != nil {
- return
- }
- return
- }
- // CreativeUpdateArticle update model.
- func (s *Service) CreativeUpdateArticle(c context.Context, mid int64, art *model.ArtParam, ak, ck, ip string) (err error) {
- identified, _ := s.IdentifyInfo(c, mid, 0, ak, ck, ip)
- if err = s.CheckIdentify(identified); err != nil {
- log.Error("s.accountRPC.IdentifyInfo mid(%d),ip(%s)", mid, ip)
- return
- }
- var arg = &model.ArgArticle{
- Aid: art.AID,
- Mid: art.MID,
- Category: art.Category,
- State: art.State,
- Reprint: art.Reprint,
- TemplateID: art.TemplateID,
- Title: art.Title,
- BannerURL: art.BannerURL,
- Content: art.Content,
- Summary: art.Summary,
- RealIP: art.RealIP,
- Words: art.Words,
- DynamicIntro: art.DynamicIntro,
- ImageURLs: art.ImageURLs,
- OriginImageURLs: art.OriginImageURLs,
- ListID: art.ListID,
- MediaID: art.MediaID,
- Spoiler: art.Spoiler,
- }
- if art.Tags != "" {
- arg.Tags = strings.Split(art.Tags, ",")
- } else {
- arg.Tags = []string{}
- }
- log.Info("d.art.UpdateArticle id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
- var a = model.TransformArticle(arg)
- if err = s.UpdateArticle(c, a, arg.ActivityID, arg.ListID, arg.RealIP); err != nil {
- return
- }
- return
- }
- // CreativeAddDraft .
- func (s *Service) CreativeAddDraft(c context.Context, mid int64, art *model.ArtParam) (aid int64, err error) {
- var arg = &model.ArgArticle{
- Aid: art.AID,
- Mid: art.MID,
- Category: art.Category,
- State: art.State,
- Reprint: art.Reprint,
- TemplateID: art.TemplateID,
- Title: art.Title,
- BannerURL: art.BannerURL,
- Content: art.Content,
- Summary: art.Summary,
- RealIP: art.RealIP,
- Words: art.Words,
- DynamicIntro: art.DynamicIntro,
- ImageURLs: art.ImageURLs,
- OriginImageURLs: art.OriginImageURLs,
- ListID: art.ListID,
- MediaID: art.MediaID,
- Spoiler: art.Spoiler,
- }
- if art.Tags != "" {
- arg.Tags = strings.Split(art.Tags, ",")
- } else {
- arg.Tags = []string{}
- }
- log.Info("d.art.AddDraft id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
- d := model.TransformDraft(arg)
- aid, err = s.AddArtDraft(c, d)
- return
- }
- // CheckIdentify fn
- func (s *Service) CheckIdentify(identify int) (err error) {
- switch identify {
- case 0:
- err = nil
- case 1:
- err = ecode.UserCheckInvalidPhone
- case 2:
- err = ecode.UserCheckNoPhone
- }
- return
- }
- // IdentifyInfo .
- func (s *Service) IdentifyInfo(c context.Context, mid int64, phoneOnly int8, ak, ck, ip string) (ret int, err error) {
- var (
- mf *accmdl.Profile
- arg = &accmdl.ArgMid{
- Mid: mid,
- }
- )
- if mf, err = s.accountRPC.Profile3(c, arg); err != nil {
- log.Error("d.acc.MyInfo error(%+v) | mid(%d) ck(%s) ak(%s) ip(%s) arg(%v)", err, mid, ck, ak, ip, arg)
- err = ecode.CreativeAccServiceErr
- return
- }
- //switch for FrontEnd return json format
- ret = s.switchPhoneRet(int(mf.TelStatus))
- if phoneOnly == 1 {
- return
- }
- if mf.TelStatus == 1 || mf.Identification == 1 {
- return 0, err
- }
- return
- }
- // 0: "已实名认证",
- // 1: "根据国家实名制认证的相关要求,您需要换绑一个非170/171的手机号,才能继续进行操作。",
- // 2: "根据国家实名制认证的相关要求,您需要绑定手机号,才能继续进行操作。",
- func (s *Service) switchPhoneRet(newV int) (oldV int) {
- switch newV {
- case 0:
- oldV = 2
- case 1:
- oldV = 0
- case 2:
- oldV = 1
- }
- return
- }
- // CreativeArticles creative articles list
- func (s *Service) CreativeArticles(c context.Context, mid int64, pn, ps, sort, group, category int, ip string) (arts *model.CreativeArtList, err error) {
- var res *model.CreationArts
- res, err = s.CreationUpperArticlesMeta(c, mid, group, category, sort, pn, ps, ip)
- arts = &model.CreativeArtList{}
- if res != nil {
- arts.Articles = make([]*model.CreativeMeta, 0, len(res.Articles))
- arts.Page = res.Page
- arts.Type = res.Type
- }
- if err != nil {
- log.Error("s.art.Articles(mid:%d) error(%+v)", mid, err)
- return
- }
- if (res == nil) || (res.Articles == nil) || (len(res.Articles) == 0) {
- log.Info("s.art.Articles(mid:%d) res(%v)", mid, res)
- return
- }
- for _, v := range res.Articles {
- id := strconv.FormatInt(v.ID, 10)
- m := &model.CreativeMeta{
- ID: v.ID,
- Category: v.Category,
- Title: v.Title,
- Summary: v.Summary,
- BannerURL: v.BannerURL,
- TemplateID: v.TemplateID,
- State: v.State,
- Reprint: v.Reprint,
- Reason: v.Reason,
- PTime: v.PublishTime,
- Author: v.Author,
- Stats: v.Stats,
- CTime: v.Ctime,
- MTime: v.Mtime,
- EditURL: "https://member.bilibili.com/article-text/mobile?aid=" + id + "&type=2",
- DynamicIntro: v.Dynamic,
- ImageURLs: v.ImageURLs,
- OriginImageURLs: v.OriginImageURLs,
- List: v.List,
- }
- if m.ImageURLs == nil {
- m.ImageURLs = []string{}
- }
- if m.OriginImageURLs == nil {
- m.OriginImageURLs = []string{}
- }
- switch m.State {
- case 0, 7:
- // 开放浏览, 可编辑
- m.ViewURL = "https://www.bilibili.com/read/cv" + id
- m.IsPreview = 0
- m.EditTimes = s.EditTimes(c, m.ID)
- m.EditURL = "https://member.bilibili.com/article-text/mobile?aid=" + id + "&type=3"
- case 4:
- // 开放浏览
- m.ViewURL = "https://www.bilibili.com/read/cv" + id
- m.IsPreview = 0
- case 5, 6:
- // 开放浏览,重复编辑待审/重复编辑未通过
- m.ViewURL = "https://www.bilibili.com/read/cv" + id
- m.IsPreview = 2
- m.PreViewURL = "https://www.bilibili.com/read/preview/" + id
- var (
- a *model.Article
- e1 error
- )
- if a, e1 = s.ArticleVersion(c, m.ID); e1 != nil {
- log.Error("s.ArticleVersion(%d) error(%+v)", m.ID, e1)
- continue
- }
- m.Title = a.Title
- m.Reason = a.Reason
- m.Category = a.Category
- m.TemplateID = a.TemplateID
- m.ImageURLs = a.ImageURLs
- m.Summary = a.Summary
- m.Reprint = a.Reprint
- m.BannerURL = a.BannerURL
- m.OriginImageURLs = a.OriginImageURLs
- if m.State == 6 {
- m.EditURL = "https://member.bilibili.com/article-text/mobile?aid=" + id + "&type=3"
- m.EditTimes = s.EditTimes(c, m.ID)
- m.Reason, _ = s.lastReason(c, m.ID, m.State)
- }
- default:
- // 预览
- m.PreViewURL = "https://www.bilibili.com/read/preview/" + id
- m.IsPreview = 1
- }
- tags := []string{}
- m.Tags = tags
- if len(v.Tags) > 0 {
- for _, vv := range v.Tags {
- tags = append(tags, vv.Name)
- }
- m.Tags = tags
- }
- arts.Articles = append(arts.Articles, m)
- }
- return
- }
- // CreativeDrafts get draft list.
- func (s *Service) CreativeDrafts(c context.Context, mid int64, pn, ps int, ip string) (dls *model.CreativeDraftList, err error) {
- var res *model.Drafts
- res, err = s.UpperDrafts(c, mid, pn, ps)
- if err != nil {
- log.Error("s.art.Drafts(mid:%d) error(%+v)", mid, err)
- return
- }
- if res == nil || res.Drafts == nil || len(res.Drafts) <= 0 {
- log.Info("s.art.Drafts(mid:%d) res(%+v)", mid, res)
- return
- }
- ms := make([]*model.CreativeMeta, 0, len(res.Drafts))
- for _, v := range res.Drafts {
- id := strconv.FormatInt(v.ID, 10)
- m := &model.CreativeMeta{
- ID: v.ID,
- Category: v.Category,
- Title: v.Title,
- Summary: v.Summary,
- BannerURL: v.BannerURL,
- TemplateID: v.TemplateID,
- State: v.State,
- Reprint: v.Reprint,
- Reason: v.Reason,
- PTime: v.PublishTime,
- Author: v.Author,
- Stats: v.Stats,
- CTime: v.Ctime,
- MTime: v.Mtime,
- DynamicIntro: v.Dynamic,
- ImageURLs: v.ImageURLs,
- OriginImageURLs: v.OriginImageURLs,
- List: v.List,
- EditURL: "https://member.bilibili.com/article-text/mobile?aid=" + id,
- }
- if m.ImageURLs == nil {
- m.ImageURLs = []string{}
- }
- if m.OriginImageURLs == nil {
- m.OriginImageURLs = []string{}
- }
- m.Tags = v.Tags
- if len(v.Tags) == 0 {
- m.Tags = []string{}
- }
- ms = append(ms, m)
- }
- dls = &model.CreativeDraftList{
- DraftURL: "https://member.bilibili.com/creative/app/article_drafts",
- }
- dls.Drafts = ms
- dls.Page = res.Page
- return
- }
- // CreativeDraft get draft.
- func (s *Service) CreativeDraft(c context.Context, aid, mid int64, ip string) (res *model.CreativeMeta, err error) {
- var df *model.Draft
- if df, err = s.ArtDraft(c, aid, mid); err != nil {
- return
- }
- if df == nil || df.Article == nil {
- err = ecode.CreativeArticleNotExist
- return
- }
- res = &model.CreativeMeta{
- ID: df.Article.ID,
- Category: df.Article.Category,
- Title: df.Article.Title,
- Content: df.Article.Content,
- Summary: df.Article.Summary,
- BannerURL: df.Article.BannerURL,
- TemplateID: df.Article.TemplateID,
- State: df.Article.State,
- Author: df.Article.Author,
- Stats: df.Article.Stats,
- Reprint: df.Article.Reprint,
- Reason: df.Article.Reason,
- PTime: df.Article.PublishTime,
- CTime: df.Article.Ctime,
- MTime: df.Article.Mtime,
- DynamicIntro: df.Article.Dynamic,
- ImageURLs: df.ImageURLs,
- OriginImageURLs: df.OriginImageURLs,
- List: df.List,
- MediaID: df.Article.Media.MediaID,
- Spoiler: df.Article.Media.Spoiler,
- }
- if res.ImageURLs == nil {
- res.ImageURLs = []string{}
- }
- if res.OriginImageURLs == nil {
- res.OriginImageURLs = []string{}
- }
- res.Tags = df.Tags
- if len(df.Tags) == 0 {
- res.Tags = []string{}
- }
- return
- }
- // CreativeView get article detail.
- func (s *Service) CreativeView(c context.Context, aid, mid int64, ip string) (res *model.CreativeMeta, err error) {
- var art *model.Article
- if art, err = s.CreationArticle(c, aid, mid); err != nil {
- return
- }
- res = &model.CreativeMeta{
- ID: art.ID,
- Category: art.Category,
- Title: art.Title,
- Content: art.Content,
- Summary: art.Summary,
- BannerURL: art.BannerURL,
- TemplateID: art.TemplateID,
- State: art.State,
- Reprint: art.Reprint,
- Reason: art.Reason,
- PTime: art.PublishTime,
- Author: art.Author,
- Stats: art.Stats,
- CTime: art.Ctime,
- MTime: art.Mtime,
- DynamicIntro: art.Dynamic,
- ImageURLs: art.ImageURLs,
- OriginImageURLs: art.OriginImageURLs,
- List: art.List,
- MediaID: art.Media.MediaID,
- Spoiler: art.Media.Spoiler,
- }
- if res.State == model.StateOpen || res.State == model.StateReReject || res.State == model.StateRePass {
- res.EditTimes = s.EditTimes(c, res.ID)
- }
- if res.ImageURLs == nil {
- res.ImageURLs = []string{}
- }
- if res.OriginImageURLs == nil {
- res.OriginImageURLs = []string{}
- }
- if len(art.Tags) > 0 {
- var tags []string
- for _, v := range art.Tags {
- tags = append(tags, v.Name)
- }
- res.Tags = tags
- }
- return
- }
- // CreativeDraftCount count of upper's drafts
- func (s *Service) CreativeDraftCount(c context.Context, mid int64) (count int) {
- count, _ = s.dao.CountUpperDraft(c, mid)
- return
- }
- // ArticleCapture capture a new image.
- func (s *Service) ArticleCapture(c context.Context, url string) (loc string, size int, err error) {
- loc, size, err = s.dao.Capture(c, url)
- if err != nil {
- log.Error("s.bfs.Capture error(%v)", err)
- }
- return
- }
- // SetMediaScore set media score.
- func (s *Service) SetMediaScore(c context.Context, score, aid, mediaID, mid int64) (err error) {
- return s.dao.SetScore(c, score, aid, mediaID, mid)
- }
- // DelMediaScore get media score.
- func (s *Service) DelMediaScore(c context.Context, aid, mediaID, mid int64) (err error) {
- return s.dao.DelScore(c, aid, mediaID, mid)
- }
|