(bookId int, isPV bool)
| 77 | } |
| 78 | |
| 79 | func (*BookCounter) Decrease(bookId int, isPV bool) { |
| 80 | sc := NewBookCounter() |
| 81 | today, _ := strconv.Atoi(time.Now().Format(dateFormat)) |
| 82 | o := orm.NewOrm() |
| 83 | o.QueryTable(sc).Filter("bid", bookId).Filter("day", today).One(sc) |
| 84 | if sc.Id == 0 { |
| 85 | sc = &BookCounter{ |
| 86 | Bid: bookId, |
| 87 | Day: today, |
| 88 | } |
| 89 | if isPV { |
| 90 | sc.ViewCnt = 1 |
| 91 | } else { |
| 92 | sc.StarCnt = 1 |
| 93 | } |
| 94 | o.Insert(sc) |
| 95 | } else { |
| 96 | if isPV { |
| 97 | if sc.ViewCnt > 0 { |
| 98 | sc.ViewCnt -= 1 |
| 99 | } |
| 100 | } else { |
| 101 | if sc.StarCnt > 0 { |
| 102 | sc.StarCnt -= 1 |
| 103 | } |
| 104 | } |
| 105 | o.Update(sc) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | func (m *BookCounter) StarSort(prd period, limit int, withCache ...bool) (books []SortedBook) { |
| 110 | return m._sort(prd, limit, "star", withCache...) |
no test coverage detected