package yb_community_question_comment import "hongze/hongze_yb/global" // Update 更新对应字段数据 func (item *YbCommunityQuestionComment) Update(updateCols []string) (err error) { err = global.DEFAULT_MYSQL.Model(item).Select(updateCols).Updates(*item).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 := ` UPDATE yb_community_question_comment SET enabled = 0, modify_time = NOW(), is_hot = 0, is_top = 0 WHERE type = 1 and user_id = ? and community_question_comment_id = ?` err = tx.Exec(sql1, userId, commentId).Error if err != nil { return } // 删除相关联的回复 sql2 := ` UPDATE yb_community_question_comment SET enabled = 0, modify_time = NOW() WHERE reply_comment_id = ? and type = 2` err = tx.Exec(sql2, commentId).Error return }