lrf402788946 4 лет назад
Родитель
Сommit
e0f7e3af08
1 измененных файлов с 3 добавлено и 124 удалено
  1. 3 124
      app/service/notice.js

+ 3 - 124
app/service/notice.js

@@ -53,10 +53,6 @@ class NoticeService extends CrudService {
       else if (type === '3') personList = await this.getRangeClasses({ id: classid });
     }
     personList = personList.map(i => i._id);
-    // console.group('发送人列表');
-    // console.table(userList);
-    // console.groupEnd();
-    // console.log(personList);
     // 获取所有人后发送信息
     const userList = await this.umodel.find({ uid: { $in: personList } });
     console.log(userList);
@@ -68,34 +64,13 @@ class NoticeService extends CrudService {
       const remark = '感谢您的使用';
       const date = await this.ctx.service.util.updatedate();
       const detail = content;
-      const tourl = this.ctx.app.config.baseUrl + '/mobiledirtea/messageInfo/index?uid=' + user.uid + '&noticeid=' + res.id;
+      const tourl = this.ctx.app.config.baseUrl + '/trainnotice/?userid=' + user._id + '&noticeid=' + res.id;
       this.ctx.service.weixin.sendTemplateDesign(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知,请点击确认您已收到信息!', detail, date, remark, tourl);
       const notified = _.get(res, 'notified', []);
       notified.push({ notifiedid: user._id, username: user.name });
       res.notified = notified;
     }
     res.save();
-    // if (res) {
-    //   // 判断班级id是否为空
-    //   // 不为空时被通知人:当前期,班下的学生,教师,班主任,并使用type判断
-    //   const notified_ = await this.getnotified(termid, classid, type);
-    //   res.notified = notified_;
-    //   await res.save();
-    //   for (const elm of notified_) {
-    //     const user = await this.umodel.findOne({ uid: elm.notifiedid });
-    //     if (!user) {
-    //       continue;
-    //     }
-    //     if (user.openid) {
-    //       const openid = user.openid;
-    //       const remark = '感谢您的使用';
-    //       const date = await this.ctx.service.util.updatedate();
-    //       const detail = '尊敬的' + user.name + ',您有一个新的通知,请及时查收';
-    //       const tourl = this.ctx.app.config.baseUrl + '/mobiledirtea/messageInfo/index?uid=' + user.uid + '&noticeid=' + res.id;
-    //       this.ctx.service.weixin.sendTemplateDesign(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark, tourl);
-    //     }
-    //   }
-    // }
   }
 
   /**
@@ -145,108 +120,12 @@ class NoticeService extends CrudService {
   }
 
 
-  // 取得要通知的人
-  async getnotified(termid, classid, type) {
-    const notified_ = [];
-    if (classid) {
-      if (type === '1') {
-        const students = await this.stumodel.find({ classid });
-        for (const stu of students) {
-          const newdata = { notifiedid: stu.id, username: stu.name };
-          notified_.push(newdata);
-        }
-      } else if (type === '2') {
-        const lesson = await this.lmodel.findOne({ classid });
-        for (const elm of lesson.lessons) {
-          const newdata = { notifiedid: elm.teaid, username: elm.teaname };
-          notified_.push(newdata);
-        }
-      } else if (type === '3') {
-        const class_ = await this.clsmodel.findById(classid);
-        if (class_) {
-          const htea = await this.heamodel.findById(class_.headteacherid);
-          if (htea) {
-            const newdata = { notifiedid: htea.id, username: htea.name };
-            notified_.push(newdata);
-          }
-        }
-      } else if (type === '0') {
-        const students = await this.stumodel.find({ classid });
-        for (const stu of students) {
-          const newdata = { notifiedid: stu.id, username: stu.name };
-          notified_.push(newdata);
-        }
-        const lesson = await this.lmodel.findOne({ classid });
-        for (const elm of lesson.lessons) {
-          const newdata = { notifiedid: elm.teaid, username: elm.teaname };
-          notified_.push(newdata);
-        }
-        const class_ = await this.clsmodel.findById(classid);
-        if (class_) {
-          const htea = await this.heamodel.findById(class_.headteacherid);
-          if (htea) {
-            const newdata = { notifiedid: htea.id, username: htea.name };
-            notified_.push(newdata);
-          }
-        }
-      }
-    } else {
-      // 没输入班级的时候
-      if (type === '1') {
-        const students = await this.stumodel.find({ termid });
-        for (const stu of students) {
-          const newdata = { notifiedid: stu.id, username: stu.name };
-          notified_.push(newdata);
-        }
-      } else if (type === '2') {
-        const lessons = await this.lmodel.find({ termid });
-        for (const les of lessons) {
-          for (const elm of les.lessons) {
-            const newdata = { notifiedid: elm.teaid, username: elm.teaname };
-            notified_.push(newdata);
-          }
-        }
-      } else if (type === '3') {
-        const class_ = await this.clsmodel.find({ termid });
-        for (const cla of class_) {
-          const htea = await this.heamodel.findById(cla.headteacherid);
-          if (htea) {
-            const newdata = { notifiedid: htea.id, username: htea.name };
-            notified_.push(newdata);
-          }
-        }
-      } else if (type === '0') {
-        const students = await this.stumodel.find({ termid });
-        for (const stu of students) {
-          const newdata = { notifiedid: stu.id, username: stu.name };
-          notified_.push(newdata);
-        }
-        const lessons = await this.lmodel.find({ termid });
-        for (const les of lessons) {
-          for (const elm of les.lessons) {
-            const newdata = { notifiedid: elm.teaid, username: elm.teaname };
-            notified_.push(newdata);
-          }
-        }
-        const class_ = await this.clsmodel.find({ termid });
-        for (const cla of class_) {
-          const htea = await this.heamodel.findById(cla.headteacherid);
-          if (htea) {
-            const newdata = { notifiedid: htea.id, username: htea.name };
-            notified_.push(newdata);
-          }
-        }
-      }
-    }
-    return notified_;
-  }
-
   async look(data) {
-    const { noticeid, uid } = data;
+    const { noticeid, userid } = data;
     const notice = await this.model.findById(noticeid);
     if (notice) {
       for (const elm of notice.notified) {
-        if (elm.notifiedid === uid) {
+        if (elm.notifiedid === userid) {
           elm.status = '1';
           elm.readtime = sd.format(new Date(), 'YYYY-MM-DD HH:mm:ss');
         }