wangfei 6 years ago
parent
commit
91dd7466f1
1 changed files with 24 additions and 6 deletions
  1. 24
    6
      models/book/book.go

+ 24
- 6
models/book/book.go View File

@@ -216,14 +216,32 @@ func (m *BookDAO) AddChangeRecord(change model.TaInStockChange) error {
216 216
 	return err
217 217
 }
218 218
 
219
+// BookBorrowRecord 图书借阅记录
220
+type BookBorrowRecord struct {
221
+	model.TaBookBorrowRecord `xorm:"extends"`
222
+	BookName                 string
223
+	BookImg                  string
224
+	CaseName                 string
225
+}
226
+
219 227
 // GetMineRecord 获取个人借阅记录
220
-func (m *BookDAO) GetMineRecord(customerid, status string, page, pagesize int) ([]model.TaBookBorrowRecord, error) {
221
-	var records []model.TaBookBorrowRecord
222
-	var db = m.db.Where("customer_id=?", customerid)
228
+func (m *BookDAO) GetMineRecord(customerid, status string, page, pagesize int) ([]BookBorrowRecord, error) {
229
+	var records []BookBorrowRecord
230
+	sql := `select a.*,b.book_name,b.book_img,c.case_name from ta_book_borrow_record a 
231
+	inner join sys_case c on a.case_id=c.case_id 
232
+	left join ta_book b on a.book_id=b.book_id 
233
+	where a.customer_id=? `
223 234
 	if status != "" {
224
-		db.And("borrow_status=?", status)
235
+		sql += ` and a.borrow_status in ('` + strings.Replace(status, ",", "','", -1) + `')`
236
+	}
237
+	sql += ` order by a.borrow_status asc`
238
+	if status == "4" {
239
+		sql += `,a.reserve_date asc`
240
+	} else {
241
+		sql += `,a.end_date asc`
225 242
 	}
226
-	err := db.Limit(pagesize, pagesize*(page-1)).Find(&records)
243
+	sql += ` limit ` + strconv.Itoa((page-1)*pagesize) + `, ` + strconv.Itoa(pagesize)
244
+	err := m.db.Sql(sql, customerid).Find(&records)
227 245
 	return records, err
228 246
 }
229 247
 
@@ -232,7 +250,7 @@ func (m *BookDAO) GetMineRecordCount(customerid, status string) (int, error) {
232 250
 	var records []model.TaBookBorrowRecord
233 251
 	var db = m.db.Where("customer_id=?", customerid)
234 252
 	if status != "" {
235
-		db.And("borrow_status=?", status)
253
+		db.And("borrow_status in ('" + strings.Replace(status, ",", "','", -1) + "')")
236 254
 	}
237 255
 	err := db.Find(&records)
238 256
 	return len(records), err