liuyu 4 سال پیش
والد
کامیت
d7508fe615
2فایلهای تغییر یافته به همراه21 افزوده شده و 0 حذف شده
  1. 2 0
      app/controller/weixin.js
  2. 19 0
      app/service/lesson.js

+ 2 - 0
app/controller/weixin.js

@@ -80,6 +80,8 @@ class WeixinController extends Controller {
       const { redirect_uri, type, uid, qrcode } = JSON.parse(val);
       console.log('redirect_uri-->' + redirect_uri);
       const user = await this.ctx.service.user.findByOpenid(openid);
+      console.log(user);
+      console.log('type-->' + type);
       if (type === '0') {
         // 通过openid取得用户信息
         if (user) {

+ 19 - 0
app/service/lesson.js

@@ -15,6 +15,7 @@ class LessonService extends CrudService {
     this.tmodel = this.ctx.model.Trainplan;
     this.clamodel = this.ctx.model.Class;
     this.lmodel = this.ctx.model.Lessonmode;
+    this.teamodel = this.ctx.model.Teacher;
   }
 
   // 自动排课私有方法
@@ -72,6 +73,7 @@ class LessonService extends CrudService {
                 if (i === 6) {
                   allday = _lessonmode.allday;
                 }
+
                 const data = {
                   subid: _subid,
                   subname: lessm['day' + i],
@@ -79,6 +81,12 @@ class LessonService extends CrudService {
                   time: lessm.time,
                   day: allday,
                 };
+                // 将教师按照分数的综合成绩排序,上报时间,安排教师.
+                const teacher_ = await this.autoteacher(_subid);
+                if (teacher_) {
+                  data.teaid = teacher_.id;
+                  data.teaname = teacher_.name;
+                }
                 newlesson.push(data);
               }
             }
@@ -97,6 +105,17 @@ class LessonService extends CrudService {
     }
   }
 
+  // 自动排教师,按照分数的综合成绩排序,上报时间,安排教师
+  async autoteacher(subid) {
+    // 按照上报时间取得所有老师,进行正序排列
+    const teachers = await this.teamodel.find({ subid, status: '4' }).sort({ zlscore: '-1', msscore: '-1', xsscore: '-1' });
+    let teacher = {};
+    if (teachers.length > 0) {
+      teacher = teachers[0];
+    }
+    return teacher;
+  }
+
   // 取得日期间所有日期
   async getAllDays(begin_date, end_date) {
     const errArr = [],