update.go 765 B

1234567891011121314151617181920212223242526272829303132
  1. package yb_comment
  2. import "hongze/hongze_yb/global"
  3. // Update 更新对应字段数据
  4. /*func (yc *YbComment) Update(updateCols []string) (err error) {
  5. err = global.DEFAULT_MYSQL.Model(yc).Select(updateCols).Updates(*yc).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 := ` Delete from yb_comment WHERE type = 1 and user_id = ? and comment_id = ?`
  19. err = tx.Exec(sql1, userId, commentId).Error
  20. if err != nil {
  21. return
  22. }
  23. // 删除相关联的回复
  24. sql2 := `Delete from yb_comment WHERE reply_comment_id = ? and type = 2`
  25. err = tx.Exec(sql2, commentId).Error
  26. return
  27. }