查询阅读进度
(uid, bookId int)
| 255 | |
| 256 | //查询阅读进度 |
| 257 | func (this *ReadRecord) Progress(uid, bookId int) (rp ReadProgress, err error) { |
| 258 | if uid*bookId == 0 { |
| 259 | err = errors.New("用户id和书籍id均不能为空") |
| 260 | return |
| 261 | } |
| 262 | var ( |
| 263 | rc ReadCount |
| 264 | book = new(Book) |
| 265 | ) |
| 266 | o := orm.NewOrm() |
| 267 | if err = o.QueryTable(tableReadCount).Filter("uid", uid).Filter("book_id", bookId).One(&rc, "cnt"); err == nil { |
| 268 | if err = o.QueryTable(book).Filter("book_id", bookId).One(book, "doc_count", "identify"); err == nil { |
| 269 | rp.Total = book.DocCount |
| 270 | } |
| 271 | } |
| 272 | rp.Cnt = rc.Cnt |
| 273 | rp.BookIdentify = book.Identify |
| 274 | if rp.Total == 0 { |
| 275 | rp.Percent = "0.00%" |
| 276 | } else { |
| 277 | if rp.Cnt > rp.Total { |
| 278 | rp.Cnt = rp.Total |
| 279 | } |
| 280 | f := float32(rp.Cnt) / float32(rp.Total) |
| 281 | rp.Percent = fmt.Sprintf("%.2f", f*100) + "%" |
| 282 | } |
| 283 | return |
| 284 | } |
| 285 | |
| 286 | // 查询阅读进度 |
| 287 | func (this *ReadRecord) BooksProgress(uid int, bookId ...int) (read map[int]int) { |