lrf 2 роки тому
батько
коміт
196ccaba2d

+ 1 - 1
app/controller/config/.statistics.js.js

@@ -72,6 +72,6 @@ module.exports = {
     },
   },
   studentSign: {
-    requestBody: ['lesson_id', 'student_id', 'range'],
+    requestBody: ['lesson_id', 'student_id', 'range', 'skip', 'limit'],
   },
 };

+ 1 - 0
app/model/apply/tempLessonApply.js

@@ -14,6 +14,7 @@ const tempLessonApply = {
   file: { type: Array, required: false, zh: '证据' }, //
   is_pay: { type: String, default: '0', zh: '是否已支付' }, // 0:未支付;1:已支付:-1:支付失败:-3已退款
   pay_id: { type: String, required: false, zh: '支付id', ref: 'PayOrder' }, //
+  is_sign: { type: String, required: false, default: '1', zh: '签到' }, // 0:未到;1:已签到
 };
 const schema = new Schema(tempLessonApply, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });

+ 58 - 5
app/service/statistics.js

@@ -287,8 +287,12 @@ class StatisticsService extends CrudService {
   }
 
   async studentSign({ lesson_id, student_id, range, skip, limit }) {
+    console.log('line 290 in function:');
     const pipeline = [];
-    let $match = { lesson_id, student_id };
+    const baseCol = { time_start: 1, title: 1 };
+    const studentQuery = {};
+    // 返回数据:课程,上课时间,学生,是否签到,是否缴费
+    let $match = { lesson_id };
     if (_.isArray(range)) {
       const start = _.head(range);
       const end = _.last(range);
@@ -297,11 +301,60 @@ class StatisticsService extends CrudService {
       $match = { ...$match, ...tq };
     }
     pipeline.push({ $match });
-
-    //
-
+    pipeline.push({ $addFields: { lesson_id: { $toString: '$_id' } } });
+    if (student_id) {
+      studentQuery.student_id = student_id;
+    }
+    // #region 正式学生
+    pipeline.push({
+      $lookup: {
+        from: 'lessonStudent',
+        localField: 'lesson_id',
+        foreignField: 'lesson_id',
+        pipeline: [
+          { $match: studentQuery },
+          { $project: { is_sign: 1, is_pay: 1, soid: { $toObjectId: '$student_id' } } },
+          {
+            $lookup: {
+              from: 'student',
+              localField: 'soid',
+              foreignField: '_id',
+              as: 'si',
+            },
+          },
+          { $project: { is_sign: 1, is_pay: 1, name: { $first: '$si.name' }, icon: { $first: '$si.icon' } } },
+        ],
+        as: 'zStudent',
+      },
+    });
+    // #endregion
+    // #region 临时学生
+    pipeline.push({
+      $lookup: {
+        from: 'tempLessonApply',
+        localField: 'lesson_id',
+        foreignField: 'lesson_id',
+        pipeline: [
+          { $match: studentQuery },
+          { $addFields: { soid: { $toObjectId: '$student_id' } } },
+          {
+            $lookup: {
+              from: 'student',
+              localField: 'soid',
+              foreignField: '_id',
+              as: 'si',
+            },
+          },
+          { $project: { name: 1, is_sign: 1, is_pay: 1, icon: { $ifNull: [{ $first: '$si.icon' }, []] } } },
+        ],
+        as: 'lStudent',
+      },
+    });
+    // #endregion
+    pipeline.push({ $project: { ...baseCol, studentList: { $concatArrays: [ '$zStudent', '$lStudent' ] } } });
+    pipeline.push({ $unwind: '$studentList' });
+    pipeline.push({ $project: { ...baseCol, name: '$studentList.name', is_pay: '$studentList.is_pay', is_sign: '$studentList.is_sign', icon: '$studentList.icon' } });
     pipeline.push({ $sort: { time_start: 1 } });
-    // 返回数据:学生,上课时间,课程,是否签单,是否缴费
     const res = await this.lessonModel.aggregate(pipeline);
     return res;
   }

+ 1 - 1
app/z_router/statistics.js

@@ -7,7 +7,7 @@ const rkey = 'statistics';
 const ckey = 'statistics';
 const keyZh = '统计';
 const routes = [
-  { method: 'get', path: `${rkey}/studentSign`, controller: `${ckey}.studentSign`, name: `${ckey}studentSign`, zh: `${keyZh}-学员签到情况` },
+  { method: 'post', path: `${rkey}/studentSign`, controller: `${ckey}.studentSign`, name: `${ckey}studentSign`, zh: `${keyZh}-学员签到情况` },
   { method: 'get', path: `${rkey}/schoolInByLesson`, middleware: [ 'dealQuery' ], controller: `${ckey}.schoolInByLesson`, name: `${ckey}schoolInByLesson`, zh: `${keyZh}-收入明细` },
   { method: 'get', path: `${rkey}/coachStudentLesson`, controller: `${ckey}.coachStudentLesson`, name: `${ckey}coachStudentLesson`, zh: `${keyZh}-教练,学员情况` },
   { method: 'get', path: `${rkey}/coachLesson`, controller: `${ckey}.coachLesson`, name: `${ckey}coachLesson`, zh: `${keyZh}-教练,授课情况` },