12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const stringRandom = require('string-random');
- class TeacherService extends CrudService {
- constructor(ctx) {
- super(ctx, 'teacher');
- this.model = this.ctx.model.Teacher;
- this.umodel = this.ctx.model.User;
- }
- // 根据状态删除教师信息
- async deleteByStatus({ status }) {
- await this.model.deleteMany({ status });
- return 'deleted';
- }
- // 查询详情
- async fetchTeacher({ id }) {
- // 将文件拼到查询到的数据后
- 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') {
- const passwd = stringRandom();
- detail = '您的账号身份已确认,密码为:' + passwd + '请尽快登录账号上传课件资料附件';
- // 状态更新后创建教师用户
- const newdata = { name: teacher.name, mobile: teacher.phone, type: '3', uid: teacher.id };
- newdata.passwd = passwd;
- await this.umodel.create(newdata);
- } else if (status === '4') {
- detail = '您已通过审核被正式录入教师库';
- }
- const moment = require('moment');
- 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);
- }
- }
- }
- module.exports = TeacherService;
|