lrf402788946 пре 4 година
родитељ
комит
a51691b597
3 измењених фајлова са 32 додато и 0 уклоњено
  1. 4 0
      app/controller/home.js
  2. 1 0
      app/router.js
  3. 27 0
      app/service/users/product.js

+ 4 - 0
app/controller/home.js

@@ -11,6 +11,10 @@ class HomeController extends Controller {
     const data = await this.ctx.service.util.util.utilMethod(this.ctx.query, this.ctx.request.body);
     this.ctx.ok({ data });
   }
+  async indexQuery() {
+    const data = await this.ctx.service.users.product.indexQuery();
+    this.ctx.ok({ data });
+  }
 }
 
 module.exports = HomeController;

+ 1 - 0
app/router.js

@@ -9,6 +9,7 @@ module.exports = app => {
   const profix = '/api/live/';
   const vision = 'v0';
   router.post(`${profix}${vision}/util`, controller.home.utilMethod);
+  router.get(`${profix}${vision}/index`, controller.home.indexQuery);
   require('./router/users/admin')(app); // 管理员
   require('./router/users/personal')(app); // 个人用户
   require('./router/users/organization')(app); // 机构用户

+ 27 - 0
app/service/users/product.js

@@ -6,6 +6,8 @@ class ProductService extends CrudService {
   constructor(ctx) {
     super(ctx, 'product');
     this.model = this.ctx.model.Product;
+    this.patent = this.ctx.model.Patent;
+    this.roadShow = this.ctx.model.RoadShow;
     this.personal = this.ctx.model.Personal;
     this.expert = this.ctx.model.Expert;
     this.organization = this.ctx.model.Organization;
@@ -45,6 +47,31 @@ class ProductService extends CrudService {
     }
     return { data: res, total };
   }
+
+  async indexQuery() {
+    // product,limit=>6;status=>2;type=>0/1/2
+    // 科技需求
+    const require = await this.getSample('model', 6, { type: '0', status: '2' });
+    // 技术成果
+    const achieve = await this.getSample('model', 6, { type: '1', status: '2' });
+    // 商务服务
+    const serve = await this.getSample('model', 6, { type: '2', status: '2' });
+    // 专利:patent limit=>6
+    const patent = await this.getSample('patent');
+    // 专家:expert:limit=>8
+    const expert = await this.getSample('expert', 8);
+    // 路演:roadShow:limit=>5
+    const roadShow = await this.getSample('roadShow', 5);
+    return { require, achieve, serve, patent, expert, roadShow };
+  }
+
+  async getSample(model, limit = 6, match = {}) {
+    const res = await this[model].aggregate([
+      { $match: match },
+      { $sample: { size: parseInt(limit) } },
+    ]);
+    return res;
+  }
 }
 
 module.exports = ProductService;