message.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/admin/main/dm/model"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _sendNotify = "/api/notify/send.user.notify.do"
  11. _msgReporterTitle = "举报处理结果通知"
  12. _msgPosterTitle = "弹幕违规处理通知"
  13. _msgReporterKey = "1_6_4"
  14. _msgPosterKey = "1_6_5"
  15. _msgSubtitleTitle = "字幕状态变更"
  16. _msgSubtitleUpKey = "1_6_8"
  17. _msgSubtitleUserKey = "1_6_7"
  18. )
  19. type msgReturn struct {
  20. Code int64 `json:"code"`
  21. Ts interface{} `json:"ts"`
  22. Data *struct {
  23. Mc string `json:"mc"`
  24. DataType int8 `json:"data_type"`
  25. TotalCount int64 `json:"total_count"`
  26. ErrorCount int64 `json:"error_count"`
  27. ErrorMids []int64 `json:"error_mid_list"`
  28. } `json:"data"`
  29. }
  30. // SendMsgToReporter send message
  31. func (d *Dao) SendMsgToReporter(c context.Context, rptMsg *model.ReportMsg) (err error) {
  32. var (
  33. res = &msgReturn{}
  34. )
  35. params := url.Values{}
  36. params.Set("mc", _msgReporterKey)
  37. params.Set("title", _msgReporterTitle)
  38. params.Set("data_type", "4")
  39. params.Set("context", d.createReportContent(rptMsg))
  40. params.Set("mid_list", rptMsg.Uids)
  41. err = d.httpCli.Post(c, d.sendNotifyURI, "", params, res)
  42. if err != nil {
  43. log.Error("d.httpCli.Post(%s) error(%v)", d.sendNotifyURI+"?"+params.Encode(), err)
  44. return
  45. }
  46. if res.Code != 0 {
  47. err = fmt.Errorf("return code:%d", res.Code)
  48. log.Error("d.httpCli.Post(%s) error(%v)", d.sendNotifyURI+"?"+params.Encode(), err)
  49. }
  50. return
  51. }
  52. func (d *Dao) createReportContent(rptMsg *model.ReportMsg) (content string) {
  53. if rptMsg.State == model.StatSecondAutoDelete ||
  54. rptMsg.State == model.StatFirstDelete ||
  55. rptMsg.State == model.StatSecondDelete {
  56. if rptMsg.Block != 0 { // 如果未封禁
  57. content = fmt.Sprintf(model.RptTemplate["del"], rptMsg.Title, rptMsg.Aid, rptMsg.Msg, ",该用户已被封禁", model.BlockReason[rptMsg.BlockReason])
  58. } else {
  59. content = fmt.Sprintf(model.RptTemplate["del"], rptMsg.Title, rptMsg.Aid, rptMsg.Msg, "", model.AdminRptReason[rptMsg.RptReason])
  60. }
  61. } else {
  62. content = fmt.Sprintf(model.RptTemplate["ignore"], rptMsg.Title, rptMsg.Aid, rptMsg.Msg)
  63. }
  64. return
  65. }
  66. // SendMsgToPoster send message
  67. func (d *Dao) SendMsgToPoster(c context.Context, rptMsg *model.ReportMsg) (err error) {
  68. var (
  69. res = &msgReturn{}
  70. )
  71. params := url.Values{}
  72. params.Set("mc", _msgPosterKey)
  73. params.Set("title", _msgPosterTitle)
  74. params.Set("data_type", "4")
  75. msgContent, err := d.createPosterContent(rptMsg)
  76. if err != nil {
  77. log.Error("d.SendMsgToPoster error(%v)", err)
  78. return
  79. }
  80. params.Set("context", msgContent)
  81. params.Set("mid_list", rptMsg.Uids)
  82. err = d.httpCli.Post(c, d.sendNotifyURI, "", params, res)
  83. if err != nil {
  84. log.Error("d.httpCli.Post(%s) error(%v)", d.sendNotifyURI+"?"+params.Encode(), err)
  85. return
  86. }
  87. if res.Code != 0 {
  88. err = fmt.Errorf("return code:%d", res.Code)
  89. log.Error("d.httpCli.Post(%s) error(%v)", d.sendNotifyURI+"?"+params.Encode(), err)
  90. }
  91. return
  92. }
  93. func (d *Dao) createPosterContent(rptMsg *model.ReportMsg) (content string, err error) {
  94. var (
  95. part1, part2, tmpl string
  96. )
  97. if rptMsg.Block > 0 {
  98. part1 = fmt.Sprintf(",并被封禁%d天", rptMsg.Block)
  99. part2 = model.BlockReason[rptMsg.BlockReason]
  100. tmpl, err = model.PosterBlockMsg(rptMsg.BlockReason)
  101. if err != nil {
  102. log.Error("reportModel.PosterBlockMsg error(%v)", err)
  103. return
  104. }
  105. content = fmt.Sprintf(tmpl, rptMsg.Title, rptMsg.Aid, rptMsg.Msg, part1, part2)
  106. } else if rptMsg.Block == -1 {
  107. part1 = ",并被永久封禁"
  108. part2 = model.BlockReason[rptMsg.BlockReason]
  109. tmpl, err = model.PosterBlockMsg(rptMsg.BlockReason)
  110. if err != nil {
  111. log.Error("reportModel.PosterBlockMsg error(%v)", err)
  112. return
  113. }
  114. content = fmt.Sprintf(tmpl, rptMsg.Title, rptMsg.Aid, rptMsg.Msg, part1, part2)
  115. } else {
  116. part1 = ""
  117. part2 = model.AdminRptReason[rptMsg.RptReason]
  118. tmpl, err = model.PosterAdminRptMsg(rptMsg.RptReason)
  119. if err != nil {
  120. log.Error("report.PosterAdminRptMsg error(%v)", err)
  121. return
  122. }
  123. content = fmt.Sprintf(tmpl, rptMsg.Title, rptMsg.Aid, rptMsg.Msg, part1, part2)
  124. }
  125. return
  126. }
  127. // SendMsgToSubtitleUp .
  128. func (d *Dao) SendMsgToSubtitleUp(c context.Context, arg *model.NotifySubtitleUp) (err error) {
  129. var (
  130. res = &msgReturn{}
  131. )
  132. params := url.Values{}
  133. params.Set("mc", _msgSubtitleUpKey)
  134. params.Set("title", _msgSubtitleTitle)
  135. params.Set("data_type", "4")
  136. params.Set("context", arg.Msg())
  137. params.Set("mid_list", fmt.Sprint(arg.Mid))
  138. err = d.httpCli.Post(c, d.sendNotifyURI, "", params, res)
  139. if err != nil {
  140. log.Error("d.httpCli.Post(%s) error(%v)", d.sendNotifyURI+"?"+params.Encode(), err)
  141. return
  142. }
  143. if res.Code != 0 {
  144. err = fmt.Errorf("return code:%d", res.Code)
  145. log.Error("d.httpCli.Post(%s) error(%v)", d.sendNotifyURI+"?"+params.Encode(), err)
  146. }
  147. return
  148. }
  149. // SendMsgToSubtitleUser .
  150. func (d *Dao) SendMsgToSubtitleUser(c context.Context, arg *model.NotifySubtitleUser) (err error) {
  151. var (
  152. res = &msgReturn{}
  153. )
  154. params := url.Values{}
  155. params.Set("mc", _msgSubtitleUserKey)
  156. params.Set("title", _msgSubtitleTitle)
  157. params.Set("data_type", "4")
  158. params.Set("context", arg.Msg())
  159. params.Set("mid_list", fmt.Sprint(arg.Mid))
  160. err = d.httpCli.Post(c, d.sendNotifyURI, "", params, res)
  161. if err != nil {
  162. log.Error("d.httpCli.Post(%s) error(%v)", d.sendNotifyURI+"?"+params.Encode(), err)
  163. return
  164. }
  165. if res.Code != 0 {
  166. err = fmt.Errorf("return code:%d", res.Code)
  167. log.Error("d.httpCli.Post(%s) error(%v)", d.sendNotifyURI+"?"+params.Encode(), err)
  168. }
  169. return
  170. }