|
@@ -39,25 +39,39 @@ class TrainplanService extends CrudService {
|
|
|
|
|
|
async update({ id }, data) {
|
|
async update({ id }, data) {
|
|
const trainplan = await this.model.findById(id);
|
|
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 { year, title, termnum, festivals, status } = data;
|
|
|
|
+ if (year) {
|
|
|
|
+ trainplan.year = year;
|
|
|
|
+ }
|
|
|
|
+ if (title) {
|
|
|
|
+ trainplan.title = title;
|
|
|
|
+ }
|
|
|
|
+ if (termnum) {
|
|
|
|
+ trainplan.termnum = termnum;
|
|
|
|
+ }
|
|
|
|
+ if (festivals) {
|
|
|
|
+ trainplan.festivals = festivals;
|
|
|
|
+ }
|
|
|
|
+ // 如果培训计划状态改为发布
|
|
|
|
+ if (status === '1') {
|
|
|
|
+ // 查询所有入库的教师
|
|
const teachers = await this.tmodel.find({ status: '4' });
|
|
const teachers = await this.tmodel.find({ status: '4' });
|
|
for (const teacher of teachers) {
|
|
for (const teacher of teachers) {
|
|
- const openid = teacher.openid;
|
|
|
|
- const detail = data.title + '已发布,请注意查收!';
|
|
|
|
|
|
+ const teacherid = teacher._id;
|
|
|
|
+ const _teacher = await this.umodel.findOne({ uid: teacherid, type: '3' });
|
|
|
|
+ const openid = _teacher.openid;
|
|
|
|
+ const detail = trainplan.title + '已发布,请注意查收!';
|
|
const moment = require('moment');
|
|
const moment = require('moment');
|
|
let date = new Date();
|
|
let date = new Date();
|
|
date = moment(date).format('YYYY-MM-DD HH:mm:ss');
|
|
date = moment(date).format('YYYY-MM-DD HH:mm:ss');
|
|
const remark = '感谢您的使用';
|
|
const remark = '感谢您的使用';
|
|
this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, 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' });
|
|
const schools = await this.umodel.find({ type: '2' });
|
|
for (const school of schools) {
|
|
for (const school of schools) {
|
|
const openid = school.openid;
|
|
const openid = school.openid;
|
|
- const detail = data.title + '已发布,请注意查收!';
|
|
|
|
|
|
+ const detail = trainplan.title + '已发布,请注意查收!';
|
|
const moment = require('moment');
|
|
const moment = require('moment');
|
|
let date = new Date();
|
|
let date = new Date();
|
|
date = moment(date).format('YYYY-MM-DD HH:mm:ss');
|
|
date = moment(date).format('YYYY-MM-DD HH:mm:ss');
|
|
@@ -65,7 +79,7 @@ class TrainplanService extends CrudService {
|
|
this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
|
|
this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ return await trainplan.save();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
module.exports = TrainplanService;
|
|
module.exports = TrainplanService;
|