music.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/admin/main/creative/model/logcli"
  6. "go-common/app/admin/main/creative/model/music"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/xstr"
  10. )
  11. //SendNotify .
  12. func (s *Service) SendNotify(c *bm.Context, sendIds []int64, data map[int64]*music.SidNotify) (err error) {
  13. var (
  14. //mid首次收录
  15. content = "您的音频稿件(au:%d)已被手机投稿BGM库收录,快加入素材激励计划(#{APP申请入口}{\"https://member.bilibili.com/studio/up-allowance-h5#\"},#{WEB申请入口}{\"https://member.bilibili.com/v/#/allowance\"})获取收益吧!被收录稿件名:《%s》"
  16. //sid首次收录
  17. content2 = "您的音频稿件【《%s》(au:%d)】已被手机投稿BGM库收录,期待您创作更多优秀的新作品哦"
  18. title = "创作激励计划素材收录通知"
  19. )
  20. for _, sid := range sendIds {
  21. if _, ok := data[sid]; !ok {
  22. continue
  23. }
  24. sendConfig := data[sid]
  25. log.Info("svc.SendNotify param sendConfig(%+v) ", sendConfig)
  26. var (
  27. mids []int64
  28. first, send bool
  29. sendContent string
  30. )
  31. //check exists
  32. exists := music.Music{}
  33. if err = s.DBArchive.Model(&music.Music{}).Where("sid=?", sid).First(&exists).Error; err != nil {
  34. continue
  35. }
  36. //每个mid 第一次收录 优先级最高
  37. if sendConfig.MidFirst {
  38. first = true
  39. send = true
  40. }
  41. if !sendConfig.MidFirst && sendConfig.SidFirst {
  42. first = false
  43. send = true
  44. }
  45. if !first {
  46. content = content2
  47. sendContent = fmt.Sprintf(content, exists.Name, exists.Sid)
  48. } else {
  49. sendContent = fmt.Sprintf(content, exists.Sid, exists.Name)
  50. }
  51. if !send {
  52. return
  53. }
  54. mids = []int64{exists.Mid}
  55. s.addAsyn(func() {
  56. if err = s.dao.MutliSendSysMsg(context.TODO(), mids, title, sendContent); err != nil {
  57. log.Error("s.d.MutliSendSysMsg(%s,%s,%s) error(%+v)", xstr.JoinInts(mids), title, sendContent, err)
  58. return
  59. }
  60. })
  61. s.SendMusicLog(c, logcli.LogClientArchiveMusicTypeCategoryRelation, &music.LogParam{ID: sid, UID: 0, UName: fmt.Sprintf("mid(%d)", exists.Mid), Action: "SendNotify", Name: sendContent})
  62. }
  63. return
  64. }