|
@@ -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;
|