lrf před 2 roky
rodič
revize
66cfea286b
1 změnil soubory, kde provedl 11 přidání a 1 odebrání
  1. 11 1
      app/service/trade/orderDetail.js

+ 11 - 1
app/service/trade/orderDetail.js

@@ -131,7 +131,6 @@ class OrderDetailService extends CrudService {
     return res;
   }
 
-
   async query(filter, { skip = 0, limit, sort, desc, projection } = {}) {
     // 处理排序
     if (sort && _.isString(sort)) {
@@ -230,6 +229,17 @@ class OrderDetailService extends CrudService {
 
     return list;
   }
+
+  async count(filter) {
+    let condition = _.cloneDeep(filter);
+    condition = await this.beforeQuery(condition);
+    condition = this.dealFilter(condition);
+    const pipline = [{ $project: { _id: 1, id: { $toString: '$_id' } } }, { $sort: { 'meta.createdAt': -1 } }];
+    pipline.push({ $match: condition });
+    pipline.push({ $count: 'id' });
+    const rs = await this.model.aggregate(pipline);
+    return _.get(_.head(rs), 'id');
+  }
 }
 
 module.exports = OrderDetailService;