liuyu 5 年之前
父節點
當前提交
f28fee5bb5
共有 3 個文件被更改,包括 28 次插入0 次删除
  1. 5 0
      app/controller/product.js
  2. 1 0
      app/router.js
  3. 22 0
      app/service/product.js

+ 5 - 0
app/controller/product.js

@@ -21,6 +21,11 @@ class ProductController extends Controller {
     const res = await this.service.newquery(this.ctx.query);
     this.ctx.ok({ ...res });
   }
+
+  async allquery() {
+    const res = await this.service.allquery(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
 }
 
 module.exports = CrudController(ProductController, meta);

+ 1 - 0
app/router.js

@@ -22,6 +22,7 @@ module.exports = app => {
   router.post('expertsaudit', '/api/market/expertsaudit/update/:id', controller.expertsaudit.update);
 
   // 产品信息表设置路由
+  router.get('product', '/api/market/product/allquery', controller.product.allquery);
   router.get('product', '/api/market/product/newquery', controller.product.newquery);
   router.get('product', '/api/market/product/newfetch/:id', controller.product.newfetch);
   router.resources('product', '/api/market/product', controller.product); // index、create、show、destroy

+ 22 - 0
app/service/product.js

@@ -39,6 +39,28 @@ class ProductService extends CrudService {
     }
     return { data, total: products.length };
   }
+
+  // 根据uid查询所有子id下的所有产品
+  async allquery(data) {
+    const { uid } = data;
+    assert(uid, '缺少参数');
+    const url = this.ctx.app.config.axios.auth.baseUrl + '?pid=' + uid + '&skip=0&limit=9999';
+    const res = await this.ctx.curl(url, {
+      method: 'get',
+      headers: {
+        'content-type': 'application/json',
+      },
+      dataType: 'json',
+    });
+    const result = [];
+    for (const elm of res.data.data) {
+      const datas = await this.model.find({ userid: elm.uid });
+      for (const el of datas) {
+        result.push(el);
+      }
+    }
+    return result;
+  }
 }
 
 module.exports = ProductService;