lrf402788946 4 年 前
コミット
58587bc6f5

+ 2 - 0
app/controller/dock/.transaction.js

@@ -48,6 +48,8 @@ module.exports = {
         demander: "demander",
         product_id: "product_id",
         product: "%product%",
+        user_id: "user_id",
+        status: "status",
         "create_time@start": "create_time@start",
         "create_time@end": "create_time@end",
       },

+ 16 - 0
app/service/dock/transaction.js

@@ -12,6 +12,22 @@ class TransactionService extends CrudService {
     this.model = this.ctx.model.Transaction;
   }
 
+  async query(query, { skip = 0, limit = 0 } = {}) {
+    query = this.ctx.service.util.util.dealQuery(query);
+    const { user_id, supplier, demander, status, ...info } = query;
+    query.status = status.split(',');
+    let res;
+    if (!user_id) {
+      res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
+        .sort({ 'meta.createdAt': -1 });
+    } else {
+      const nquery = { ...info, $or: [{ supplier: user_id }, { demander: user_id }] };
+      res = await this.model.find(nquery).skip(parseInt(skip)).limit(parseInt(limit))
+        .sort({ 'meta.createdAt': -1 });
+    }
+    return res;
+  }
+
   /**
    *  审核交易
    * @param {Object} { id } 交易数据的id

+ 6 - 1
app/service/util/util.js

@@ -21,12 +21,17 @@ class UtilService extends CrudService {
     ]);
     return res;
   }
+
+  dealQuery(query) {
+    return this.turnFilter(this.turnDateRangeQuery(query));
+  }
+
   /**
    * 将查询条件中模糊查询的标识转换成对应object
    * @param {Object} filter 查询条件
    */
   turnFilter(filter) {
-    const str = /^%\w*%$/;
+    const str = /^%\S*%$/;
     const keys = Object.keys(filter);
     for (const key of keys) {
       const res = key.match(str);