lrf 2 anni fa
parent
commit
360668468c
1 ha cambiato i file con 30 aggiunte e 0 eliminazioni
  1. 30 0
      app/service/view/goods.js

+ 30 - 0
app/service/view/goods.js

@@ -81,6 +81,36 @@ class GoodsService extends CrudService {
     const list = await this.goodsModel.aggregate(pipline);
     return list;
   }
+
+  async indexActTagsGoods() {
+    const dictData = await this.ctx.model.Dev.DictData.find({ code: 'act_tags' });
+    const result = [];
+    for (const t of dictData) {
+      const { label, value } = t;
+      const list = await this.searchActTagsGoods(value);
+      const arr = [];
+      for (const g of list) {
+        const obj = {
+          url: _.get(g, 'file'),
+          name: _.get(g, 'name'),
+        };
+        if (arr.length === 0) {
+          obj.title = label;
+        }
+        arr.push(obj);
+      }
+      result.push({ list: arr });
+    }
+    return result;
+  }
+
+  async searchActTagsGoods(act_tags, limit = 2) {
+    const pipline = [{ $match: { status: { $ne: '0' }, act_tags } }];
+    pipline.push({ $project: { name: 1, file: 1 } });
+    if (parseInt(limit)) pipline.push({ $limit: parseInt(limit) });
+    const list = await this.goodsModel.aggregate(pipline);
+    return list;
+  }
 }
 
 module.exports = GoodsService;