community_question_comment.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package yb
  2. import (
  3. "errors"
  4. "hongze/hz_crm_api/models/company"
  5. "hongze/hz_crm_api/models/yb"
  6. "hongze/hz_crm_api/services"
  7. "hongze/hz_crm_api/services/alarm_msg"
  8. "hongze/hz_crm_api/utils"
  9. "time"
  10. )
  11. // SoftDeleteQuestionComment 删除问题评论
  12. func SoftDeleteQuestionComment(questionCommentId int) (err error, errMsg string) {
  13. errMsg = `删除成功`
  14. questionCommentInfo, err := yb.GetQuestionCommentById(questionCommentId)
  15. if err != nil {
  16. errMsg = "查找评论失败"
  17. if err.Error() == utils.ErrNoRow() {
  18. errMsg = "该评论不存在"
  19. }
  20. return
  21. }
  22. //标记删除
  23. questionCommentInfo.Enabled = 0
  24. questionCommentInfo.ModifyTime = time.Now()
  25. err = questionCommentInfo.Update([]string{"Enabled", "ModifyTime"})
  26. if err != nil {
  27. errMsg = "删除提问失败"
  28. return
  29. }
  30. // 删除评论后的逻辑处理
  31. go afterDeleteComment(questionCommentInfo)
  32. return
  33. }
  34. // DeleteQuestionComment 删除问题评论
  35. func DeleteQuestionComment(questionCommentId int) (err error, errMsg string) {
  36. errMsg = `删除成功`
  37. questionCommentInfo, err := yb.GetQuestionCommentById(questionCommentId)
  38. if err != nil {
  39. errMsg = "查找评论失败"
  40. if err.Error() == utils.ErrNoRow() {
  41. errMsg = "该评论不存在"
  42. }
  43. return
  44. }
  45. //标记删除
  46. questionCommentInfo.Enabled = 0
  47. questionCommentInfo.ModifyTime = time.Now()
  48. err = questionCommentInfo.Delete()
  49. if err != nil {
  50. errMsg = "删除提问失败"
  51. return
  52. }
  53. // 删除评论后的逻辑处理
  54. go afterDeleteComment(questionCommentInfo)
  55. return
  56. }
  57. // SetHotQuestionComment 设置/取消 问题评论精选
  58. func SetHotQuestionComment(questionCommentId int) (err error, errMsg string) {
  59. errMsg = `操作失败`
  60. questionCommentInfo, err := yb.GetQuestionCommentById(questionCommentId)
  61. if err != nil {
  62. errMsg = "查找评论失败"
  63. if err.Error() == utils.ErrNoRow() {
  64. errMsg = "该评论不存在"
  65. }
  66. return
  67. }
  68. //var isHot int8
  69. isHot := int8(1)
  70. if questionCommentInfo.IsHot == 1 {
  71. isHot = 0
  72. }
  73. //标记删除
  74. questionCommentInfo.IsHot = isHot //是否设置精选(0-未设置,1-已设置)
  75. questionCommentInfo.HotTopTime = time.Now()
  76. questionCommentInfo.HotTime = time.Now()
  77. questionCommentInfo.ModifyTime = time.Now()
  78. err = questionCommentInfo.Update([]string{"IsHot", "HotTopTime", "HotTime", "ModifyTime"})
  79. if err != nil {
  80. errMsg = "操作失败"
  81. }
  82. return
  83. }
  84. // afterDeleteComment 删除评论后的逻辑处理
  85. func afterDeleteComment(communityQuestionComment *yb.YbCommunityQuestionComment) {
  86. var err error
  87. defer func() {
  88. if err != nil {
  89. go alarm_msg.SendAlarmMsg("问答评论信息删除后,标记站内消息失败"+time.Now().Format(utils.FormatDateTime)+";Err:"+err.Error(), 3)
  90. }
  91. }()
  92. sourceType := 0
  93. switch communityQuestionComment.Source {
  94. case 1:
  95. sourceType = services.CompanyApprovalMessageSourceTypeByQuestionComment
  96. case 2:
  97. sourceType = services.CompanyApprovalMessageSourceTypeByVideoComment
  98. case 3:
  99. sourceType = services.CompanyApprovalMessageSourceTypeByRoadVideoComment
  100. default:
  101. err = errors.New("sourceType有误")
  102. return
  103. }
  104. err = company.CancelCompanyApprovalMessage(int(communityQuestionComment.CommunityQuestionCommentId), sourceType)
  105. return
  106. }