send.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "strconv"
  7. "time"
  8. "go-common/app/job/main/videoup/model/archive"
  9. "go-common/app/job/main/videoup/model/message"
  10. "go-common/app/job/main/videoup/model/redis"
  11. "go-common/library/log"
  12. )
  13. func (s *Service) sendChangeMsg(c context.Context, a *archive.Archive, v *archive.Video, m *message.Videoup) (err error) {
  14. const (
  15. _changeTypeID = "1_7_13"
  16. _changeCopyright = "1_7_14"
  17. _changeTitle = "1_7_15"
  18. _changeCover = "1_7_16"
  19. )
  20. var (
  21. code string
  22. title string
  23. msg string
  24. )
  25. title = "稿件信息变动通知"
  26. now := time.Now().Unix()
  27. if m.ChangeTitle {
  28. code = _changeTitle
  29. msg = fmt.Sprintf(`您的稿件《%s》 #{(av%d)}{"http://www.bilibili.com/video/av%d/"} 标题内容已被管理员修改,相关规则请查阅投稿页和帮助中心。`, a.Title, a.Aid, a.Aid)
  30. s.msg.Send(c, code, title, msg, a.Mid, now)
  31. }
  32. if m.ChangeTypeID {
  33. code = _changeTypeID
  34. msg = fmt.Sprintf(`您的稿件《%s》(#{(av%d)}{"http://www.bilibili.com/video/av%d/"} 不符合分区分类规则,已被管理员移动至%s区,相关规则请查阅投稿页和帮助中心`, a.Title, a.Aid, a.Aid, s.TypeMap[a.TypeID])
  35. s.msg.Send(c, code, title, msg, a.Mid, now)
  36. }
  37. if m.ChangeCopyright {
  38. code = _changeCopyright
  39. msg = fmt.Sprintf(`您的稿件《%s》#{(av%d)}{"http://www.bilibili.com/video/av%d/"} 投稿类型已被管理员修改,相关规则请查阅投稿页和帮助中心。`, a.Title, a.Aid, a.Aid)
  40. s.msg.Send(c, code, title, msg, a.Mid, now)
  41. }
  42. if m.ChangeCover {
  43. code = _changeCover
  44. msg = fmt.Sprintf(`您的稿件《%s》#{(av%d)}{"http://www.bilibili.com/video/av%d/"} 封面已被管理员修改,相关规则请查阅投稿页和帮助中心。`, a.Title, a.Aid, a.Aid)
  45. s.msg.Send(c, code, title, msg, a.Mid, now)
  46. }
  47. return
  48. }
  49. // sendMissionMsg
  50. func (s *Service) sendMissionMsg(c context.Context, a *archive.Archive) (err error) {
  51. var (
  52. code = "1_7_21"
  53. title = "【您的稿件已通过审核】"
  54. msg = `您的《%s》(%d)已经通过审核,但由于不符合本次征稿活动的规则,故该稿件无法参与本次活动的评选。 #{点击查看>>}{"http://www.bilibili.com/video/av%d/"} 如果您有疑问,请联系help@bilibili.com。更多活动信息请关注哔哩哔哩活动。`
  55. now = time.Now().Unix()
  56. )
  57. msg = fmt.Sprintf(msg, a.Title, a.Aid, a.Aid)
  58. if err = s.msg.Send(c, code, title, msg, a.Mid, now); err != nil {
  59. log.Error("s.msg.Send(%s,%s,%s,%d,%d) error(%v)", code, title, msg, a.Mid, now, err)
  60. return
  61. }
  62. return
  63. }
  64. // sendNewUpperMsg
  65. func (s *Service) sendNewUpperMsg(c context.Context, mid, aid int64) (err error) {
  66. var (
  67. code = "1_7_22"
  68. title = "【 %s,有位神秘人访问了你的作品!】"
  69. msg = `终于看到你的投稿啦|ω・)!欢迎加入UP主大家庭,与我们分享你的热爱。我是你的贴身小秘创作君,请收下我悄悄为你准备的 #{入门福利}{"http://member.bilibili.com/studio/annyroal/newcomer-letter?aid=%d"},一定要亲自打开噢(/ω\)!想了解更多UP主资讯,欢迎关注 #{@哔哩哔哩创作中心}{"https://space.bilibili.com/37090048/?from=message"} !`
  70. now = time.Now().Unix()
  71. )
  72. upper, err := s.profile(c, mid)
  73. if err != nil {
  74. log.Error("s.profile(%d) error(%v)", mid, err)
  75. return
  76. }
  77. title = fmt.Sprintf(title, upper.Profile.Name)
  78. msg = fmt.Sprintf(msg, aid)
  79. if err = s.msg.Send(c, code, title, msg, mid, now); err != nil {
  80. log.Error("s.msg.Send(%s,%s,%s,%d,%d) error(%v)", code, title, msg, mid, now, err)
  81. return
  82. }
  83. return
  84. }
  85. func (s *Service) sendMsg(c context.Context, a *archive.Archive, v *archive.Video) (err error) {
  86. const (
  87. _codePass = "1_7_1"
  88. _codeRecycle = "1_7_3"
  89. _codeLock = "1_7_5"
  90. _codeXcodeFail = "1_7_7"
  91. )
  92. var (
  93. code string
  94. title string
  95. reason string
  96. msg string
  97. title2 string
  98. msg2 string
  99. )
  100. switch a.State {
  101. case archive.StateOpen, archive.StateForbidUserDelay, archive.StateOrange:
  102. code = _codePass
  103. title = "您的稿件已通过审核"
  104. title2 = "您的视频已通过审核"
  105. msg = fmt.Sprintf(`您的稿件《%s》(av%d)已经通过审核,#{点击查看>>}{"http://www.bilibili.com/video/av%d/"}`, a.Title, a.Aid, a.Aid)
  106. msg2 = fmt.Sprintf(`您的视频《%s》(av%d)已经通过审核,#{点击查看>>}{"http://www.bilibili.com/video/av%d/"}`, a.Title, a.Aid, a.Aid)
  107. case archive.StateForbidRecicle:
  108. code = _codeRecycle
  109. title = "您的稿件被退回"
  110. title2 = "您的视频被退回"
  111. if v != nil {
  112. reason, _ = s.arc.Reason(c, v.ID)
  113. } else {
  114. reason = a.Reason
  115. }
  116. msg = fmt.Sprintf(`您的稿件《%s》(av%d)未能通过审核。原因:%s 您可以编辑稿件重新投稿,或者对审核结果进行申诉。`, a.Title, a.Aid, reason)
  117. msg2 = fmt.Sprintf(`您的视频《%s》(av%d)未能通过审核。原因:%s。您可以编辑稿件重新投稿,或者对审核结果进行申诉。#{点击进行编辑>>}{"https://member.bilibili.com/v/video/submit.html?type=edit&aid=%d"}`, a.Title, a.Aid, reason, a.Aid)
  118. case archive.StateForbidLock:
  119. code = _codeLock
  120. title = "您的视频被退回且锁定"
  121. title2 = title
  122. if v != nil {
  123. reason, _ = s.arc.Reason(c, v.ID)
  124. } else {
  125. reason = a.Reason
  126. }
  127. msg = fmt.Sprintf("您的稿件《%s》(av%d)未能通过审核且被锁定(锁定稿件无法被编辑)。原因:%s。", a.Title, a.Aid, reason)
  128. msg2 = fmt.Sprintf("您的视频《%s》(av%d)未能通过审核且被锁定(锁定稿件无法被编辑)。原因:%s。", a.Title, a.Aid, reason)
  129. case archive.StateForbidXcodeFail:
  130. if v == nil {
  131. log.Warn("(%d:%s)二转失败(-16)", a.Aid, title)
  132. return
  133. }
  134. code = _codeXcodeFail
  135. title = "您的视频未能成功转码"
  136. title2 = title
  137. msg = fmt.Sprintf(`您的稿件《%s》(av%d)未能成功转码。原因:%s 请检查视频文件是否可以正常播放后再重新上传视频后再进行投稿,#{点击进入编辑>>}{"http://member.bilibili.com/v/video/submit.html?type=edit&aid=%d"}`,
  138. a.Title, a.Aid, archive.XcodeFailMsgs[v.FailCode], a.Aid)
  139. msg2 = fmt.Sprintf(`您的视频《%s》(av%d)未能成功转码。原因:%s。请检查视频文件是否可以正常播放后再重新上传视频进行投稿。#{点击进行编辑>>}{"https://member.bilibili.com/v/video/submit.html?type=edit&aid=%d"}`,
  140. a.Title, a.Aid, archive.XcodeFailMsgs[v.FailCode], a.Aid)
  141. default:
  142. return
  143. }
  144. now := time.Now().Unix()
  145. s.msg.Send(c, code, title, msg, a.Mid, now)
  146. s.msg.Send(c, "113_1_1", title2, msg2, a.Mid, now)
  147. return
  148. }
  149. // sendAuditMsg send message when delay archive open publish or archive auto open or first round forbid
  150. func (s *Service) sendAuditMsg(c context.Context, route string, aid int64) {
  151. var (
  152. msg = &message.Videoup{
  153. Route: route,
  154. Aid: aid,
  155. Timestamp: time.Now().Unix(),
  156. }
  157. )
  158. k := strconv.FormatInt(aid, 10)
  159. log.Info("s.sendAuditMsg() key(%s) msg(%v)", k, msg)
  160. if err := s.videoupPub.Send(c, k, msg); err != nil {
  161. log.Error("s.sendAuditMsg() key(%s) msg(%v) error (%v)", k, msg, err)
  162. s.syncRetry(c, aid, 0, redis.ActionForSendOpenMsg, msg.Route, "")
  163. }
  164. }
  165. // sendPostFirstRound send message when first round after async status
  166. func (s *Service) sendPostFirstRound(c context.Context, route string, aid int64, filename string, adminChange bool) {
  167. var (
  168. msg = &message.Videoup{
  169. Route: route,
  170. Aid: aid,
  171. Filename: filename,
  172. AdminChange: adminChange,
  173. Timestamp: time.Now().Unix(),
  174. }
  175. bs []byte
  176. )
  177. k := strconv.FormatInt(aid, 10)
  178. log.Info("sendPostFirstRound key(%s) msg(%+v)", k, msg)
  179. if err := s.videoupPub.Send(c, k, msg); err != nil {
  180. log.Error("sendPostFirstRound s.videoupPub.Send key(%s) msg(%+v) error (%v)", k, msg, err)
  181. if bs, err = json.Marshal(msg); err != nil {
  182. log.Error("sendPostFirstRound json.Marshal error(%v)", err)
  183. return
  184. }
  185. s.syncRetry(c, aid, 0, redis.ActionForPostFirstRound, msg.Route, string(bs))
  186. }
  187. }