Pārlūkot izejas kodu

Merge branch 'master' of http://git.cc-lotus.info/new_train/service-center

liuyu 4 gadi atpakaļ
vecāks
revīzija
497a71c0f2
3 mainītis faili ar 24 papildinājumiem un 1 dzēšanām
  1. 9 1
      app/controller/class.js
  2. 1 0
      app/router.js
  3. 14 0
      app/service/class.js

+ 9 - 1
app/controller/class.js

@@ -29,7 +29,15 @@ class ClassController extends Controller {
 
   // 根据班级id与学生id修改学生班级
   async studentupclass() {
-    const res = await this.service.studentupclass(this.ctx.params, this.ctx.request.body);
+    const res = await this.service.studentupclass(
+      this.ctx.params,
+      this.ctx.request.body
+    );
+    this.ctx.ok({ data: res });
+  }
+
+  async searchDate() {
+    const res = await this.service.searchDate(this.ctx.query);
     this.ctx.ok({ data: res });
   }
 }

+ 1 - 0
app/router.js

@@ -53,6 +53,7 @@ module.exports = app => {
   router.post('bedroom', '/api/train/bedroom/ibeacon', controller.bedroom.ibeacon);
 
   // 班级表设置路由
+  router.get('class', '/api/train/class/searchDate', controller.class.searchDate);
   router.post('class', '/api/train/class/notice', controller.class.notice);
   router.resources('class', '/api/train/class', controller.class); // index、create、show、destroy
   router.post('class', '/api/train/class/update/:id', controller.class.update);

+ 14 - 0
app/service/class.js

@@ -138,6 +138,20 @@ class ClassService extends CrudService {
       await classInfo.save();
     }
   }
+
+  async searchDate({ classid }) {
+    const classInfo = await this.model.findById(classid);
+    const trainplan = await this.tmodel.findById(classInfo.planid);
+    if (trainplan) {
+      const term = _.filter(trainplan.termnum, item => item.id === classInfo.termid);
+      if (term.length > 0) {
+        const batch = _.filter(term[0].batchnum, item => item.id === classInfo.batchid);
+        if (batch.length > 0) {
+          return { startdate: batch[0].startdate, enddate: batch[0].enddate };
+        }
+      }
+    }
+  }
 }
 
 module.exports = ClassService;