wangfei 6 år sedan
förälder
incheckning
5918273a1c
4 ändrade filer med 41 tillägg och 6 borttagningar
  1. 4
    1
      controllers/course/course.go
  2. 12
    2
      models/course/course.go
  3. 5
    0
      models/goods/orders.go
  4. 20
    3
      service/course/course.go

+ 4
- 1
controllers/course/course.go Visa fil

@@ -216,7 +216,10 @@ func (c *CourseController) GetCourseByLocation() {
216 216
 
217 217
 // GetCustomerCourse 获取用户课程信息
218 218
 func (c *CourseController) GetCustomerCourse() {
219
-	courses, err := c.serv.GetCustomerCourse()
219
+	page, _ := c.GetInt("page")
220
+	pageSize, _ := c.GetInt("pagesize")
221
+
222
+	courses, err := c.serv.GetCustomerCourse(page, pageSize)
220 223
 	if err != nil {
221 224
 		c.ResponseError(err)
222 225
 	}

+ 12
- 2
models/course/course.go Visa fil

@@ -456,10 +456,10 @@ type CustomerCourse struct {
456 456
 }
457 457
 
458 458
 // GetCustomerCourse 获取我的课程信息
459
-func (m *CourseDAO) GetCustomerCourse(custID string) ([]CustomerCourse, error) {
459
+func (m *CourseDAO) GetCustomerCourse(custID string, page, pageSize int) ([]CustomerCourse, error) {
460 460
 	var courses []CustomerCourse
461 461
 	sql := `select * from ta_customer_course where status>` + strconv.Itoa(models.STATUS_DEL) + ` and customer_id='` + custID + `'`
462
-
462
+	sql += ` order by create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
463 463
 	err := m.db.Sql(sql).Find(&courses)
464 464
 	if err != nil {
465 465
 		return nil, err
@@ -474,6 +474,16 @@ func (m *CourseDAO) GetCustomerCourse(custID string) ([]CustomerCourse, error) {
474 474
 	return courses, nil
475 475
 }
476 476
 
477
+// GetCustomerCourseCount 获取我的课程总数
478
+func (m *CourseDAO) GetCustomerCourseCount(custID string) (int, error) {
479
+	var courses []model.TaCustomerCourse
480
+	err := m.db.Where("status>"+strconv.Itoa(models.STATUS_DEL)).And("customer_id=?", custID).Find(&courses)
481
+	if err != nil {
482
+		return 0, err
483
+	}
484
+	return len(courses), nil
485
+}
486
+
477 487
 // GetCustomerCourseDetail 获取我的课程明细
478 488
 func (m *CourseDAO) GetCustomerCourseDetail(customerCourseID string) ([]model.TaCustomerCourseDetail, error) {
479 489
 	var details []model.TaCustomerCourseDetail

+ 5
- 0
models/goods/orders.go Visa fil

@@ -203,3 +203,8 @@ func (m *GoodsDAO) GetOrdersByRecord(recordid string) ([]OrdersWithGoods, error)
203 203
 	}
204 204
 	return orderList, nil
205 205
 }
206
+
207
+// GetCustomerOrders 获取用户订单
208
+// func (m *GoodsDAO) GetCustomerOrders(custID string) ([]OrdersWithGoods, error) {
209
+
210
+// }

+ 20
- 3
service/course/course.go Visa fil

@@ -500,14 +500,31 @@ func (s *CourseServ) GetCourseByLocation(orgid, locationid string) ([]course.Cou
500 500
 }
501 501
 
502 502
 // GetCustomerCourse 获取用户的课程信息
503
-func (s *CourseServ) GetCustomerCourse() ([]course.CustomerCourse, error) {
503
+func (s *CourseServ) GetCustomerCourse(page, pageSize int) (map[string]interface{}, error) {
504
+	if pageSize == 0 {
505
+		pageSize = service.PAGENUM
506
+	}
507
+	if page == 0 {
508
+		page = 1
509
+	}
504 510
 	cust := s.ctx.Get("customer").(model.TaCustomer)
505
-	courses, err := s.dao.GetCustomerCourse(cust.CustomerId)
511
+	list, err := s.dao.GetCustomerCourse(cust.CustomerId, page, pageSize)
506 512
 	if err != nil {
507 513
 		utils.LogError("获取课程信息失败: " + err.Error())
508 514
 		return nil, errors.New("获取课程信息失败")
509 515
 	}
510
-	return courses, nil
516
+	total, err := s.dao.GetCustomerCourseCount(cust.CustomerId)
517
+	if err != nil {
518
+		utils.LogError("获取课程信息失败: " + err.Error())
519
+		return nil, errors.New("获取课程信息失败")
520
+	}
521
+
522
+	return map[string]interface{}{
523
+		"list":     list,
524
+		"pagesize": pageSize,
525
+		"pagenum":  total,
526
+		"page":     page,
527
+	}, nil
511 528
 }
512 529
 
513 530
 // GetCustomerCourseByID 获取我的课程明细