reloaded 5 年之前
父節點
當前提交
463155f635
共有 6 個文件被更改,包括 52 次插入3 次删除
  1. 5 0
      app/controller/teacher.js
  2. 1 0
      app/router.js
  3. 17 0
      app/service/apply.js
  4. 6 2
      app/service/group.js
  5. 22 1
      app/service/teacher.js
  6. 1 0
      app/service/teaplan.js

+ 5 - 0
app/controller/teacher.js

@@ -48,6 +48,11 @@ class TeacherController extends Controller {
     this.ctx.ok({ data: res });
     this.ctx.ok({ data: res });
   }
   }
 
 
+  async status() {
+    const res = await this.service.status(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+
 }
 }
 
 
 module.exports = TeacherController;
 module.exports = TeacherController;

+ 1 - 0
app/router.js

@@ -17,6 +17,7 @@ module.exports = app => {
   router.post('teacher', '/api/train/teacher/update/:id', controller.teacher.update);
   router.post('teacher', '/api/train/teacher/update/:id', controller.teacher.update);
   router.get('teacher', '/api/train/teacher', controller.teacher.query);
   router.get('teacher', '/api/train/teacher', controller.teacher.query);
   router.get('teacher', '/api/train/teacher/show/:id', controller.teacher.show);
   router.get('teacher', '/api/train/teacher/show/:id', controller.teacher.show);
+  router.post('teacher', '/api/train/teacher/status', controller.teacher.status);
 
 
   // 作业表配置路由
   // 作业表配置路由
   router.post('task', '/api/train/task', controller.task.create);
   router.post('task', '/api/train/task', controller.task.create);

+ 17 - 0
app/service/apply.js

@@ -11,6 +11,23 @@ class ApplyService extends CrudService {
   constructor(ctx) {
   constructor(ctx) {
     super(ctx, 'apply');
     super(ctx, 'apply');
     this.model = this.ctx.model.Apply;
     this.model = this.ctx.model.Apply;
+    this.tmodel = this.ctx.model.Teacher;
+  }
+
+  // 查询
+  async query({ skip, limit, ...num }) {
+    const total = await this.model.find(num).length;
+    const data = await this.model.find(num).skip(Number(skip)).limit(Number(limit));
+    console.log(data);
+    const teachers = [];
+    for (const _data of data) {
+      const teacherid = _data.teacherid;
+      const teacher = await this.tmodel.findById(teacherid);
+      teachers.push(teacher);
+    }
+    const newdata = { data, teachers };
+    const result = { total, newdata };
+    return result;
   }
   }
 
 
 }
 }

+ 6 - 2
app/service/group.js

@@ -16,8 +16,12 @@ class GroupService extends CrudService {
   async insert(data) {
   async insert(data) {
     const { groupid, studentid } = data;
     const { groupid, studentid } = data;
     const group = await this.model.findById(groupid);
     const group = await this.model.findById(groupid);
-    group.studentid.push(studentid);
-    await group.save();
+    if (group.studentid.includes(studentid)) {
+      throw new BusinessError(ErrorCode.DATA_EXIST, '您已加入该组,请勿重复操作');
+    } else {
+      group.studentid.push(studentid);
+      await group.save();
+    }
   }
   }
 
 
   async exit(data) {
   async exit(data) {

+ 22 - 1
app/service/teacher.js

@@ -89,8 +89,10 @@ class TeacherService extends CrudService {
 
 
   // 根据参数查询信息
   // 根据参数查询信息
   async query({ skip, limit, ...number }) {
   async query({ skip, limit, ...number }) {
+    const total = await this.model.find(number);
     const teacher = await this.model.find(number).skip(Number(skip)).limit(Number(limit));
     const teacher = await this.model.find(number).skip(Number(skip)).limit(Number(limit));
-    return teacher;
+    const result = { total, teacher };
+    return result;
   }
   }
 
 
   // 查询详情
   // 查询详情
@@ -99,6 +101,25 @@ class TeacherService extends CrudService {
     return await this.model.findById(id, '+file');
     return await this.model.findById(id, '+file');
   }
   }
 
 
+  async status(data) {
+    const { teachersid, status, remark } = data;
+    for (const teacherid of teachersid) {
+      const teacher = await this.model.findById(teacherid);
+      teacher.status = status;
+      await teacher.save();
+      let detail = '';
+      if (status === '1') {
+        detail = '您的账号身份已确认,请尽快登录账号上传课件资料附件';
+      } else if (status === '4') {
+        detail = '您已通过审核被正式录入教师库';
+      }
+      const moment = require('moment');
+      const date = moment(teacher.meta.updatedAt).format('YYYY-MM-DD HH:mm:ss');
+      console.log(detail);
+      await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, teacher.openid, '您有一个新的通知', detail, date, remark);
+    }
+  }
+
 }
 }
 
 
 module.exports = TeacherService;
 module.exports = TeacherService;

+ 1 - 0
app/service/teaplan.js

@@ -12,6 +12,7 @@ class TeaplanService extends CrudService {
     super(ctx, 'teaplan');
     super(ctx, 'teaplan');
     this.model = this.ctx.model.Teaplan;
     this.model = this.ctx.model.Teaplan;
   }
   }
+
 }
 }
 
 
 module.exports = TeaplanService;
 module.exports = TeaplanService;