lrf402788946 4 năm trước cách đây
mục cha
commit
202ca91b48
3 tập tin đã thay đổi với 24 bổ sung4 xóa
  1. 6 2
      app/service/count.js
  2. 17 1
      app/service/leave.js
  3. 1 1
      app/service/lesson.js

+ 6 - 2
app/service/count.js

@@ -82,7 +82,9 @@ class CountService extends CrudService {
     ]);
     const h = _.head(trainstuRes);
     if (h) {
-      const { total: trainstu } = h;
+      let { total: trainstu } = h;
+      // 减去退出的学生
+      trainstu = trainstu - data.levelexit || 0;
       data.trainstu = trainstu;
     } else {
       data.trainstu = 0;
@@ -179,7 +181,9 @@ class CountService extends CrudService {
     ]);
     const h = _.head(trainstuRes);
     if (h) {
-      const { total: trainstu } = h;
+      let { total: trainstu } = h;
+      // 减去退出的学生
+      trainstu = trainstu - data.levelexit || 0;
       data.trainstu = trainstu;
     } else {
       data.trainstu = 0;

+ 17 - 1
app/service/leave.js

@@ -16,6 +16,7 @@ class LeaveService extends CrudService {
     this.cmodel = this.ctx.model.Class;
   }
   async create(data) {
+    const { type } = data;
     const studentid = data.studentid;
     const student = await this.smodel.findById(studentid);
     const schid = student.schid;
@@ -25,7 +26,22 @@ class LeaveService extends CrudService {
     sch = JSON.parse(JSON.stringify(sch));
     const { _id } = sch;
     const user = await this.umodel.findOne({ uid: _id, type: '2' });
-    const entity = await this.model.create(newdata);
+    let entity;
+    if (type === '1') {
+      // 退出只能有一个
+      entity = await this.model.findOne({ studentid, type: '1' });
+      if (entity) {
+        const { starttime, endtime, reason } = data;
+        if (starttime) entity.starttime = starttime;
+        if (endtime) entity.endtime = endtime;
+        if (reason) entity.reason = reason;
+        await entity.save();
+      } else {
+        entity = await this.model.create(newdata);
+      }
+    } else {
+      entity = await this.model.create(newdata);
+    }
     if (user) {
       const openid = user.openid;
       const date = await this.ctx.service.util.updatedate();

+ 1 - 1
app/service/lesson.js

@@ -599,7 +599,7 @@ class LessonService extends CrudService {
                 }
               }
             }
-            const obj = { date, time, ...kvs };
+            const obj = { date, time, ...kvs, day: '0' };
             lessons.push(obj);
           }