|
@@ -207,15 +207,48 @@ func (m *BookDAO) AddChangeRecord(change model.TaInStockChange) error {
|
207
|
207
|
}
|
208
|
208
|
|
209
|
209
|
// GetMineRecord 获取个人借阅记录
|
210
|
|
-func (m *BookDAO) GetMineRecord(customerid string, page, pagesize int) ([]model.TaBookBorrowRecord, error) {
|
|
210
|
+func (m *BookDAO) GetMineRecord(customerid, status string, page, pagesize int) ([]model.TaBookBorrowRecord, error) {
|
211
|
211
|
var records []model.TaBookBorrowRecord
|
212
|
|
- err := m.db.Where("customer_id=?", customerid).Limit(pagesize, pagesize*(page-1)).Find(&records)
|
|
212
|
+ var db = m.db.Where("customer_id=?", customerid)
|
|
213
|
+ if status != "" {
|
|
214
|
+ db.And("borrow_status=?", status)
|
|
215
|
+ }
|
|
216
|
+ err := db.Limit(pagesize, pagesize*(page-1)).Find(&records)
|
213
|
217
|
return records, err
|
214
|
218
|
}
|
215
|
219
|
|
216
|
220
|
// GetMineRecordCount 获取个人借阅记录count
|
217
|
|
-func (m *BookDAO) GetMineRecordCount(customerid string) (int, error) {
|
|
221
|
+func (m *BookDAO) GetMineRecordCount(customerid, status string) (int, error) {
|
218
|
222
|
var records []model.TaBookBorrowRecord
|
219
|
|
- err := m.db.Where("customer_id=?", customerid).Find(&records)
|
|
223
|
+ var db = m.db.Where("customer_id=?", customerid)
|
|
224
|
+ if status != "" {
|
|
225
|
+ db.And("borrow_status=?", status)
|
|
226
|
+ }
|
|
227
|
+ err := db.Find(&records)
|
220
|
228
|
return len(records), err
|
221
|
229
|
}
|
|
230
|
+
|
|
231
|
+// ReserveBook 图书预约
|
|
232
|
+func (m *BookDAO) ReserveBook(record model.TaBookBorrowRecord) (model.TaBookBorrowRecord, error) {
|
|
233
|
+ record.BookBorrowRecordId = utils.GetGUID()
|
|
234
|
+ record.CreateDate = time.Now()
|
|
235
|
+ record.ReserveDate = time.Now()
|
|
236
|
+ dd, _ := time.ParseDuration("168h")
|
|
237
|
+ record.ReserveEndDate = time.Now().Add(dd)
|
|
238
|
+ record.BorrowStatus = models.BORROW_TYPE_RESERVE
|
|
239
|
+ _, err := m.db.Insert(record)
|
|
240
|
+
|
|
241
|
+ return record, err
|
|
242
|
+}
|
|
243
|
+
|
|
244
|
+// CheckUserReserveBook 判断用户书籍预约状态
|
|
245
|
+func (m *BookDAO) CheckUserReserveBook(customerid, bookid string) (bool, error) {
|
|
246
|
+ var records []model.TaBookBorrowRecord
|
|
247
|
+ err := m.db.Where("customer_id=?", customerid).And("book_id=?", bookid).And("status in ('" + models.BORROW_TYPE_RESERVE + "','" + models.BORROW_TYPE_BORROWED + "','" + models.BORROW_TYPE_LATE + "')").Find(&records)
|
|
248
|
+ if err != nil {
|
|
249
|
+ return false, err
|
|
250
|
+ }
|
|
251
|
+ return len(records) == 0, nil
|
|
252
|
+}
|
|
253
|
+
|
|
254
|
+//
|