删除评论
(id int)
| 176 | |
| 177 | // 删除评论 |
| 178 | func (this *Comments) DeleteComment(id int) { |
| 179 | m := &Comments{} |
| 180 | o := orm.NewOrm() |
| 181 | o.QueryTable(m).Filter("id", id).One(m, "book_id") |
| 182 | if m.BookId > 0 && m.DocId == 0 { |
| 183 | o.QueryTable(m).Filter("id", id).Delete() |
| 184 | sql := "update md_books set cnt_comment = cnt_comment - 1 where cnt_comment > 0 and book_id = ?" |
| 185 | _, err := o.Raw(sql, m.BookId).Exec() |
| 186 | if err != nil { |
| 187 | beego.Error(err.Error()) |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | func (this *Comments) Count(bookId int, status ...int) (int64, error) { |
| 193 | query := orm.NewOrm().QueryTable(this) |