lrf 2 years ago
parent
commit
0dcfe7f34a
3 changed files with 42 additions and 0 deletions
  1. 8 0
      app/controller/config/.statistics.js.js
  2. 33 0
      app/service/statistics.js
  3. 1 0
      app/z_router/statistics.js

+ 8 - 0
app/controller/config/.statistics.js.js

@@ -38,4 +38,12 @@ module.exports = {
       },
     },
   },
+  studentPay: {
+    parameters: {
+      query: {
+        school_id: 'school_id',
+        student_id: 'student_id',
+      },
+    },
+  },
 };

+ 33 - 0
app/service/statistics.js

@@ -17,8 +17,41 @@ class StatisticsService extends CrudService {
     this.lessonStudentModel = this.ctx.model.Business.LessonStudent;
     this.lessonModel = this.ctx.model.Business.Lesson;
   }
+  // 学员统计,付费情况
+  async studentPay({ school_id, student_id }) {
+    assert(school_id, '缺少学校信息');
+    assert(student_id, '缺少学生信息');
+    const query = { school_id, payer_id: student_id, is_pay: '1', type: [ '-1', '-2', '2' ] };
+    const { year } = this.getPartsOfNow();
+    const yearEnd = `${year}-12-01`;
+    let monthList = this.getMonthList(12, yearEnd);
+    monthList = monthList.map(i => {
+      const start = moment(i).startOf('month').format('YYYY-MM-DD HH:mm:ss');
+      const end = moment(i).endOf('month').format('YYYY-MM-DD HH:mm:ss');
+      return [ start, end ];
+    });
+    query.$and = [{ 'meta.createdAt': { $gte: `${year}-01-01 00:00:00` } }, { 'meta.createdAt': { $lte: `${year}-12-31 23:59:59` } }];
+    const billList = await this.billModel.find(query);
+    const arr = [];
+    for (const months of monthList) {
+      const s = _.head(months);
+      const l = _.last(months);
+      const m = moment(s).month() + 1;
+      const list = billList.filter(f => moment(_.get(f, 'meta.createdAt')).isBetween(s, l, null, '[]'));
+      const payList = list.filter(f => f.type !== '2');
+      const returnList = list.filter(f => f.type === '2');
+      const pay = payList.reduce((p, n) => p + (n.money || 0), 0);
+      const ret = returnList.reduce((p, n) => p + (n.money || 0), 0);
+      const total = pay - ret;
+      arr.push({ name: `${m}月`, value: total });
+    }
+    return arr;
+  }
 
+
+  // 学员统计,学员上课时长及签到
   async studentLearning({ school_id, student_id }) {
+    assert(school_id, '缺少学校信息');
     assert(student_id, '缺少学生信息');
     const query = { school_id, student_id, is_pay: '1' };
     const { year } = this.getPartsOfNow();

+ 1 - 0
app/z_router/statistics.js

@@ -7,6 +7,7 @@ const rkey = 'statistics';
 const ckey = 'statistics';
 const keyZh = '统计';
 const routes = [
+  { method: 'get', path: `${rkey}/studentPay`, controller: `${ckey}.studentPay`, name: `${ckey}studentPay`, zh: `${keyZh}-学员,付费情况` },
   { method: 'get', path: `${rkey}/studentLearning`, controller: `${ckey}.studentLearning`, name: `${ckey}studentLearning`, zh: `${keyZh}-学员,学习情况` },
   { method: 'get', path: `${rkey}/schoolCoachIn`, controller: `${ckey}.schoolCoachIn`, name: `${ckey}schoolCoachIn`, zh: `${keyZh}-羽校,教练收入` },
   { method: 'get', path: `${rkey}/schoolSignCoach`, controller: `${ckey}.schoolSignCoach`, name: `${ckey}schoolSignCoach`, zh: `${keyZh}-羽校,教练出勤率` },