lrf402788946 4 tahun lalu
induk
melakukan
e263c6f408
1 mengubah file dengan 20 tambahan dan 7 penghapusan
  1. 20 7
      app/service/leave.js

+ 20 - 7
app/service/leave.js

@@ -20,14 +20,20 @@ class LeaveService extends CrudService {
     const student = await this.smodel.findById(studentid);
     const schid = student.schid;
     const newdata = { ...data, status: '0', schid };
+    // TODO请假发送不对
+    let sch = await this.ctx.model.School.find({ code: schid });
+    if (!sch) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该学生的学校信息');
+    sch = JSON.parse(JSON.stringify(sch));
+    const { _id } = sch;
+    const user = await this.umodel.findOne({ uid: _id, type: '2' });
     const entity = await this.model.create(newdata);
-    const user = await this.umodel.findOne({ uid: schid, type: '2' });
     if (user) {
-      const openid = user.openid;
+      const openid = 'ocPqjswkUejZHq2ANriNrFFC7A3I'; // user.openid
       const date = await this.ctx.service.util.updatedate();
-      const detail = student.name + '发起了请假请求,请及时处理';
+      const detail = student.name + '发起了请假请求(点击消息审核请假)';
       const remark = '感谢您的使用';
-      await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
+      const to_uri = `${this.app.config.baseUrl}/msgconfirm/leave/status?id=${entity.id}`;
+      if (openid) { await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个学生请假通知', detail, date, remark, to_uri); }
     }
     return await this.fetch({ id: entity.id });
   }
@@ -78,7 +84,7 @@ class LeaveService extends CrudService {
         for (const user of users) {
           const openid = user.openid;
           const date = await this.ctx.service.util.updatedate();
-          this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', toOtherMsg, date, remark);
+          this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, 'ocPqjswkUejZHq2ANriNrFFC7A3I', '您有一个新的通知', toOtherMsg, date, remark);
         }
         const _class = await this.cmodel.findById(student.classid);
         // 通知班主任学生请假通过
@@ -87,7 +93,14 @@ class LeaveService extends CrudService {
         if (headuser) {
           const openid = headuser.openid;
           const date = await this.ctx.service.util.updatedate();
-          this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', toOtherMsg, date, remark);
+          // TODO,如果是退出,需要班主任确认,加上最后一个参数
+          if (leave.type === '1') {
+            const to_uri = `${this.app.config.baseUrl}/msgconfirm/leave/confirm?id=${leave.id}`;
+            const remark = '点击消息确认学生是否已经退出';
+            this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, 'ocPqjswkUejZHq2ANriNrFFC7A3I', '您有一个新的通知', toOtherMsg, date, remark, to_uri);
+          } else {
+            this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, 'ocPqjswkUejZHq2ANriNrFFC7A3I', '您有一个新的通知', toOtherMsg, date, remark);
+          }
         }
         const leadstu = await this.smodel.findOne({ classid: student.classid, job: '班长' });
         if (leadstu) {
@@ -95,7 +108,7 @@ class LeaveService extends CrudService {
           if (leaduser) {
             const openid = leaduser.openid;
             const date = await this.ctx.service.util.updatedate();
-            this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', toOtherMsg, date, remark);
+            this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, 'ocPqjswkUejZHq2ANriNrFFC7A3I', '您有一个新的通知', toOtherMsg, date, remark);
           }
         }
         const stuopenid = stuuser.openid;