lrf402788946 пре 4 година
родитељ
комит
fc8e323078
3 измењених фајлова са 44 додато и 1 уклоњено
  1. 5 1
      app/controller/.liveroom.js
  2. 6 0
      app/router.js
  3. 33 0
      app/service/liveroom.js

+ 5 - 1
app/controller/.liveroom.js

@@ -46,7 +46,11 @@ module.exports = {
     },
   },
   personcount: {
-    requestBody: ["number", "name", "userid", 'type'],
+    requestBody: ["number", "name", "userid", "type"],
     service: "personcount",
   },
+  sendmsg: {
+    requestBody: ["!roomid", "termid", "classid"],
+    service: "sendNotice",
+  },
 };

+ 6 - 0
app/router.js

@@ -540,6 +540,12 @@ module.exports = app => {
     '/api/train/liveroom/update/:id',
     controller.liveroom.update
   );
+  // 通知看直播
+  router.post(
+    'liveroom',
+    '/api/train/liveroom/sendmsg',
+    controller.liveroom.sendmsg
+  );
   // 监听人数
   router.post(
     'liveroom',

+ 33 - 0
app/service/liveroom.js

@@ -11,6 +11,8 @@ class LiveroomService extends CrudService {
   constructor(ctx) {
     super(ctx, 'liveroom');
     this.model = this.ctx.model.Liveroom;
+    this.stumodel = this.ctx.model.Student;
+    this.umodel = this.ctx.model.User;
   }
   async create(data) {
     const { subid, teacherid } = data;
@@ -61,6 +63,37 @@ class LiveroomService extends CrudService {
     }
     return list;
   }
+
+  async sendNotice(data) {
+    const { roomid, termid, classid } = data;
+    const room = await this.model.findById(roomid);
+    if (!room) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '直播房间不存在');
+    }
+    const backUrl = encodeURI(`${this.app.config.baseUrl}${this.config.authUrl}?state=0&redirect_uri=${this.app.config.baseUrl}/student/login?redirect_uri=/user/liveDetail/${roomid}`);
+    console.log(backUrl);
+    let list = [];
+    const query = {};
+    if (termid) query.termid = termid;
+    if (classid) query.classid = classid;
+    list = await this.stumodel.find(query);
+    list = list.map(i => ObjectId(i._id));
+    list = await this.umodel.find({ uid: { $in: list } });
+    for (const stu of list) {
+      const { openid } = stu;
+      if (openid) {
+        await this.ctx.service.weixin.sendTemplateDesign(
+          this.ctx.app.config.REVIEW_TEMPLATE_ID,
+          openid,
+          '您有一个新的通知!',
+          '您有新的安排',
+          '您有在线课堂将要开课,请注意课表上课时间',
+          '感谢您的使用',
+          backUrl
+        );
+      }
+    }
+  }
 }
 
 module.exports = LiveroomService;