leave.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class LeaveService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'leave');
  10. this.model = this.ctx.model.Leave;
  11. this.smodel = this.ctx.model.Student;
  12. this.umodel = this.ctx.model.User;
  13. }
  14. async create(data) {
  15. const newdata = { ...data, status: '0' };
  16. const entity = await this.model.create(newdata);
  17. const studentid = data.studentid;
  18. const student = await this.smodel.findById(studentid);
  19. const schoolid = student.schoolid;
  20. const user = await this.umodel.findOne({ uid: schoolid });
  21. const openid = user.openid;
  22. const date = await this.ctx.service.util.updatedate();
  23. const detail = student.name + '发起了请假请求,请及时处理';
  24. const remark = '感谢您的使用';
  25. await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
  26. return await this.fetch({ id: entity.id });
  27. }
  28. }
  29. module.exports = LeaveService;