package yb_comment import "hongze/hongze_yb/global" // Update 更新对应字段数据 /*func (yc *YbComment) Update(updateCols []string) (err error) { err = global.DEFAULT_MYSQL.Model(yc).Select(updateCols).Updates(*yc).Error return }*/ // Delete 直接删除留言 func Delete(userId uint64, commentId uint64)(err error) { tx := global.DEFAULT_MYSQL.Begin() defer func() { if err != nil { tx.Rollback() } else { tx.Commit() } }() sql1 := ` Delete from yb_comment WHERE type = 1 and user_id = ? and comment_id = ?` err = tx.Exec(sql1, userId, commentId).Error if err != nil { return } // 删除相关联的回复 sql2 := `Delete from yb_comment WHERE reply_comment_id = ? and type = 2` err = tx.Exec(sql2, commentId).Error return }