wangfei 6 years ago
parent
commit
c213e17651
5 changed files with 46 additions and 12 deletions
  1. 2
    1
      controllers/book/book.go
  2. 37
    4
      models/book/book.go
  3. 3
    3
      models/constant.go
  4. 3
    3
      service/book/book.go
  5. 1
    1
      service/sys.go

+ 2
- 1
controllers/book/book.go View File

@@ -63,7 +63,8 @@ func (c *BookController) GetBookList() {
63 63
 func (c *BookController) GetMineRecord() {
64 64
 	page, _ := c.GetInt("page")
65 65
 	pagesize, _ := c.GetInt("pagesize")
66
-	list, err := c.serv.GetMineRecord(page, pagesize)
66
+	status := c.GetString("status")
67
+	list, err := c.serv.GetMineRecord(status, page, pagesize)
67 68
 	if err != nil {
68 69
 		c.ResponseError(err)
69 70
 	}

+ 37
- 4
models/book/book.go View File

@@ -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
+//

+ 3
- 3
models/constant.go View File

@@ -258,9 +258,9 @@ const (
258 258
 	BORROW_TYPE_RESERVE  = "reserve"
259 259
 	BORROW_TYPE_BORROWED = "borrowed"
260 260
 	BORROW_TYPE_RETURN   = "return"
261
-	BORROW_TYPE_EXPIRE   = "expire"
262
-	BORROW_TYPE_LATE     = "late"
263
-	BORROW_TYPE_CANCEL   = "cancel"
261
+	BORROW_TYPE_EXPIRE   = "expire" // 过期
262
+	BORROW_TYPE_LATE     = "late"   // 延期
263
+	BORROW_TYPE_CANCEL   = "cancel" // 取消
264 264
 )
265 265
 
266 266
 // 是否推荐

+ 3
- 3
service/book/book.go View File

@@ -89,17 +89,17 @@ func (s *BookServ) EditBook(book model.TaBook) error {
89 89
 }
90 90
 
91 91
 // GetMineRecord 获取个人借阅记录
92
-func (s *BookServ) GetMineRecord(page, pageSize int) (map[string]interface{}, error) {
92
+func (s *BookServ) GetMineRecord(status string, page, pageSize int) (map[string]interface{}, error) {
93 93
 	if pageSize == 0 {
94 94
 		pageSize = service.PAGENUM
95 95
 	}
96 96
 	customer := s.ctx.Get("customer").(model.TaCustomer)
97
-	list, err := s.dao.GetMineRecord(customer.CustomerId, page, pageSize)
97
+	list, err := s.dao.GetMineRecord(customer.CustomerId, status, page, pageSize)
98 98
 	if err != nil {
99 99
 		utils.LogError("获取图书列表失败: " + err.Error())
100 100
 		return nil, errors.New("获取图书列表失败")
101 101
 	}
102
-	total, err := s.dao.GetMineRecordCount(customer.CustomerId)
102
+	total, err := s.dao.GetMineRecordCount(customer.CustomerId, status)
103 103
 	if err != nil {
104 104
 		utils.LogError("获取图书列表失败: " + err.Error())
105 105
 		return nil, errors.New("获取图书列表失败")

+ 1
- 1
service/sys.go View File

@@ -165,7 +165,7 @@ func (s *SysServ) authWechat(gctx *context.Context) map[string]interface{} {
165 165
 	var openID string
166 166
 
167 167
 	if beego.BConfig.RunMode == "dev" {
168
-		openID = "oMOpz0hVnuuxCwpViqMN6Vwx3Ewo11"
168
+		openID = "ouHcHt8oyP4jofR5cV2CZYXYgqkQ"
169 169
 	} else {
170 170
 		// 初始化微信配置
171 171
 		if err := s.initWechatClient(s.org.OrgId); err != nil {