1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- class TrainplanService extends CrudService {
- constructor(ctx) {
- 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 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;
|