update.go 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package yb_community_question_comment
  2. import "hongze/hongze_yb/global"
  3. // Update 更新对应字段数据
  4. func (item *YbCommunityQuestionComment) Update(updateCols []string) (err error) {
  5. err = global.DEFAULT_MYSQL.Model(item).Select(updateCols).Updates(*item).Error
  6. return
  7. }
  8. // Delete 软删除,隐藏评论
  9. func Delete(userId uint64, commentId uint64) (err error) {
  10. tx := global.DEFAULT_MYSQL.Begin()
  11. defer func() {
  12. if err != nil {
  13. tx.Rollback()
  14. } else {
  15. tx.Commit()
  16. }
  17. }()
  18. sql1 := ` UPDATE yb_community_question_comment
  19. SET
  20. enabled = 0,
  21. modify_time = NOW(),
  22. is_hot = 0,
  23. is_top = 0
  24. WHERE type = 1 and user_id = ? and community_question_comment_id = ?`
  25. err = tx.Exec(sql1, userId, commentId).Error
  26. if err != nil {
  27. return
  28. }
  29. // 删除相关联的回复
  30. sql2 := ` UPDATE yb_community_question_comment
  31. SET
  32. enabled = 0,
  33. modify_time = NOW()
  34. WHERE reply_comment_id = ? and type = 2`
  35. err = tx.Exec(sql2, commentId).Error
  36. return
  37. }