lrf 2 년 전
부모
커밋
c4633f6c9e
3개의 변경된 파일8개의 추가작업 그리고 16개의 파일을 삭제
  1. 1 1
      app/controller/trade/config/.orderDetail.js
  2. 6 14
      app/service/trade/orderDetail.js
  3. 1 1
      app/z_router/trade/orderDetail.js

+ 1 - 1
app/controller/trade/config/.orderDetail.js

@@ -43,7 +43,7 @@ module.exports = {
       query: ['skip', 'limit'],
       sort: ['meta.createdAt'],
       desc: true,
-      count: true,
+      count: false,
     },
   },
   sot: {

+ 6 - 14
app/service/trade/orderDetail.js

@@ -203,6 +203,11 @@ class OrderDetailService extends CrudService {
     if (parseInt(skip) >= 0) qPipline.push({ $skip: parseInt(skip) });
     if (parseInt(limit)) qPipline.push({ $limit: parseInt(limit) });
     const rs = await this.model.aggregate(qPipline);
+    const tPipline = _.cloneDeep(pipline);
+    tPipline.push({ $addFields: { id: { $toString: '$_id' } } });
+    tPipline.push({ $count: 'id' });
+    const t = await this.model.aggregate(tPipline);
+    const total = _.get(_.head(t), 'id');
     const list = [];
     for (const i of rs) {
       const { goods } = i;
@@ -226,22 +231,9 @@ class OrderDetailService extends CrudService {
       obj.is_afterSale = asum > 0;
       list.push(obj);
     }
-
-    return list;
+    return { data: list, total };
   }
 
-  async count(filter) {
-    let condition = _.cloneDeep(filter);
-    condition = await this.beforeQuery(condition);
-    condition = this.dealFilter(condition);
-    console.log(condition);
-    const pipline = [{ $sort: { 'meta.createdAt': -1 } }];
-    pipline.push({ $match: condition });
-    pipline.push({ $project: { _id: 1, id: { $toString: '$_id' } } });
-    pipline.push({ $count: 'id' });
-    const rs = await this.model.aggregate(pipline);
-    return _.get(_.head(rs), 'id');
-  }
 }
 
 module.exports = OrderDetailService;

+ 1 - 1
app/z_router/trade/orderDetail.js

@@ -8,7 +8,7 @@ const ckey = 'trade.orderDetail';
 const keyZh = '订单详情';
 const routes = [
   { method: 'get', path: `${rkey}/sot/:id`, controller: `${ckey}.sot`, name: `${ckey}sot`, zh: `${keyZh}查询物流` },
-  { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
+  { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, middleware: [ 'dealQuery' ], name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
   { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },