lrf 2 년 전
부모
커밋
360668468c
1개의 변경된 파일30개의 추가작업 그리고 0개의 파일을 삭제
  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;