community_question_comment.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/wx_user"
  7. "hongze/hongze_mobile_admin/models/tables/yb_community_question_comment"
  8. "hongze/hongze_mobile_admin/utils"
  9. "strings"
  10. "time"
  11. )
  12. // GetCommunityQuestionCommentList 问答评论列表
  13. func GetCommunityQuestionCommentList(condition string, pars []interface{}, startSize, pageSize int) (total int, commentList []*ybResponse.CommunityQuestionCommentItem, err error) {
  14. commentList = make([]*ybResponse.CommunityQuestionCommentItem, 0)
  15. total, list, e := yb_community_question_comment.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
  16. if e != nil {
  17. err = errors.New("获取问题列表失败 Err:" + e.Error())
  18. return
  19. }
  20. if len(list) == 0 {
  21. return
  22. }
  23. // 查找用户
  24. userIdArr := make([]string, 0)
  25. for _, v := range list {
  26. userIdArr = append(userIdArr, fmt.Sprint(v.UserId))
  27. }
  28. //评论人信息
  29. wxUserCompanyInfoMap := make(map[int]*wx_user.UserCompanyInfoList, 0)
  30. if len(userIdArr) > 0 {
  31. userIds := strings.Join(userIdArr, ",")
  32. wxUserCompanyInfoList, tmpErr := wx_user.GetUserListByUserIds(userIds)
  33. if tmpErr != nil {
  34. err = tmpErr
  35. return
  36. }
  37. for _, v := range wxUserCompanyInfoList {
  38. wxUserCompanyInfoMap[v.UserId] = v
  39. }
  40. }
  41. for _, v := range list {
  42. item := &ybResponse.CommunityQuestionCommentItem{
  43. CommunityQuestionCommentId: v.CommunityQuestionCommentId,
  44. CommunityQuestionId: v.CommunityQuestionId,
  45. UserId: v.UserId,
  46. Content: v.Content,
  47. IsTop: v.IsTop,
  48. IsHot: v.IsHot,
  49. HotTopTime: v.HotTopTime,
  50. IsShowName: v.IsShowName,
  51. SourceAgent: v.SourceAgent,
  52. TopTime: v.TopTime,
  53. HotTime: v.HotTime,
  54. ModifyTime: v.ModifyTime,
  55. CreateTime: v.CreateTime,
  56. QuestionContent: v.QuestionContent,
  57. CompanyId: 0,
  58. UserName: "",
  59. CompanyName: "",
  60. CompanyProductStatus: "",
  61. }
  62. //评论人信息
  63. if tmpWxUserCompanyInfo, ok := wxUserCompanyInfoMap[int(v.UserId)]; ok {
  64. item.CompanyId = tmpWxUserCompanyInfo.CompanyId
  65. item.UserName = tmpWxUserCompanyInfo.RealName
  66. item.CompanyName = tmpWxUserCompanyInfo.CompanyName
  67. item.CompanyProductStatus = tmpWxUserCompanyInfo.CompanyProductStatus
  68. }
  69. commentList = append(commentList, item)
  70. }
  71. return
  72. }
  73. // SoftDeleteQuestionComment 删除问题评论
  74. func SoftDeleteQuestionComment(questionCommentId int) (err error, errMsg string) {
  75. errMsg = `删除成功`
  76. questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
  77. if err != nil {
  78. errMsg = "查找评论失败"
  79. if err.Error() == utils.ErrNoRow() {
  80. errMsg = "该评论不存在"
  81. }
  82. return
  83. }
  84. //标记删除
  85. questionCommentInfo.Enabled = 0
  86. questionCommentInfo.ModifyTime = time.Now()
  87. err = questionCommentInfo.Update([]string{"Enabled", "ModifyTime"})
  88. if err != nil {
  89. errMsg = "删除提问失败"
  90. }
  91. return
  92. }
  93. // SetHotQuestionComment 设置/取消 问题评论精选
  94. func SetHotQuestionComment(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. //var isHot int8
  105. isHot := int8(1)
  106. if questionCommentInfo.IsHot == 1 {
  107. isHot = 0
  108. }
  109. //标记删除
  110. questionCommentInfo.IsHot = isHot //是否设置精选(0-未设置,1-已设置)
  111. questionCommentInfo.HotTopTime = time.Now()
  112. questionCommentInfo.HotTime = time.Now()
  113. questionCommentInfo.ModifyTime = time.Now()
  114. err = questionCommentInfo.Update([]string{"IsHot", "HotTopTime", "HotTime", "ModifyTime"})
  115. if err != nil {
  116. errMsg = "操作失败"
  117. }
  118. return
  119. }