12345678910111213141516171819202122232425262728293031323334 |
- '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 LeaveService extends CrudService {
- constructor(ctx) {
- super(ctx, 'leave');
- this.model = this.ctx.model.Leave;
- this.smodel = this.ctx.model.Student;
- this.umodel = this.ctx.model.User;
- }
- async create(data) {
- const newdata = { ...data, status: '0' };
- const entity = await this.model.create(newdata);
- const studentid = data.studentid;
- const student = await this.smodel.findById(studentid);
- const schoolid = student.schoolid;
- const user = await this.umodel.findOne({ uid: schoolid });
- const openid = user.openid;
- const date = await this.ctx.service.util.updatedate();
- const detail = student.name + '发起了请假请求,请及时处理';
- const remark = '感谢您的使用';
- await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
- return await this.fetch({ id: entity.id });
- }
- }
- module.exports = LeaveService;
|