Преглед на файлове

新增培训计划发布后向学校及老师发送通知

reloaded преди 5 години
родител
ревизия
27c128b800
променени са 2 файла, в които са добавени 55 реда и са изтрити 21 реда
  1. 2 2
      app/service/teacher.js
  2. 53 19
      app/service/trainplan.js

+ 2 - 2
app/service/teacher.js

@@ -114,8 +114,8 @@ class TeacherService extends CrudService {
         detail = '您已通过审核被正式录入教师库';
       }
       const moment = require('moment');
-      const date = moment(teacher.meta.updatedAt).format('YYYY-MM-DD HH:mm:ss');
-      console.log(detail);
+      let date = new Date();
+      date = moment(date).format('YYYY-MM-DD HH:mm:ss');
       await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, teacher.openid, '您有一个新的通知', detail, date, remark);
     }
   }

+ 53 - 19
app/service/trainplan.js

@@ -12,26 +12,60 @@ class TrainplanService extends CrudService {
     super(ctx, 'trainplan');
     this.model = this.ctx.model.Trainplan;
     this.clamodel = this.ctx.model.Class;
+    this.umodel = this.ctx.model.User;
+    this.smodel = this.ctx.model.School;
+    this.tmodel = this.ctx.model.Teacher;
   }
 
-//   async create(data) {
-//     const terminfo = await data.termnum;
-//     console.log(terminfo);
-//     const { batchnum: { type, name, number }, term } = terminfo;
-//     console.log(type);
-//     if (type === 1) {
-//       const classdata = { name, number, term, type };
-//       await this.clamodel.create(classdata);
-//     }
-//     if (type === 0) {
-//       for (let i = 0; i < class; i++) {
-//         const name = '第' + term + '期' + batch + '批次' + i + '班';
-//         const classdate = { name, number, term, type, newbatch };
-//         await this.clamodel.create(classdate);
-//       }
-//     }
-//     return this.tpmodel.create(data);
-//   }
-// }
+  //   async create(data) {
+  //     const terminfo = await data.termnum;
+  //     console.log(terminfo);
+  //     const { batchnum: { type, name, number }, term } = terminfo;
+  //     console.log(type);
+  //     if (type === 1) {
+  //       const classdata = { name, number, term, type };
+  //       await this.clamodel.create(classdata);
+  //     }
+  //     if (type === 0) {
+  //       for (let i = 0; i < class; i++) {
+  //         const name = '第' + term + '期' + batch + '批次' + i + '班';
+  //         const classdate = { name, number, term, type, newbatch };
+  //         await this.clamodel.create(classdate);
+  //       }
+  //     }
+  //     return this.tpmodel.create(data);
+  //   }
+  // }
+
+  async update({ id }, data) {
+    const trainplan = await this.model.findById(id);
+    trainplan.year = data.year;
+    trainplan.title = data.title;
+    trainplan.termnum = data.termnum;
+    trainplan.festivals = data.festivals;
+    if (data.status === '1') {
+      const teachers = await this.tmodel.find({ status: '4' });
+      for (const teacher of teachers) {
+        const openid = teacher.openid;
+        const detail = data.title + '已发布,请注意查收!';
+        const moment = require('moment');
+        let date = new Date();
+        date = moment(date).format('YYYY-MM-DD HH:mm:ss');
+        const remark = '感谢您的使用';
+        this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
+      }
+      const schools = await this.umodel.find({ type: '2' });
+      for (const school of schools) {
+        const openid = school.openid;
+        const detail = data.title + '已发布,请注意查收!';
+        const moment = require('moment');
+        let date = new Date();
+        date = moment(date).format('YYYY-MM-DD HH:mm:ss');
+        const remark = '感谢您的使用';
+        this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
+      }
+    }
+
+  }
 }
 module.exports = TrainplanService;