胡轶钦 пре 6 година
родитељ
комит
029f8cce42
4 измењених фајлова са 112 додато и 63 уклоњено
  1. 18
    3
      controllers/book/book.go
  2. 26
    0
      models/book/book.go
  3. 1
    0
      routers/common.go
  4. 67
    60
      service/book/book.go

+ 18
- 3
controllers/book/book.go Прегледај датотеку

@@ -216,8 +216,14 @@ func (c *BookController) ExcelInpuData() {
216 216
 
217 217
 	for _, sheet := range xlFile.Sheets {
218 218
 		for _, row := range sheet.Rows {
219
-			total, _ := row.Cells[2].Int()
220
-			Days, _ := row.Cells[3].Int()
219
+			total, err := row.Cells[2].Int()
220
+			if err != nil {
221
+				c.ResponseError(err)
222
+			}
223
+			Days, err := row.Cells[3].Int()
224
+			if err != nil {
225
+				c.ResponseError(err)
226
+			}
221 227
 			var book = model.TaBook{
222 228
 				CaseId:      caseId,
223 229
 				BookBarcode: row.Cells[0].String(),
@@ -230,7 +236,7 @@ func (c *BookController) ExcelInpuData() {
230 236
 				IsRecommend: 0,
231 237
 				Price:       "0",
232 238
 			}
233
-			err := c.serv.AuthBook(book)
239
+			err = c.serv.AuthBook(book)
234 240
 			if err != nil {
235 241
 				c.ResponseError(err)
236 242
 			}
@@ -301,3 +307,12 @@ func (c *BookController) GetBookById() {
301 307
 	}
302 308
 	c.ResponseJSON(list)
303 309
 }
310
+
311
+func (c *BookController) GetCustomerBorrowInfo() {
312
+	customerInfo := c.GetString(":customerInfo")
313
+	list, err := c.serv.GetCustomerBorrowInfo(customerInfo)
314
+	if err != nil {
315
+		c.ResponseError(err)
316
+	}
317
+	c.ResponseJSON(list)
318
+}

+ 26
- 0
models/book/book.go Прегледај датотеку

@@ -505,3 +505,29 @@ func (m *BookDAO) IsBarcodeExist(barcode, caseId string) (int, error) {
505 505
 	err := m.db.Sql(sql).Find(&book)
506 506
 	return len(book), err
507 507
 }
508
+
509
+type CustomerInfo struct {
510
+	Name      string
511
+	Phone     string
512
+	BorrowNum int
513
+	LateNum   int
514
+	IsLate    string
515
+}
516
+
517
+func (m *BookDAO) GetCustomerBorrowInfo(customerInfo string) (*CustomerInfo, error) {
518
+	var customer []CustomerInfo
519
+	sql := `SELECT
520
+	a.NAME,
521
+	a.phone ,
522
+	(select count(1) from ta_book_borrow_record c WHERE borrow_status = '1' and c.customer_id = a.customer_id)as borrow_num,
523
+	(select count(1) from ta_book_borrow_record c WHERE borrow_status = '0' and c.customer_id = a.customer_id)as late_num
524
+FROM
525
+	ta_customer a INNER JOIN ta_book_borrow_record b on a.customer_id = b.customer_id 
526
+	where a.phone = '` + customerInfo + `' OR a.barcode = '` + customerInfo + `'
527
+GROUP BY a.phone`
528
+	err := m.db.SQL(sql).Find(&customer)
529
+	if len(customer) <= 0 {
530
+		return nil, err
531
+	}
532
+	return &customer[0], err
533
+}

+ 1
- 0
routers/common.go Прегледај датотеку

@@ -363,6 +363,7 @@ func getCommonRoutes(prefix string) beego.LinkNamespace {
363 363
 		beego.NSRouter("/book/excel", &book.BookController{}, "post:ExcelInpuData"),
364 364
 		beego.NSRouter("/book/cancel/:recordId", &book.BookController{}, "put:CancelReserve"),
365 365
 		beego.NSRouter("/book/:bookId", &book.BookController{}, "delete:DeleteBook"),
366
+		beego.NSRouter("/book/customer/:customerInfo", &book.BookController{}, "get:GetCustomerBorrowInfo"),
366 367
 
367 368
 		// booktype 图书类型管理
368 369
 		beego.NSRouter("/booktype", &booktype.BooktypeController{}, "get:GetList"),

+ 67
- 60
service/book/book.go Прегледај датотеку

@@ -2,7 +2,6 @@ package book
2 2
 
3 3
 import (
4 4
 	"errors"
5
-	"fmt"
6 5
 	"spaceofcheng/services/models"
7 6
 	"spaceofcheng/services/models/book"
8 7
 	"spaceofcheng/services/models/customer"
@@ -416,64 +415,72 @@ func (s *BookServ) DeleteBook(bookId string) error {
416 415
 	return nil
417 416
 }
418 417
 
419
-func (s *BookServ) SendMessageToCustomer() error {
420
-	weekList, err := s.dao.GetAllOneWeekRecord()
421
-	if err != nil {
422
-		utils.LogError("发送消息失败失败: " + err.Error())
423
-		return errors.New("发送消息失败失败")
424
-	}
425
-	lateList, err := s.dao.GetAllLateRecord()
426
-	if err != nil {
427
-		utils.LogError("发送消息失败失败: " + err.Error())
428
-		return errors.New("发送消息失败失败")
429
-	}
430
-	if len(weekList) > 0 {
431
-		for i := 0; i < len(weekList); i++ {
432
-			userMap, err := s.dao.GetUserMappingById(weekList[i].CustomerId)
433
-			if err != nil {
434
-				utils.LogError("发送消息失败失败: " + err.Error())
435
-				return errors.New("发送消息失败失败")
436
-			}
437
-			message := utils.Message{
438
-				To: utils.ClientID{ID: userMap.Openid},
439
-				Data: map[string]interface{}{
440
-					"orgid": weekList[i].OrgId,
441
-					"tplid": "6WoxRkdXrRyF0T7Kc4PU5CjkpzAPWKKsA6wBLAGSQQg",
442
-					"data": map[string]string{
443
-						"first":    "您好,您借阅图书即将逾期,请及时归还。",
444
-						"keyword1": weekList[i].BookName,
445
-						"keyword2": weekList[i].BorrowDate.Format("2006-01-02"),
446
-						"keyword3": weekList[i].EndDate.Format("2006-01-02"),
447
-						"remark":   fmt.Sprintf("避免影响您下次借阅,请及时归还至", weekList[i].CaseName),
448
-					},
449
-				},
450
-			}
451
-			go utils.SendWechat(message)
452
-		}
453
-	}
454
-	if len(lateList) > 0 {
455
-		for i := 0; i < len(lateList); i++ {
456
-			userMap, err := s.dao.GetUserMappingById(lateList[i].CustomerId)
457
-			if err != nil {
458
-				utils.LogError("发送消息失败失败: " + err.Error())
459
-				return errors.New("发送消息失败失败")
460
-			}
461
-			message := utils.Message{
462
-				To: utils.ClientID{ID: userMap.Openid},
463
-				Data: map[string]interface{}{
464
-					"orgid": lateList[i].OrgId,
465
-					"tplid": "ID:Be0a25NMb3fzLtNaaQn_YOuECQDnlCs1es5aVvfwRhs",
466
-					"data": map[string]string{
467
-						"first":    "您好,您借阅图书的时间已经逾期2天",
468
-						"keyword1": lateList[i].BookName,
469
-						"keyword2": weekList[i].BorrowDate.Format("2006-01-02"),
470
-						"keyword3": weekList[i].EndDate.Format("2006-01-02"),
471
-						"remark":   fmt.Sprintf("避免影响您下次借阅,请及时归还至", lateList[i].CaseName),
472
-					},
473
-				},
474
-			}
475
-			go utils.SendWechat(message)
476
-		}
418
+// func (s *BookServ) SendMessageToCustomer() error {
419
+// 	weekList, err := s.dao.GetAllOneWeekRecord()
420
+// 	if err != nil {
421
+// 		utils.LogError("发送消息失败失败: " + err.Error())
422
+// 		return errors.New("发送消息失败失败")
423
+// 	}
424
+// 	lateList, err := s.dao.GetAllLateRecord()
425
+// 	if err != nil {
426
+// 		utils.LogError("发送消息失败失败: " + err.Error())
427
+// 		return errors.New("发送消息失败失败")
428
+// 	}
429
+// 	if len(weekList) > 0 {
430
+// 		for i := 0; i < len(weekList); i++ {
431
+// 			userMap, err := s.dao.GetUserMappingById(weekList[i].CustomerId)
432
+// 			if err != nil {
433
+// 				utils.LogError("发送消息失败失败: " + err.Error())
434
+// 				return errors.New("发送消息失败失败")
435
+// 			}
436
+// 			message := utils.Message{
437
+// 				To: utils.ClientID{ID: userMap.Openid},
438
+// 				Data: map[string]interface{}{
439
+// 					"orgid": weekList[i].OrgId,
440
+// 					"tplid": "6WoxRkdXrRyF0T7Kc4PU5CjkpzAPWKKsA6wBLAGSQQg",
441
+// 					"data": map[string]string{
442
+// 						"first":    "您好,您借阅图书即将逾期,请及时归还。",
443
+// 						"keyword1": weekList[i].BookName,
444
+// 						"keyword2": weekList[i].BorrowDate.Format("2006-01-02"),
445
+// 						"keyword3": weekList[i].EndDate.Format("2006-01-02"),
446
+// 						"remark":   fmt.Sprintf("避免影响您下次借阅,请及时归还至", weekList[i].CaseName),
447
+// 					},
448
+// 				},
449
+// 			}
450
+// 			go utils.SendWechat(message)
451
+// 		}
452
+// 	}
453
+// 	if len(lateList) > 0 {
454
+// 		for i := 0; i < len(lateList); i++ {
455
+// 			userMap, err := s.dao.GetUserMappingById(lateList[i].CustomerId)
456
+// 			if err != nil {
457
+// 				utils.LogError("发送消息失败失败: " + err.Error())
458
+// 				return errors.New("发送消息失败失败")
459
+// 			}
460
+// 			message := utils.Message{
461
+// 				To: utils.ClientID{ID: userMap.Openid},
462
+// 				Data: map[string]interface{}{
463
+// 					"orgid": lateList[i].OrgId,
464
+// 					"tplid": "ID:Be0a25NMb3fzLtNaaQn_YOuECQDnlCs1es5aVvfwRhs",
465
+// 					"data": map[string]string{
466
+// 						"first":    "您好,您借阅图书的时间已经逾期2天",
467
+// 						"keyword1": lateList[i].BookName,
468
+// 						"keyword2": weekList[i].BorrowDate.Format("2006-01-02"),
469
+// 						"keyword3": weekList[i].EndDate.Format("2006-01-02"),
470
+// 						"remark":   fmt.Sprintf("避免影响您下次借阅,请及时归还至", lateList[i].CaseName),
471
+// 					},
472
+// 				},
473
+// 			}
474
+// 			go utils.SendWechat(message)
475
+// 		}
476
+// 	}
477
+// 	return nil
478
+// }
479
+func (s *BookServ) GetCustomerBorrowInfo(customerInfo string) (*book.CustomerInfo, error) {
480
+	customer, err := s.dao.GetCustomerBorrowInfo(customerInfo)
481
+	if err != nil {
482
+		utils.LogError("获取用户信息失败: " + err.Error())
483
+		return nil, errors.New("获取用户信息失败")
477 484
 	}
478
-	return nil
485
+	return customer, nil
479 486
 }