Преглед на файлове

修改统计,将套餐id修改成套餐名词

lrf402788946 преди 4 години
родител
ревизия
72cb5b25a8
променени са 3 файла, в които са добавени 37 реда и са изтрити 11 реда
  1. 36 7
      app/service/count.js
  2. 0 2
      app/service/set.js
  3. 1 2
      app/service/util.js

+ 36 - 7
app/service/count.js

@@ -1,6 +1,7 @@
 'use strict';
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
+const { ObjectId } = require('mongoose').Types;
 const moment = require('moment');
 const _ = require('lodash');
 
@@ -10,14 +11,15 @@ class CountService extends CrudService {
     super(ctx, 'count');
     this.model = this.ctx.model.Count;
     this.card = this.ctx.model.Card;
+    this.set = this.ctx.model.Set;
     // group,yesterday,week,month查询是否需要详细信息
     this.needDetail = false;
   }
 
   async index(query) {
-    const { id } = query;
-    if (!id) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未接收到用户信息');
-    const user = await this.card.findById(id);
+    const { mobile } = query;
+    if (!mobile) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未接收到用户信息');
+    const user = await this.card.findOne({ mobile });
     const { mobile: r_mobile } = user;
     // 昨日新增
     // day-1 00:00:00 - day-1 23:59:59
@@ -42,11 +44,18 @@ class CountService extends CrudService {
     if (method !== 'count') {
       group = _.groupBy(group, 'set');
       if (!this.needDetail) {
+        const result = {};
         // 如果需要详情,则把下面代码注释
         const keys = Object.keys(group);
+        const setList = await this.set.find({ _id: keys.map(k => ObjectId(k)) });
         for (const key of keys) {
-          group[key] = group[key].length;
+          const res = setList.find(f => ObjectId(f._id).equals(key));
+          if (res) {
+            result[`${res.title}`] = group[key].length;
+
+          }
         }
+        return result;
       }
     }
     return group;
@@ -61,14 +70,21 @@ class CountService extends CrudService {
   async yesterday({ r_mobile, ...info }, method = 'count') {
     let yesterday = await this.card[method]({ r_mobile, ...info, create_time: { $gte: moment().subtract(1, 'days').format('YYYY-MM-DD'), $lte: moment().format('YYYY-MM-DD') } });
     if (method !== 'count') {
+      const result = {};
       yesterday = _.groupBy(yesterday, 'set');
       if (!this.needDetail) {
         // 如果需要详情,则把下面代码注释
         const keys = Object.keys(yesterday);
+        const setList = await this.set.find({ _id: keys.map(k => ObjectId(k)) });
         for (const key of keys) {
-          yesterday[key] = yesterday[key].length;
+          const res = setList.find(f => ObjectId(f._id).equals(key));
+          if (res) {
+            result[`${res.title}`] = yesterday[key].length;
+
+          }
         }
       }
+      return result;
     }
     return yesterday;
   }
@@ -84,14 +100,21 @@ class CountService extends CrudService {
     const we = moment().add(7 - wnum, 'days').format('YYYY-MM-DD');
     let week = await this.card[method]({ r_mobile, ...info, create_time: { $gte: ws, $lte: we } });
     if (method !== 'count') {
+      const result = {};
       week = _.groupBy(week, 'set');
       if (!this.needDetail) {
         // 如果需要详情,则把下面代码注释
         const keys = Object.keys(week);
+        const setList = await this.set.find({ _id: keys.map(k => ObjectId(k)) });
         for (const key of keys) {
-          week[key] = week[key].length;
+          const res = setList.find(f => ObjectId(f._id).equals(key));
+          if (res) {
+            result[`${res.title}`] = week[key].length;
+
+          }
         }
       }
+      return result;
     }
     return week;
   }
@@ -107,14 +130,20 @@ class CountService extends CrudService {
     const me = moment(ms).add(1, 'months').format('YYYY-MM-DD');
     let month = await this.card[method]({ r_mobile, ...info, create_time: { $gte: ms, $lte: me } });
     if (method !== 'count') {
+      const result = {};
       month = _.groupBy(month, 'set');
       if (!this.needDetail) {
         // 如果需要详情,则把下面代码注释
         const keys = Object.keys(month);
+        const setList = await this.set.find({ _id: keys.map(k => ObjectId(k)) });
         for (const key of keys) {
-          month[key] = month[key].length;
+          const res = setList.find(f => ObjectId(f._id).equals(key));
+          if (res) {
+            result[`${res.title}`] = month[key].length;
+          }
         }
       }
+      return result;
     }
     return month;
   }

+ 0 - 2
app/service/set.js

@@ -36,14 +36,12 @@ class SetService extends CrudService {
   async range(condition) {
     const { contact, ...others } = condition;
     assert(contact, '缺少城市范围');
-    console.log(contact);
     if (this.provinceList.includes(contact)) {
       others.contact = contact;
     } else {
       const xzqh = await this.xzqh.find({ pcode: contact });
       others.contact = xzqh.map(i => i.code);
     }
-    console.log(others);
     const res = await this.model.find(others);
     return res;
   }

+ 1 - 2
app/service/util.js

@@ -13,13 +13,12 @@ class UtilService extends CrudService {
     this.set = this.ctx.model.Set;// 套餐
   }
   async utilMethod(query, body) {
-    this.initSetSeed();
+    // this.initSetSeed();
   }
 
   async initSetSeed() {
     let xzqh = await this.xzqh.find({ pcode: { $exists: false } });
     xzqh = JSON.parse(JSON.stringify((xzqh)));
-    console.log(xzqh.length);
     const set169 = code => ({ title: '169套餐', has_group: true, contact: code });
     const set129 = code => ({ title: '129套餐', has_group: false, contact: code });
     const setList = [];