wangfei 6 years ago
parent
commit
9879703b13

+ 28
- 0
controllers/course/course.go View File

185
 	}
185
 	}
186
 	c.ResponseJSON("删除成功!")
186
 	c.ResponseJSON("删除成功!")
187
 }
187
 }
188
+
189
+// GetSelectCourseList 获取精选课程
190
+// func (c *CourseController) GetSelectCourseList() {
191
+// 	orgid := c.GetString("orgid")
192
+// 	courses, err := c.dao.GetSelectCourseList(orgid)
193
+// 	if err != nil {
194
+// 		c.ResponseError(err)
195
+// 	}
196
+// 	c.ResponseJSON(courses)
197
+// }
198
+
199
+// GetCourseByLocation 根据位置获取课程信息
200
+func (c *CourseController) GetCourseByLocation() {
201
+	locationid := c.GetString("locationid")
202
+	orgid := c.GetString("orgid")
203
+	if locationid == "selected" {
204
+		courses, err := c.dao.GetSelectCourseList(orgid)
205
+		if err != nil {
206
+			c.ResponseError(err)
207
+		}
208
+		c.ResponseJSON(courses)
209
+	}
210
+	courses, err := c.dao.GetCourseByLocation(orgid, locationid)
211
+	if err != nil {
212
+		c.ResponseError(err)
213
+	}
214
+	c.ResponseJSON(courses)
215
+}

+ 1
- 1
controllers/message/image.go View File

18
 
18
 
19
 // GetImgByLocation 根据位置获取轮播图信息
19
 // GetImgByLocation 根据位置获取轮播图信息
20
 func (c *MessageController) GetImgByLocation() {
20
 func (c *MessageController) GetImgByLocation() {
21
-	loctionid := c.GetString("loctionid")
21
+	loctionid := c.GetString("locationid")
22
 	orgid := c.GetString("orgid")
22
 	orgid := c.GetString("orgid")
23
 	imgs, err := c.dao.GetImgByLocation(loctionid, orgid)
23
 	imgs, err := c.dao.GetImgByLocation(loctionid, orgid)
24
 	if err != nil {
24
 	if err != nil {

+ 6
- 2
controllers/message/location.go View File

5
 // GetLocations 获取位置列表
5
 // GetLocations 获取位置列表
6
 func (c *MessageController) GetLocations() {
6
 func (c *MessageController) GetLocations() {
7
 	issys := c.GetString("issys")
7
 	issys := c.GetString("issys")
8
-	org := c.Context.Get("org").(model.SysOrg)
9
-	location, err := c.dao.GetLocationList(issys, org.OrgId)
8
+	orgid := c.GetString("orgid")
9
+	if orgid == "" {
10
+		org := c.Context.Get("org").(model.SysOrg)
11
+		orgid = org.OrgId
12
+	}
13
+	location, err := c.dao.GetLocationList(issys, orgid)
10
 	if err != nil {
14
 	if err != nil {
11
 		c.ResponseError(err)
15
 		c.ResponseError(err)
12
 	}
16
 	}

+ 48
- 0
models/course/course.go View File

27
 
27
 
28
 const (
28
 const (
29
 	STATUS_UNPUBLISH = 0
29
 	STATUS_UNPUBLISH = 0
30
+	IS_SELECT        = 1
30
 )
31
 )
31
 
32
 
32
 // CourseInfo 课程
33
 // CourseInfo 课程
196
 	CourseTags     []model.TaCourseTag
197
 	CourseTags     []model.TaCourseTag
197
 	CourseImgs     []model.TaCourseImg
198
 	CourseImgs     []model.TaCourseImg
198
 	CourseDetail   []model.TaCourseDetail
199
 	CourseDetail   []model.TaCourseDetail
200
+	CaseInfo       *model.SysCase
199
 }
201
 }
200
 
202
 
201
 // GetCourseInfo 获取课程详情
203
 // GetCourseInfo 获取课程详情
326
 	_, err := m.db.Exec(sql)
328
 	_, err := m.db.Exec(sql)
327
 	return err
329
 	return err
328
 }
330
 }
331
+
332
+// GetCourseDetailCount 获取已排课数量
333
+func (m *CourseDAO) GetCourseDetailCount(courseid string) (int, error) {
334
+	var details []model.TaCourseDetail
335
+	err := m.db.Where("course_id=?", courseid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Find(&details)
336
+	if err != nil {
337
+		return 0, err
338
+	}
339
+	return len(details), nil
340
+}
341
+
342
+// UpdateCourseScheduleNum 更新课程已排课数量
343
+func (m *CourseDAO) UpdateCourseScheduleNum(courseid string, num int) error {
344
+	var info = model.TaCourse{
345
+		CourseId:    courseid,
346
+		ScheduleNum: num,
347
+	}
348
+	var cols = []string{
349
+		"schedule_num",
350
+	}
351
+	_, err := m.db.Cols(cols...).Where("course_id=?", courseid).Update(info)
352
+	return err
353
+}
354
+
355
+// DeleteScheduleByCourse 删除排课记录
356
+func (m *CourseDAO) DeleteScheduleByCourse(courseid string) error {
357
+	sql := `update ta_course_detail set status=` + strconv.Itoa(models.STATUS_DEL) + ` where course_id='` + courseid + `'`
358
+	_, err := m.db.Exec(sql)
359
+	return err
360
+}
361
+
362
+// GetSelectCourseList 获取精选课程
363
+func (m *CourseDAO) GetSelectCourseList(orgid string) ([]CourseDetail, error) {
364
+	var courses []CourseDetail
365
+	sql := `select * from ta_course where is_select=` + strconv.Itoa(IS_SELECT) + ` and status=` + strconv.Itoa(models.STATUS_NORMAL) + ` and org_id='` + orgid + `'`
366
+	err := m.db.Sql(sql).Find(&courses)
367
+	return courses, err
368
+}
369
+
370
+// GetCourseByLocation 根据位置获取课程信息
371
+func (m *CourseDAO) GetCourseByLocation(orgid, locationid string) ([]CourseDetail, error) {
372
+	var courses []CourseDetail
373
+	sql := `select * from ta_course where status=` + strconv.Itoa(models.STATUS_NORMAL) + ` and org_id='` + orgid + `' and location_id ='` + locationid + `'`
374
+	err := m.db.Sql(sql).Find(&courses)
375
+	return courses, err
376
+}

+ 36
- 0
models/course/order.go View File

1
+package course
2
+
3
+import (
4
+	"spaceofcheng/services/models/model"
5
+	"spaceofcheng/services/utils"
6
+	"strings"
7
+	"time"
8
+)
9
+
10
+// SaveCourseOrder 保存订单
11
+func (m *CourseDAO) SaveCourseOrder(order model.TaCourseOrders) (*model.TaCourseOrders, error) {
12
+	order.OrdersId = utils.GetGUID()
13
+	// 当前订单号的随机方式 = 时间 + 个人ID
14
+	order.OrdersNo = "Customer-" + time.Now().Local().Format("20060102150405") + "-" + strings.Join(utils.GUIID2IntString(order.CustomerId), "")
15
+	order.CreateDate = time.Now()
16
+	_, err := m.db.Insert(&order)
17
+	return &order, err
18
+}
19
+
20
+// GetOrderByID 根据id获取订单明细
21
+func (m *CourseDAO) GetOrderByID(ordersid string) (*model.TaCourseOrders, error) {
22
+	var orders []model.TaCourseOrders
23
+	err := m.db.Where("orders_id=?", ordersid).Find(&orders)
24
+	if err != nil {
25
+		return nil, err
26
+	}
27
+	if len(orders) > 0 {
28
+		return &orders[0], nil
29
+	}
30
+	return nil, nil
31
+}
32
+
33
+// SaveCourseOrderDetail 保存订单明细
34
+func (m *CourseDAO) SaveCourseOrderDetail() {
35
+
36
+}

+ 5
- 4
models/message/cmscase.go View File

35
 }
35
 }
36
 
36
 
37
 // GetCmsCaseByOrg 获取列表
37
 // GetCmsCaseByOrg 获取列表
38
-func (m *MessageDAO) GetCmsCaseByOrg(orgid string) ([]model.TaCmsCase, error) {
39
-	var cases []model.TaCmsCase
40
-	err := m.db.Where("org_id=?", orgid).Find(&cases)
41
-	beego.Error(cases)
38
+func (m *MessageDAO) GetCmsCaseByOrg(orgid string) ([]CmsCase, error) {
39
+	var cases []CmsCase
40
+	sql := `select * from ta_cms_case where org_id='` + orgid + `' and status=` + strconv.Itoa(models.STATUS_NORMAL)
41
+	err := m.db.Sql(sql).Find(&cases)
42
+	// err := m.db.Where("org_id=?", orgid).Find(&cases)
42
 	return cases, err
43
 	return cases, err
43
 }
44
 }
44
 
45
 

+ 1
- 1
models/message/image.go View File

26
 }
26
 }
27
 
27
 
28
 // GetImgByLocation 根据位置获取轮播图信息
28
 // GetImgByLocation 根据位置获取轮播图信息
29
-func (m *MessageDAO) GetImgByLocation(orgid, locationid string) ([]model.TaCmsImages, error) {
29
+func (m *MessageDAO) GetImgByLocation(locationid, orgid string) ([]model.TaCmsImages, error) {
30
 	var imgs []model.TaCmsImages
30
 	var imgs []model.TaCmsImages
31
 	err := m.db.Where("status>"+strconv.Itoa(models.STATUS_DEL)).And("org_id=?", orgid).And("location_id=?", locationid).Asc("sort").Find(&imgs)
31
 	err := m.db.Where("status>"+strconv.Itoa(models.STATUS_DEL)).And("org_id=?", orgid).And("location_id=?", locationid).Asc("sort").Find(&imgs)
32
 	return imgs, err
32
 	return imgs, err

+ 0
- 2
models/model/ta_course_orders.go View File

12
 	CaseId       string    `xorm:"VARCHAR(64)"`
12
 	CaseId       string    `xorm:"VARCHAR(64)"`
13
 	CourseId     string    `xorm:"VARCHAR(64)"`
13
 	CourseId     string    `xorm:"VARCHAR(64)"`
14
 	CourseName   string    `xorm:"VARCHAR(50)"`
14
 	CourseName   string    `xorm:"VARCHAR(50)"`
15
-	LocationId   string    `xorm:"VARCHAR(64)"`
16
-	LocationName string    `xorm:"VARCHAR(50)"`
17
 	Price        string    `xorm:"DECIMAL(8,2)"`
15
 	Price        string    `xorm:"DECIMAL(8,2)"`
18
 	CourseNum    int       `xorm:"INT(11)"`
16
 	CourseNum    int       `xorm:"INT(11)"`
19
 	JoinNum      int       `xorm:"INT(11)"`
17
 	JoinNum      int       `xorm:"INT(11)"`

+ 14
- 0
models/model/ta_course_orders_detail.go View File

1
+package model
2
+
3
+import (
4
+	"time"
5
+)
6
+
7
+type TaCourseOrdersDetail struct {
8
+	OrdersDetailId string    `xorm:"not null pk VARCHAR(64)"`
9
+	OrdersId       string    `xorm:"not null VARCHAR(64)"`
10
+	CourseId       string    `xorm:"VARCHAR(64)"`
11
+	CourseDetailId string    `xorm:"VARCHAR(64)"`
12
+	BeginDate      time.Time `xorm:"DATETIME"`
13
+	EndDate        time.Time `xorm:"DATETIME"`
14
+}

+ 4
- 0
routers/guest.go View File

3
 import (
3
 import (
4
 	"spaceofcheng/services/controllers"
4
 	"spaceofcheng/services/controllers"
5
 	"spaceofcheng/services/controllers/cases"
5
 	"spaceofcheng/services/controllers/cases"
6
+	"spaceofcheng/services/controllers/course"
6
 	"spaceofcheng/services/controllers/customer"
7
 	"spaceofcheng/services/controllers/customer"
7
 	"spaceofcheng/services/controllers/message"
8
 	"spaceofcheng/services/controllers/message"
8
 	"spaceofcheng/services/controllers/user"
9
 	"spaceofcheng/services/controllers/user"
18
 		beego.NSRouter("/cms/info", &message.MessageController{}, "get:GetCmsInfoByLocation"),
19
 		beego.NSRouter("/cms/info", &message.MessageController{}, "get:GetCmsInfoByLocation"),
19
 		beego.NSRouter("/cms/img", &message.MessageController{}, "get:GetImgByLocation"),
20
 		beego.NSRouter("/cms/img", &message.MessageController{}, "get:GetImgByLocation"),
20
 		beego.NSRouter("/cms/news", &message.MessageController{}, "get:GetNewsByLocation"),
21
 		beego.NSRouter("/cms/news", &message.MessageController{}, "get:GetNewsByLocation"),
22
+		beego.NSRouter("/cms/case", &message.MessageController{}, "get:GetCmsCaseList"),
23
+		beego.NSRouter("/cms/location", &message.MessageController{}, "get:GetLocations"),
24
+		beego.NSRouter("/cms/course", &course.CourseController{}, "get:GetCourseByLocation"),
21
 
25
 
22
 		// 案场
26
 		// 案场
23
 		beego.NSRouter("/case", &cases.CaseController{}, "get:GetOrgCases"),
27
 		beego.NSRouter("/case", &cases.CaseController{}, "get:GetOrgCases"),

+ 101
- 11
service/course/course.go View File

2
 
2
 
3
 import (
3
 import (
4
 	"spaceofcheng/services/models"
4
 	"spaceofcheng/services/models"
5
+	"spaceofcheng/services/models/cases"
5
 	"spaceofcheng/services/models/course"
6
 	"spaceofcheng/services/models/course"
6
 	"spaceofcheng/services/models/model"
7
 	"spaceofcheng/services/models/model"
7
 	"spaceofcheng/services/service"
8
 	"spaceofcheng/services/service"
13
 
14
 
14
 // CourseServ 系统处理
15
 // CourseServ 系统处理
15
 type CourseServ struct {
16
 type CourseServ struct {
16
-	ctx *utils.Context
17
-	dao *course.CourseDAO
17
+	ctx     *utils.Context
18
+	dao     *course.CourseDAO
19
+	casedao *cases.CaseDAO
18
 }
20
 }
19
 
21
 
20
 // NewCourseServ 初始化
22
 // NewCourseServ 初始化
21
 func NewCourseServ(ctx *utils.Context) *CourseServ {
23
 func NewCourseServ(ctx *utils.Context) *CourseServ {
22
 	return &CourseServ{
24
 	return &CourseServ{
23
-		ctx: ctx,
24
-		dao: course.NewCourseDAO(ctx),
25
+		ctx:     ctx,
26
+		dao:     course.NewCourseDAO(ctx),
27
+		casedao: cases.NewCaseDAO(ctx),
25
 	}
28
 	}
26
 }
29
 }
27
 
30
 
83
 		return nil, err
86
 		return nil, err
84
 	}
87
 	}
85
 	info.CourseImgs = imgs
88
 	info.CourseImgs = imgs
89
+	caseinfo, err := s.casedao.GetCaseByID(info.CaseId)
90
+	if err != nil {
91
+		return nil, err
92
+	}
93
+	info.CaseInfo = caseinfo
86
 	return info, nil
94
 	return info, nil
87
 }
95
 }
88
 
96
 
180
 	if courseid == "" {
188
 	if courseid == "" {
181
 		return utils.LogError("没有对应的课程!")
189
 		return utils.LogError("没有对应的课程!")
182
 	}
190
 	}
183
-	err := s.dao.DelCourse(courseid)
191
+	courseinfo, err := s.dao.GetCourseByID(courseid)
192
+	if err != nil {
193
+		return err
194
+	}
195
+	if courseinfo.Status != course.STATUS_UNPUBLISH {
196
+		return utils.LogError("课程状态异常!不允许删除!")
197
+	}
198
+	err = s.dao.DelCourse(courseid)
199
+	if err != nil {
200
+		return err
201
+	}
202
+	err = s.dao.DeleteScheduleByCourse(courseid)
184
 	return err
203
 	return err
185
 }
204
 }
186
 
205
 
316
 	if detail.BeginDate.After(detail.EndDate) {
335
 	if detail.BeginDate.After(detail.EndDate) {
317
 		return nil, utils.LogError("课程截止时间必须大于开始时间!")
336
 		return nil, utils.LogError("课程截止时间必须大于开始时间!")
318
 	}
337
 	}
338
+	courseinfo, err := s.dao.GetCourseByID(detail.CourseId)
339
+	if err != nil {
340
+		return nil, err
341
+	}
342
+	if courseinfo.Status != course.STATUS_UNPUBLISH {
343
+		return nil, utils.LogError("课程状态异常!不允许排课!请刷新后重试!")
344
+	}
319
 	if detail.DetailId == "" {
345
 	if detail.DetailId == "" {
320
-		course, err := s.dao.GetCourseByID(detail.CourseId)
346
+		detail.OrgId = courseinfo.OrgId
347
+		detail.CaseId = courseinfo.CaseId
348
+		newinfo, err = s.dao.AddCourseDetail(detail)
321
 		if err != nil {
349
 		if err != nil {
322
 			return nil, err
350
 			return nil, err
323
 		}
351
 		}
324
-		detail.OrgId = course.OrgId
325
-		detail.CaseId = course.CaseId
326
-		newinfo, err = s.dao.AddCourseDetail(detail)
352
+		num, err := s.dao.GetCourseDetailCount(courseinfo.CourseId)
353
+		if err != nil {
354
+			return nil, err
355
+		}
356
+		err = s.dao.UpdateCourseScheduleNum(courseinfo.CourseId, num)
327
 		if err != nil {
357
 		if err != nil {
328
 			return nil, err
358
 			return nil, err
329
 		}
359
 		}
342
 	if detailid == "" {
372
 	if detailid == "" {
343
 		return utils.LogError("没有对应的排课信息!")
373
 		return utils.LogError("没有对应的排课信息!")
344
 	}
374
 	}
345
-	err := s.dao.DelCourseDetail(detailid)
346
-	return err
375
+	detail, err := s.dao.GetDetailByID(detailid)
376
+	if err != nil {
377
+		return err
378
+	}
379
+	courseinfo, err := s.dao.GetCourseByID(detail.CourseId)
380
+	if err != nil {
381
+		return err
382
+	}
383
+	if courseinfo.Status != course.STATUS_UNPUBLISH {
384
+		return utils.LogError("课程状态异常!不允许删除!")
385
+	}
386
+	err = s.dao.DelCourseDetail(detailid)
387
+	if err != nil {
388
+		return err
389
+	}
390
+	num, err := s.dao.GetCourseDetailCount(courseinfo.CourseId)
391
+	if err != nil {
392
+		return err
393
+	}
394
+	err = s.dao.UpdateCourseScheduleNum(courseinfo.CourseId, num)
395
+	if err != nil {
396
+		return err
397
+	}
398
+	return nil
399
+}
400
+
401
+// GetCourseBySelect 获取精选课程
402
+func (s *CourseServ) GetSelectCourseList(orgid string) ([]course.CourseDetail, error) {
403
+	if orgid == "" {
404
+		return nil, utils.LogError("参数错误!")
405
+	}
406
+	list, err := s.dao.GetSelectCourseList(orgid)
407
+	if err != nil {
408
+		return nil, err
409
+	}
410
+	for i, v := range list {
411
+		caseinfo, err := s.casedao.GetCaseByID(v.CaseId)
412
+		if err != nil {
413
+			return nil, err
414
+		}
415
+		list[i].CaseInfo = caseinfo
416
+	}
417
+	return list, err
418
+}
419
+
420
+// GetCourseByLocation 根据位置获取课程
421
+func (s *CourseServ) GetCourseByLocation(orgid, locationid string) ([]course.CourseDetail, error) {
422
+	if orgid == "" || locationid == "" {
423
+		return nil, utils.LogError("参数错误!")
424
+	}
425
+	list, err := s.dao.GetCourseByLocation(orgid, locationid)
426
+	if err != nil {
427
+		return nil, err
428
+	}
429
+	for i, v := range list {
430
+		caseinfo, err := s.casedao.GetCaseByID(v.CaseId)
431
+		if err != nil {
432
+			return nil, err
433
+		}
434
+		list[i].CaseInfo = caseinfo
435
+	}
436
+	return list, err
347
 }
437
 }

+ 11
- 1
service/message/cmscase.go View File

39
 }
39
 }
40
 
40
 
41
 // GetCmsCaseByOrg 获取项目列表
41
 // GetCmsCaseByOrg 获取项目列表
42
-func (s *MessageServ) GetCmsCaseByOrg(orgid string) ([]model.TaCmsCase, error) {
42
+func (s *MessageServ) GetCmsCaseByOrg(orgid string) ([]message.CmsCase, error) {
43
 	list, err := s.dao.GetCmsCaseByOrg(orgid)
43
 	list, err := s.dao.GetCmsCaseByOrg(orgid)
44
+	if err != nil {
45
+		return nil, err
46
+	}
47
+	for i, c := range list {
48
+		imgs, err := s.dao.GetCmsCaseImgs(c.CmsCaseId)
49
+		if err != nil {
50
+			return nil, err
51
+		}
52
+		list[i].CmsCaseImgs = imgs
53
+	}
44
 	return list, err
54
 	return list, err
45
 }
55
 }
46
 
56