msg.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package service
  2. import (
  3. "fmt"
  4. "go-common/app/admin/main/block/conf"
  5. "go-common/app/admin/main/block/model"
  6. "go-common/library/log"
  7. )
  8. // MSGInfo get msg info
  9. func (s *Service) MSGInfo(source model.BlockSource, action model.BlockAction, area model.BlockArea, reason string, days int64) (code string, title, content string) {
  10. if source == model.BlockSourceBlackHouse {
  11. areaStr := area.String()
  12. if areaStr != "" {
  13. areaStr = fmt.Sprintf("在%s中", areaStr)
  14. }
  15. if action == model.BlockActionLimit {
  16. code = conf.Conf.Property.MSG.BlackHouseLimit.Code
  17. title = conf.Conf.Property.MSG.BlackHouseLimit.Title
  18. content = fmt.Sprintf(conf.Conf.Property.MSG.BlackHouseLimit.Content, areaStr, s.convertReason(reason), days)
  19. return
  20. }
  21. if action == model.BlockActionForever {
  22. code = conf.Conf.Property.MSG.BlackHouseForever.Code
  23. title = conf.Conf.Property.MSG.BlackHouseForever.Title
  24. content = fmt.Sprintf(conf.Conf.Property.MSG.BlackHouseForever.Content, areaStr, s.convertReason(reason))
  25. return
  26. }
  27. }
  28. if source == model.BlockSourceSys {
  29. if action == model.BlockActionLimit {
  30. code = conf.Conf.Property.MSG.SysLimit.Code
  31. title = conf.Conf.Property.MSG.SysLimit.Title
  32. content = fmt.Sprintf(conf.Conf.Property.MSG.SysLimit.Content, s.convertReason(reason), days)
  33. return
  34. }
  35. if action == model.BlockActionForever {
  36. code = conf.Conf.Property.MSG.SysForever.Code
  37. title = conf.Conf.Property.MSG.SysForever.Title
  38. content = fmt.Sprintf(conf.Conf.Property.MSG.SysForever.Content, s.convertReason(reason))
  39. return
  40. }
  41. }
  42. if action == model.BlockActionAdminRemove || action == model.BlockActionSelfRemove {
  43. code = conf.Conf.Property.MSG.BlockRemove.Code
  44. title = conf.Conf.Property.MSG.BlockRemove.Title
  45. content = conf.Conf.Property.MSG.BlockRemove.Content
  46. return
  47. }
  48. log.Error("s.MSGInfo unkown source[%v] action[%v] area[%v] reason[%s] days[%d]", source, action, area, reason, days)
  49. return
  50. }
  51. func (s *Service) convertReason(reason string) string {
  52. switch reason {
  53. case "账号资料相关违规":
  54. return "账号资料违规"
  55. case "作品投稿违规":
  56. return "作品投稿违规"
  57. case "异常注册账号":
  58. return "异常注册"
  59. case "异常答题账号":
  60. return "异常答题"
  61. case "异常数据行为":
  62. return "异常数据行为"
  63. case "发布违规信息":
  64. return "发布违规信息"
  65. case "其他自动封禁", "手动封禁":
  66. return "违反社区规则"
  67. default:
  68. return reason
  69. }
  70. }