lrf 2 tahun lalu
induk
melakukan
405bc0c5ea
2 mengubah file dengan 10 tambahan dan 1 penghapusan
  1. 1 0
      app/controller/shop/config/.goods.js
  2. 9 1
      app/service/shop/goods.js

+ 1 - 0
app/controller/shop/config/.goods.js

@@ -25,6 +25,7 @@ module.exports = {
         name: 'name',
         status: 'status',
         view_num: 'view_num',
+        tags: 'tags',
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 9 - 1
app/service/shop/goods.js

@@ -4,12 +4,20 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
 
-// 
+//
 class GoodsService extends CrudService {
   constructor(ctx) {
     super(ctx, 'goods');
     this.model = this.ctx.model.Shop.Goods;
   }
+  // 标签查询
+  async beforeQuery(filter) {
+    const { tags } = filter;
+    if (tags) {
+      filter.tags = { $elemMatch: { $elemMatch: { $eq: tags } } };
+    }
+    return filter;
+  }
 }
 
 module.exports = GoodsService;