|
@@ -13,6 +13,7 @@ class LeaveService extends CrudService {
|
|
|
this.model = this.ctx.model.Leave;
|
|
|
this.smodel = this.ctx.model.Student;
|
|
|
this.umodel = this.ctx.model.User;
|
|
|
+ this.cmodel = this.ctx.model.Class;
|
|
|
}
|
|
|
async create(data) {
|
|
|
const newdata = { ...data, status: '0' };
|
|
@@ -29,6 +30,57 @@ class LeaveService extends CrudService {
|
|
|
return await this.fetch({ id: entity.id });
|
|
|
}
|
|
|
|
|
|
+ async update({ id }, data) {
|
|
|
+ const leave = await this.model.findById(id);
|
|
|
+ const { studentid, starttime, endtime, reason, status, refcause } = data;
|
|
|
+ if (studentid) {
|
|
|
+ leave.studentid = studentid;
|
|
|
+ }
|
|
|
+ if (starttime) {
|
|
|
+ leave.starttime = starttime;
|
|
|
+ }
|
|
|
+ if (endtime) {
|
|
|
+ leave.endtime = endtime;
|
|
|
+ }
|
|
|
+ if (reason) {
|
|
|
+ leave.reason = reason;
|
|
|
+ }
|
|
|
+ if (status) {
|
|
|
+ const student = await this.smodel.findById(studentid);
|
|
|
+ const remark = '感谢您的使用';
|
|
|
+ const stuuser = await this.umodel.findOne({ uid: studentid });
|
|
|
+ if (status === '1') {
|
|
|
+ let detail = student.name + '的请假申请已通过,请及时查收!';
|
|
|
+ const users = await this.umodel.find({ type: '0' });
|
|
|
+ for (const user of users) {
|
|
|
+ const openid = user.openid;
|
|
|
+ const date = await this.ctx.service.util.updatedate();
|
|
|
+ await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
|
|
|
+ }
|
|
|
+ const _class = await this.cmodel.findById(student.classid);
|
|
|
+ const headteacherid = _class.headteacherid;
|
|
|
+ const headuser = await this.umodel.findOne({ uid: headteacherid });
|
|
|
+ const openid = headuser.openid;
|
|
|
+ const date = await this.ctx.service.util.updatedate();
|
|
|
+ await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
|
|
|
+ const stuopenid = stuuser.openid;
|
|
|
+ detail = '您的请假申请已通过,请及时查收!';
|
|
|
+ await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, stuopenid, '您有一个新的通知', detail, date, remark);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (status === '2') {
|
|
|
+ const detail = '您的请假申请已被拒绝,拒绝原因为:' + refcause;
|
|
|
+ const openid = stuuser.openid;
|
|
|
+ const date = await this.ctx.service.util.updatedate();
|
|
|
+ await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (refcause) {
|
|
|
+ leave.refcause = refcause;
|
|
|
+ }
|
|
|
+ return await leave.save();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
module.exports = LeaveService;
|