community_question_comment.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package yb
  2. import (
  3. "errors"
  4. "fmt"
  5. ybResponse "hongze/hongze_mobile_admin/models/response/yb"
  6. "hongze/hongze_mobile_admin/models/tables/company_approval_message"
  7. "hongze/hongze_mobile_admin/models/tables/wx_user"
  8. "hongze/hongze_mobile_admin/models/tables/yb_community_question_comment"
  9. "hongze/hongze_mobile_admin/services"
  10. "hongze/hongze_mobile_admin/services/alarm_msg"
  11. "hongze/hongze_mobile_admin/utils"
  12. "strings"
  13. "time"
  14. )
  15. // GetCommunityQuestionCommentList 问答评论列表
  16. func GetCommunityQuestionCommentList(condition string, pars []interface{}, startSize, pageSize, source int) (total int, commentList []*ybResponse.CommunityQuestionCommentItem, err error) {
  17. commentList = make([]*ybResponse.CommunityQuestionCommentItem, 0)
  18. list := make([]*yb_community_question_comment.YbCommunityQuestionCommentAndQuestion, 0)
  19. // 来源
  20. if source == 1 {
  21. qaTotal, qaList, e := yb_community_question_comment.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
  22. if e != nil {
  23. err = errors.New("获取问题列表失败 Err:" + e.Error())
  24. return
  25. }
  26. list = qaList
  27. total = qaTotal
  28. } else {
  29. // 视频社区
  30. vcTotal, vcList, e := yb_community_question_comment.GetCommunityVideoCommentList(condition, pars, startSize, pageSize)
  31. if e != nil {
  32. err = errors.New("获取视频评论列表失败 Err:" + e.Error())
  33. return
  34. }
  35. list = vcList
  36. total = vcTotal
  37. }
  38. if len(list) == 0 {
  39. return
  40. }
  41. // 查找用户
  42. userIdArr := make([]string, 0)
  43. for _, v := range list {
  44. userIdArr = append(userIdArr, fmt.Sprint(v.UserId))
  45. }
  46. //评论人信息
  47. wxUserCompanyInfoMap := make(map[int]*wx_user.UserCompanyInfoList, 0)
  48. if len(userIdArr) > 0 {
  49. userIds := strings.Join(userIdArr, ",")
  50. wxUserCompanyInfoList, tmpErr := wx_user.GetUserListByUserIds(userIds)
  51. if tmpErr != nil {
  52. err = tmpErr
  53. return
  54. }
  55. for _, v := range wxUserCompanyInfoList {
  56. wxUserCompanyInfoMap[v.UserId] = v
  57. }
  58. }
  59. for _, v := range list {
  60. item := &ybResponse.CommunityQuestionCommentItem{
  61. CommunityQuestionCommentId: v.CommunityQuestionCommentId,
  62. CommunityQuestionId: v.CommunityQuestionId,
  63. UserId: v.UserId,
  64. Content: v.Content,
  65. IsTop: v.IsTop,
  66. IsHot: v.IsHot,
  67. HotTopTime: v.HotTopTime,
  68. IsShowName: v.IsShowName,
  69. SourceAgent: v.SourceAgent,
  70. TopTime: v.TopTime,
  71. HotTime: v.HotTime,
  72. ModifyTime: v.ModifyTime,
  73. CreateTime: v.CreateTime,
  74. QuestionContent: v.QuestionContent,
  75. CompanyId: 0,
  76. UserName: "",
  77. CompanyName: "",
  78. CompanyProductStatus: "",
  79. Source: v.Source,
  80. TagName: v.TagName,
  81. }
  82. //评论人信息
  83. if tmpWxUserCompanyInfo, ok := wxUserCompanyInfoMap[int(v.UserId)]; ok {
  84. item.CompanyId = tmpWxUserCompanyInfo.CompanyId
  85. item.UserName = tmpWxUserCompanyInfo.RealName
  86. item.CompanyName = tmpWxUserCompanyInfo.CompanyName
  87. item.CompanyProductStatus = tmpWxUserCompanyInfo.CompanyProductStatus
  88. }
  89. commentList = append(commentList, item)
  90. }
  91. return
  92. }
  93. // SoftDeleteQuestionComment 删除问题评论
  94. func SoftDeleteQuestionComment(questionCommentId int) (err error, errMsg string) {
  95. errMsg = `删除成功`
  96. questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
  97. if err != nil {
  98. errMsg = "查找评论失败"
  99. if err.Error() == utils.ErrNoRow() {
  100. errMsg = "该评论不存在"
  101. }
  102. return
  103. }
  104. //标记删除
  105. questionCommentInfo.Enabled = 0
  106. questionCommentInfo.ModifyTime = time.Now()
  107. err = questionCommentInfo.Update([]string{"Enabled", "ModifyTime"})
  108. if err != nil {
  109. errMsg = "删除提问失败"
  110. return
  111. }
  112. // 删除评论后的逻辑处理
  113. go afterDeleteComment(questionCommentInfo)
  114. return
  115. }
  116. // SetHotQuestionComment 设置/取消 问题评论精选
  117. func SetHotQuestionComment(questionCommentId int) (err error, errMsg string) {
  118. errMsg = `操作失败`
  119. questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
  120. if err != nil {
  121. errMsg = "查找评论失败"
  122. if err.Error() == utils.ErrNoRow() {
  123. errMsg = "该评论不存在"
  124. }
  125. return
  126. }
  127. //var isHot int8
  128. isHot := int8(1)
  129. if questionCommentInfo.IsHot == 1 {
  130. isHot = 0
  131. }
  132. //标记删除
  133. questionCommentInfo.IsHot = isHot //是否设置精选(0-未设置,1-已设置)
  134. questionCommentInfo.HotTopTime = time.Now()
  135. questionCommentInfo.HotTime = time.Now()
  136. questionCommentInfo.ModifyTime = time.Now()
  137. err = questionCommentInfo.Update([]string{"IsHot", "HotTopTime", "HotTime", "ModifyTime"})
  138. if err != nil {
  139. errMsg = "操作失败"
  140. }
  141. return
  142. }
  143. // afterDeleteComment 删除评论后的逻辑处理
  144. func afterDeleteComment(communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
  145. var err error
  146. defer func() {
  147. if err != nil {
  148. go alarm_msg.SendAlarmMsg("问答评论信息删除后,标记站内消息失败"+time.Now().Format(utils.FormatDateTime)+";Err:"+err.Error(), 3)
  149. }
  150. }()
  151. sourceType := services.CompanyApprovalMessageSourceTypeByQuestionComment
  152. if communityQuestionComment.Source == 2 {
  153. sourceType = services.CompanyApprovalMessageSourceTypeByVideoComment
  154. }
  155. err = company_approval_message.CancelCompanyApprovalMessage(int(communityQuestionComment.CommunityQuestionCommentId), sourceType)
  156. return
  157. }