jury.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "go-common/app/job/main/credit/model"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _msgTitle = "风纪委员任期结束"
  13. _msgContext = "您的风纪委员资格已到期,任职期间的总结报告已生成。感谢您对社区工作的大力支持!#{点击查看}{" + "\"http://www.bilibili.com/judgement/\"" + "}"
  14. _appealTitle = "账号违规处理通知"
  15. _appealContent = `抱歉,你的账号因"在%s中%s",现已进行%s处理,账号解封需要满足以下两个条件:1.账号封禁时间已满。2.完成解封答题( #{点击进入解封答题}{"http://www.bilibili.com/blackroom/releaseexame.html"} )全部完成后解封。封禁期间将无法投稿、发送及回复消息,无法发布评论、弹幕,无法对他人评论进行回复、赞踩操作,无法进行投币、编辑标签、添加关注、添加收藏操作。如对处罚有异议,可在7日内进行申诉,
  16. #{点击申诉}{"http://www.bilibili.com/judgement/appeal?bid=%d"} 。请遵守社区规范,共同维护良好的社区氛围!`
  17. )
  18. // Judge judge case.
  19. func (s *Service) Judge(c context.Context, nwMsg []byte, oldMsg []byte) (err error) {
  20. var (
  21. sum int64
  22. mr = &model.Case{}
  23. bc model.Case
  24. judge int64
  25. status int64
  26. yratio int64
  27. nratio int64
  28. judgeRadio = s.c.Judge.JudgeRadio
  29. voteMin = s.c.Judge.CaseVoteMin
  30. )
  31. if err = json.Unmarshal(nwMsg, mr); err != nil {
  32. log.Error("json.Unmarshal(%s) error(%v)", string(nwMsg), err)
  33. return
  34. }
  35. if mr.CaseType == model.JudeCaseTypePublic {
  36. return
  37. }
  38. if mr.Status != model.CaseStatusDealing {
  39. return
  40. }
  41. if bc, err = s.dao.CaseByID(c, mr.ID); err != nil {
  42. log.Error("s.dao.CaseByID error(%v)", err)
  43. return
  44. }
  45. if bc.Status == model.CaseStatusDealed || bc.Status == model.CaseStatusUndealed {
  46. return
  47. }
  48. sum = mr.Against + mr.Agree + mr.VoteDelete
  49. if voteMin <= 0 {
  50. log.Error("CaseVoteMin(%d) error(%v)", voteMin, err)
  51. return
  52. }
  53. if sum < voteMin {
  54. status = model.CaseStatusUndealed
  55. judge = model.JudgeTypeUndeal
  56. s.dao.UpdateCase(c, status, judge, mr.ID)
  57. return
  58. }
  59. yratio = mr.Agree * 100 / sum
  60. nratio = (mr.Against + mr.VoteDelete) * 100 / sum
  61. if judgeRadio <= 50 {
  62. log.Error("CaseJudgeRadio(%d) error(%v)", judgeRadio, err)
  63. return
  64. }
  65. if yratio >= judgeRadio {
  66. status = model.CaseStatusDealed
  67. judge = model.JudgeTypeLegal
  68. } else if nratio >= judgeRadio {
  69. status = model.CaseStatusDealed
  70. judge = model.JudgeTypeViolate
  71. } else {
  72. status = model.CaseStatusUndealed
  73. judge = model.JudgeTypeUndeal
  74. }
  75. s.dao.UpdateCase(c, status, judge, mr.ID)
  76. mr.Status = status
  77. mr.JudgeType = judge
  78. if status == model.CaseStatusDealed {
  79. s.BlockUser(c, mr)
  80. s.UpdateVoteCount(c, mr)
  81. s.dao.DelGrantCase(c, []int64{mr.ID})
  82. } else {
  83. if mr.OriginType == int64(model.OriginDM) {
  84. if mr.RelationID != "" {
  85. args := strings.Split(mr.RelationID, "-")
  86. if len(args) != 4 {
  87. return
  88. }
  89. s.dao.ReportDM(c, args[2], args[1], model.DMNotifyNotDel)
  90. }
  91. }
  92. }
  93. return
  94. }
  95. // BlockUser add user block.
  96. func (s *Service) BlockUser(c context.Context, mr *model.Case) (err error) {
  97. if mr.JudgeType == model.JudgeTypeViolate {
  98. s.DelOrigin(c, mr)
  99. if mr.Against <= mr.VoteDelete+mr.Agree {
  100. err = s.dealMoralCase(c, mr)
  101. return
  102. }
  103. var (
  104. ok bool
  105. punishType int64
  106. )
  107. forever, days := mr.BlockDays()
  108. if forever != model.InBlockedForever {
  109. punishType = int64(model.PunishTypeBlock)
  110. } else {
  111. punishType = int64(model.PunishTypeForever)
  112. }
  113. r := &model.BlockedInfo{
  114. UID: mr.Mid,
  115. PunishType: punishType,
  116. BlockedType: model.PunishJury,
  117. OperatorName: mr.Operator,
  118. CaseID: mr.ID,
  119. Origin: mr.Origin,
  120. OPID: mr.OPID,
  121. BlockedForever: forever,
  122. BlockedDays: days,
  123. }
  124. r.OriginContentModify = r.OriginContent
  125. if ok, err = s.CheckBlock(c, mr.Mid); err != nil || !ok {
  126. return
  127. }
  128. if mr.BusinessTime != model.DefaultTime {
  129. ok, _, err = s.jugeBlockedUser(c, mr.Mid, mr.BusinessTime, model.DealTimeTypeNone)
  130. if err != nil {
  131. log.Error("s.jugeBlockedUser(%d,%s,%d) error(%v)", mr.Mid, mr.BusinessTime, model.DealTimeTypeNone, err)
  132. return
  133. }
  134. } else {
  135. ok, _, err = s.jugeBlockedUser(c, mr.Mid, mr.Ctime, model.DealTimeTypeDay)
  136. if err != nil {
  137. log.Error("s.jugeBlockedUser(%d,%s,%d) error(%v)", mr.Mid, mr.Ctime, model.DealTimeTypeDay, err)
  138. return
  139. }
  140. }
  141. if ok {
  142. var id int64
  143. id, err = s.dao.AddBlockInfo(c, r, time.Now())
  144. if err != nil {
  145. log.Error("s.dao.AddBlockInfo error(%v)", err)
  146. return
  147. }
  148. if err = s.dao.BlockAccount(c, r); err != nil {
  149. log.Error("s.dao.BlockAccount(%+v) error(%v)", r, err)
  150. return
  151. }
  152. s.dao.SendMsg(c, mr.Mid, _appealTitle, fmt.Sprintf(_appealContent, model.OriginTypeDesc(int8(mr.OriginType)), model.ReasonTypeDesc(int8(mr.ReasonType)), model.BlockedDayDesc(int8(mr.BlockedDay)), id))
  153. }
  154. } else if mr.JudgeType == model.JudgeTypeLegal {
  155. if mr.JudgeType == int64(model.OriginDM) {
  156. s.dao.UpdatePunishResult(c, mr.ID, model.BlockNone)
  157. if mr.RelationID != "" {
  158. args := strings.Split(mr.RelationID, "-")
  159. if len(args) != 4 {
  160. return
  161. }
  162. s.dao.ReportDM(c, args[2], args[1], model.DMNotifyNotDel)
  163. }
  164. }
  165. }
  166. return
  167. }
  168. func (s *Service) dealMoralCase(c context.Context, mr *model.Case) (err error) {
  169. if err = s.dao.UpdatePunishResult(c, mr.ID, model.BlockOnlyDel); err != nil {
  170. log.Error("UpdatePunishResult error(%v)", err)
  171. return
  172. }
  173. title, content := model.OriginMsgContent(mr.OriginTitle, mr.OriginURL, mr.OriginContent, int8(mr.OriginType))
  174. for i := 0; i <= 5; i++ {
  175. if err := s.dao.AddMoral(c, mr.Mid, model.DefealtMoralVal, model.OrginMoralType(int8(mr.OriginType)), model.BUSSINESS, model.ReasonTypeDesc(int8(mr.ReasonType)), model.MoralRemark, ""); err != nil {
  176. continue
  177. }
  178. break
  179. }
  180. for i := 0; i <= 5; i++ {
  181. if err := s.dao.SendMsg(c, mr.Mid, title, content); err != nil {
  182. continue
  183. }
  184. break
  185. }
  186. return
  187. }