old_creative.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. package service
  2. import (
  3. "context"
  4. "strconv"
  5. "strings"
  6. "go-common/app/interface/openplatform/article/model"
  7. accmdl "go-common/app/service/main/account/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. // CreativeSubArticle submit model.
  12. func (s *Service) CreativeSubArticle(c context.Context, mid int64, art *model.ArtParam, ak, ck, ip string) (aid int64, err error) {
  13. identified, _ := s.IdentifyInfo(c, mid, 0, ak, ck, ip)
  14. if err = s.CheckIdentify(identified); err != nil {
  15. log.Error("s.accountRPC.IdentifyInfo mid(%d),ip(%s)", mid, ip)
  16. return
  17. }
  18. var arg = &model.ArgArticle{
  19. Aid: art.AID,
  20. Mid: art.MID,
  21. Category: art.Category,
  22. State: art.State,
  23. Reprint: art.Reprint,
  24. TemplateID: art.TemplateID,
  25. Title: art.Title,
  26. BannerURL: art.BannerURL,
  27. Content: art.Content,
  28. Summary: art.Summary,
  29. RealIP: art.RealIP,
  30. Words: art.Words,
  31. DynamicIntro: art.DynamicIntro,
  32. ImageURLs: art.ImageURLs,
  33. OriginImageURLs: art.OriginImageURLs,
  34. ActivityID: art.ActivityID,
  35. ListID: art.ListID,
  36. MediaID: art.MediaID,
  37. Spoiler: art.Spoiler,
  38. }
  39. if art.Tags != "" {
  40. arg.Tags = strings.Split(art.Tags, ",")
  41. } else {
  42. arg.Tags = []string{}
  43. }
  44. var a = model.TransformArticle(arg)
  45. if aid, err = s.AddArticle(c, a, arg.ActivityID, arg.ListID, arg.RealIP); err != nil {
  46. return
  47. }
  48. return
  49. }
  50. // CreativeUpdateArticle update model.
  51. func (s *Service) CreativeUpdateArticle(c context.Context, mid int64, art *model.ArtParam, ak, ck, ip string) (err error) {
  52. identified, _ := s.IdentifyInfo(c, mid, 0, ak, ck, ip)
  53. if err = s.CheckIdentify(identified); err != nil {
  54. log.Error("s.accountRPC.IdentifyInfo mid(%d),ip(%s)", mid, ip)
  55. return
  56. }
  57. var arg = &model.ArgArticle{
  58. Aid: art.AID,
  59. Mid: art.MID,
  60. Category: art.Category,
  61. State: art.State,
  62. Reprint: art.Reprint,
  63. TemplateID: art.TemplateID,
  64. Title: art.Title,
  65. BannerURL: art.BannerURL,
  66. Content: art.Content,
  67. Summary: art.Summary,
  68. RealIP: art.RealIP,
  69. Words: art.Words,
  70. DynamicIntro: art.DynamicIntro,
  71. ImageURLs: art.ImageURLs,
  72. OriginImageURLs: art.OriginImageURLs,
  73. ListID: art.ListID,
  74. MediaID: art.MediaID,
  75. Spoiler: art.Spoiler,
  76. }
  77. if art.Tags != "" {
  78. arg.Tags = strings.Split(art.Tags, ",")
  79. } else {
  80. arg.Tags = []string{}
  81. }
  82. log.Info("d.art.UpdateArticle id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
  83. var a = model.TransformArticle(arg)
  84. if err = s.UpdateArticle(c, a, arg.ActivityID, arg.ListID, arg.RealIP); err != nil {
  85. return
  86. }
  87. return
  88. }
  89. // CreativeAddDraft .
  90. func (s *Service) CreativeAddDraft(c context.Context, mid int64, art *model.ArtParam) (aid int64, err error) {
  91. var arg = &model.ArgArticle{
  92. Aid: art.AID,
  93. Mid: art.MID,
  94. Category: art.Category,
  95. State: art.State,
  96. Reprint: art.Reprint,
  97. TemplateID: art.TemplateID,
  98. Title: art.Title,
  99. BannerURL: art.BannerURL,
  100. Content: art.Content,
  101. Summary: art.Summary,
  102. RealIP: art.RealIP,
  103. Words: art.Words,
  104. DynamicIntro: art.DynamicIntro,
  105. ImageURLs: art.ImageURLs,
  106. OriginImageURLs: art.OriginImageURLs,
  107. ListID: art.ListID,
  108. MediaID: art.MediaID,
  109. Spoiler: art.Spoiler,
  110. }
  111. if art.Tags != "" {
  112. arg.Tags = strings.Split(art.Tags, ",")
  113. } else {
  114. arg.Tags = []string{}
  115. }
  116. log.Info("d.art.AddDraft id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
  117. d := model.TransformDraft(arg)
  118. aid, err = s.AddArtDraft(c, d)
  119. return
  120. }
  121. // CheckIdentify fn
  122. func (s *Service) CheckIdentify(identify int) (err error) {
  123. switch identify {
  124. case 0:
  125. err = nil
  126. case 1:
  127. err = ecode.UserCheckInvalidPhone
  128. case 2:
  129. err = ecode.UserCheckNoPhone
  130. }
  131. return
  132. }
  133. // IdentifyInfo .
  134. func (s *Service) IdentifyInfo(c context.Context, mid int64, phoneOnly int8, ak, ck, ip string) (ret int, err error) {
  135. var (
  136. mf *accmdl.Profile
  137. arg = &accmdl.ArgMid{
  138. Mid: mid,
  139. }
  140. )
  141. if mf, err = s.accountRPC.Profile3(c, arg); err != nil {
  142. log.Error("d.acc.MyInfo error(%+v) | mid(%d) ck(%s) ak(%s) ip(%s) arg(%v)", err, mid, ck, ak, ip, arg)
  143. err = ecode.CreativeAccServiceErr
  144. return
  145. }
  146. //switch for FrontEnd return json format
  147. ret = s.switchPhoneRet(int(mf.TelStatus))
  148. if phoneOnly == 1 {
  149. return
  150. }
  151. if mf.TelStatus == 1 || mf.Identification == 1 {
  152. return 0, err
  153. }
  154. return
  155. }
  156. // 0: "已实名认证",
  157. // 1: "根据国家实名制认证的相关要求,您需要换绑一个非170/171的手机号,才能继续进行操作。",
  158. // 2: "根据国家实名制认证的相关要求,您需要绑定手机号,才能继续进行操作。",
  159. func (s *Service) switchPhoneRet(newV int) (oldV int) {
  160. switch newV {
  161. case 0:
  162. oldV = 2
  163. case 1:
  164. oldV = 0
  165. case 2:
  166. oldV = 1
  167. }
  168. return
  169. }
  170. // CreativeArticles creative articles list
  171. func (s *Service) CreativeArticles(c context.Context, mid int64, pn, ps, sort, group, category int, ip string) (arts *model.CreativeArtList, err error) {
  172. var res *model.CreationArts
  173. res, err = s.CreationUpperArticlesMeta(c, mid, group, category, sort, pn, ps, ip)
  174. arts = &model.CreativeArtList{}
  175. if res != nil {
  176. arts.Articles = make([]*model.CreativeMeta, 0, len(res.Articles))
  177. arts.Page = res.Page
  178. arts.Type = res.Type
  179. }
  180. if err != nil {
  181. log.Error("s.art.Articles(mid:%d) error(%+v)", mid, err)
  182. return
  183. }
  184. if (res == nil) || (res.Articles == nil) || (len(res.Articles) == 0) {
  185. log.Info("s.art.Articles(mid:%d) res(%v)", mid, res)
  186. return
  187. }
  188. for _, v := range res.Articles {
  189. id := strconv.FormatInt(v.ID, 10)
  190. m := &model.CreativeMeta{
  191. ID: v.ID,
  192. Category: v.Category,
  193. Title: v.Title,
  194. Summary: v.Summary,
  195. BannerURL: v.BannerURL,
  196. TemplateID: v.TemplateID,
  197. State: v.State,
  198. Reprint: v.Reprint,
  199. Reason: v.Reason,
  200. PTime: v.PublishTime,
  201. Author: v.Author,
  202. Stats: v.Stats,
  203. CTime: v.Ctime,
  204. MTime: v.Mtime,
  205. EditURL: "https://member.bilibili.com/article-text/mobile?aid=" + id + "&type=2",
  206. DynamicIntro: v.Dynamic,
  207. ImageURLs: v.ImageURLs,
  208. OriginImageURLs: v.OriginImageURLs,
  209. List: v.List,
  210. }
  211. if m.ImageURLs == nil {
  212. m.ImageURLs = []string{}
  213. }
  214. if m.OriginImageURLs == nil {
  215. m.OriginImageURLs = []string{}
  216. }
  217. switch m.State {
  218. case 0, 7:
  219. // 开放浏览, 可编辑
  220. m.ViewURL = "https://www.bilibili.com/read/cv" + id
  221. m.IsPreview = 0
  222. m.EditTimes = s.EditTimes(c, m.ID)
  223. m.EditURL = "https://member.bilibili.com/article-text/mobile?aid=" + id + "&type=3"
  224. case 4:
  225. // 开放浏览
  226. m.ViewURL = "https://www.bilibili.com/read/cv" + id
  227. m.IsPreview = 0
  228. case 5, 6:
  229. // 开放浏览,重复编辑待审/重复编辑未通过
  230. m.ViewURL = "https://www.bilibili.com/read/cv" + id
  231. m.IsPreview = 2
  232. m.PreViewURL = "https://www.bilibili.com/read/preview/" + id
  233. var (
  234. a *model.Article
  235. e1 error
  236. )
  237. if a, e1 = s.ArticleVersion(c, m.ID); e1 != nil {
  238. log.Error("s.ArticleVersion(%d) error(%+v)", m.ID, e1)
  239. continue
  240. }
  241. m.Title = a.Title
  242. m.Reason = a.Reason
  243. m.Category = a.Category
  244. m.TemplateID = a.TemplateID
  245. m.ImageURLs = a.ImageURLs
  246. m.Summary = a.Summary
  247. m.Reprint = a.Reprint
  248. m.BannerURL = a.BannerURL
  249. m.OriginImageURLs = a.OriginImageURLs
  250. if m.State == 6 {
  251. m.EditURL = "https://member.bilibili.com/article-text/mobile?aid=" + id + "&type=3"
  252. m.EditTimes = s.EditTimes(c, m.ID)
  253. m.Reason, _ = s.lastReason(c, m.ID, m.State)
  254. }
  255. default:
  256. // 预览
  257. m.PreViewURL = "https://www.bilibili.com/read/preview/" + id
  258. m.IsPreview = 1
  259. }
  260. tags := []string{}
  261. m.Tags = tags
  262. if len(v.Tags) > 0 {
  263. for _, vv := range v.Tags {
  264. tags = append(tags, vv.Name)
  265. }
  266. m.Tags = tags
  267. }
  268. arts.Articles = append(arts.Articles, m)
  269. }
  270. return
  271. }
  272. // CreativeDrafts get draft list.
  273. func (s *Service) CreativeDrafts(c context.Context, mid int64, pn, ps int, ip string) (dls *model.CreativeDraftList, err error) {
  274. var res *model.Drafts
  275. res, err = s.UpperDrafts(c, mid, pn, ps)
  276. if err != nil {
  277. log.Error("s.art.Drafts(mid:%d) error(%+v)", mid, err)
  278. return
  279. }
  280. if res == nil || res.Drafts == nil || len(res.Drafts) <= 0 {
  281. log.Info("s.art.Drafts(mid:%d) res(%+v)", mid, res)
  282. return
  283. }
  284. ms := make([]*model.CreativeMeta, 0, len(res.Drafts))
  285. for _, v := range res.Drafts {
  286. id := strconv.FormatInt(v.ID, 10)
  287. m := &model.CreativeMeta{
  288. ID: v.ID,
  289. Category: v.Category,
  290. Title: v.Title,
  291. Summary: v.Summary,
  292. BannerURL: v.BannerURL,
  293. TemplateID: v.TemplateID,
  294. State: v.State,
  295. Reprint: v.Reprint,
  296. Reason: v.Reason,
  297. PTime: v.PublishTime,
  298. Author: v.Author,
  299. Stats: v.Stats,
  300. CTime: v.Ctime,
  301. MTime: v.Mtime,
  302. DynamicIntro: v.Dynamic,
  303. ImageURLs: v.ImageURLs,
  304. OriginImageURLs: v.OriginImageURLs,
  305. List: v.List,
  306. EditURL: "https://member.bilibili.com/article-text/mobile?aid=" + id,
  307. }
  308. if m.ImageURLs == nil {
  309. m.ImageURLs = []string{}
  310. }
  311. if m.OriginImageURLs == nil {
  312. m.OriginImageURLs = []string{}
  313. }
  314. m.Tags = v.Tags
  315. if len(v.Tags) == 0 {
  316. m.Tags = []string{}
  317. }
  318. ms = append(ms, m)
  319. }
  320. dls = &model.CreativeDraftList{
  321. DraftURL: "https://member.bilibili.com/creative/app/article_drafts",
  322. }
  323. dls.Drafts = ms
  324. dls.Page = res.Page
  325. return
  326. }
  327. // CreativeDraft get draft.
  328. func (s *Service) CreativeDraft(c context.Context, aid, mid int64, ip string) (res *model.CreativeMeta, err error) {
  329. var df *model.Draft
  330. if df, err = s.ArtDraft(c, aid, mid); err != nil {
  331. return
  332. }
  333. if df == nil || df.Article == nil {
  334. err = ecode.CreativeArticleNotExist
  335. return
  336. }
  337. res = &model.CreativeMeta{
  338. ID: df.Article.ID,
  339. Category: df.Article.Category,
  340. Title: df.Article.Title,
  341. Content: df.Article.Content,
  342. Summary: df.Article.Summary,
  343. BannerURL: df.Article.BannerURL,
  344. TemplateID: df.Article.TemplateID,
  345. State: df.Article.State,
  346. Author: df.Article.Author,
  347. Stats: df.Article.Stats,
  348. Reprint: df.Article.Reprint,
  349. Reason: df.Article.Reason,
  350. PTime: df.Article.PublishTime,
  351. CTime: df.Article.Ctime,
  352. MTime: df.Article.Mtime,
  353. DynamicIntro: df.Article.Dynamic,
  354. ImageURLs: df.ImageURLs,
  355. OriginImageURLs: df.OriginImageURLs,
  356. List: df.List,
  357. MediaID: df.Article.Media.MediaID,
  358. Spoiler: df.Article.Media.Spoiler,
  359. }
  360. if res.ImageURLs == nil {
  361. res.ImageURLs = []string{}
  362. }
  363. if res.OriginImageURLs == nil {
  364. res.OriginImageURLs = []string{}
  365. }
  366. res.Tags = df.Tags
  367. if len(df.Tags) == 0 {
  368. res.Tags = []string{}
  369. }
  370. return
  371. }
  372. // CreativeView get article detail.
  373. func (s *Service) CreativeView(c context.Context, aid, mid int64, ip string) (res *model.CreativeMeta, err error) {
  374. var art *model.Article
  375. if art, err = s.CreationArticle(c, aid, mid); err != nil {
  376. return
  377. }
  378. res = &model.CreativeMeta{
  379. ID: art.ID,
  380. Category: art.Category,
  381. Title: art.Title,
  382. Content: art.Content,
  383. Summary: art.Summary,
  384. BannerURL: art.BannerURL,
  385. TemplateID: art.TemplateID,
  386. State: art.State,
  387. Reprint: art.Reprint,
  388. Reason: art.Reason,
  389. PTime: art.PublishTime,
  390. Author: art.Author,
  391. Stats: art.Stats,
  392. CTime: art.Ctime,
  393. MTime: art.Mtime,
  394. DynamicIntro: art.Dynamic,
  395. ImageURLs: art.ImageURLs,
  396. OriginImageURLs: art.OriginImageURLs,
  397. List: art.List,
  398. MediaID: art.Media.MediaID,
  399. Spoiler: art.Media.Spoiler,
  400. }
  401. if res.State == model.StateOpen || res.State == model.StateReReject || res.State == model.StateRePass {
  402. res.EditTimes = s.EditTimes(c, res.ID)
  403. }
  404. if res.ImageURLs == nil {
  405. res.ImageURLs = []string{}
  406. }
  407. if res.OriginImageURLs == nil {
  408. res.OriginImageURLs = []string{}
  409. }
  410. if len(art.Tags) > 0 {
  411. var tags []string
  412. for _, v := range art.Tags {
  413. tags = append(tags, v.Name)
  414. }
  415. res.Tags = tags
  416. }
  417. return
  418. }
  419. // CreativeDraftCount count of upper's drafts
  420. func (s *Service) CreativeDraftCount(c context.Context, mid int64) (count int) {
  421. count, _ = s.dao.CountUpperDraft(c, mid)
  422. return
  423. }
  424. // ArticleCapture capture a new image.
  425. func (s *Service) ArticleCapture(c context.Context, url string) (loc string, size int, err error) {
  426. loc, size, err = s.dao.Capture(c, url)
  427. if err != nil {
  428. log.Error("s.bfs.Capture error(%v)", err)
  429. }
  430. return
  431. }
  432. // SetMediaScore set media score.
  433. func (s *Service) SetMediaScore(c context.Context, score, aid, mediaID, mid int64) (err error) {
  434. return s.dao.SetScore(c, score, aid, mediaID, mid)
  435. }
  436. // DelMediaScore get media score.
  437. func (s *Service) DelMediaScore(c context.Context, aid, mediaID, mid int64) (err error) {
  438. return s.dao.DelScore(c, aid, mediaID, mid)
  439. }