lrf 2 năm trước cách đây
mục cha
commit
dbd1101f60
3 tập tin đã thay đổi với 26 bổ sung3 xóa
  1. 3 3
      app/service/system/goodsTags.js
  2. 20 0
      app/service/view/goods.js
  3. 3 0
      config/config.default.js

+ 3 - 3
app/service/system/goodsTags.js

@@ -26,13 +26,13 @@ class GoodsTagsService extends CrudService {
   async tree({ pid }) {
     let list = await this.model.find({ status: '0' });
     list = JSON.parse(JSON.stringify(list));
-    list = list.map((i) => _.omit(i, ['meta', '__v']));
-    const level1 = list.filter((f) => (pid ? f.id === pid : !f.pid));
+    list = list.map(i => _.omit(i, [ 'meta', '__v' ]));
+    const level1 = list.filter(f => (pid ? f.id === pid : !f.pid));
     const loop = (list, parents) => {
       for (const p of parents) {
         const pid = _.get(p, '_id');
         if (!pid) continue;
-        const children = list.filter((f) => ObjectId(pid).equals(f.pid));
+        const children = list.filter(f => ObjectId(pid).equals(f.pid));
         if (children.length <= 0) continue;
         const newChildren = loop(list, children);
         p.children = newChildren;

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

@@ -12,6 +12,7 @@ class GoodsService extends CrudService {
     this.goodsModel = this.ctx.model.Shop.Goods;
     this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
     this.gjaModel = this.ctx.model.Shop.GoodsJoinAct;
+    this.goodsTagsModel = this.ctx.model.System.GoodsTags;
   }
   /**
    *
@@ -22,6 +23,16 @@ class GoodsService extends CrudService {
     assert(id, '缺少商品信息');
     const pipeline = [{ $match: { _id: ObjectId(id) } }];
     const goodsProject = { file: 1, tags: 1, name: 1, shot_brief: 1, brief: 1, send_time: 1, shop: 1, view_num: 1, act_tags: 1 };
+    // 将 活动标签都进行数据替换
+    pipeline.push({
+      $lookup: {
+        from: 'actTags',
+        localField: 'act_tags',
+        foreignField: 'value',
+        pipeline: [{ $project: { label: 1 } }],
+        as: 'act_tags',
+      },
+    });
     // 找店铺信息
     pipeline.push({ $addFields: { shop_id: { $toObjectId: '$shop' } } });
     pipeline.push({
@@ -119,6 +130,15 @@ class GoodsService extends CrudService {
     const res = await this.goodsModel.aggregate(pipeline);
     let data = _.head(res);
     if (data) data = JSON.parse(JSON.stringify(data));
+    if (data.goods.tags.length > 0) {
+      const nt = [];
+      for (const t of data.goods.tags) {
+        const code = _.last(t);
+        const data = await this.goodsTagsModel.findOne({ code }, 'label');
+        nt.push(data);
+      }
+      data.goods.tags = nt;
+    }
     for (const d of data.act) {
       const { tag, text } = this.ctx.service.system.platformAct.getActText(d);
       d.text = text;

+ 3 - 0
config/config.default.js

@@ -115,6 +115,9 @@ module.exports = appInfo => {
     groupJoinRefund: -111,
   };
   config.wxPayConfig = 'tehqApp';
+  config.logger = {
+    level: 'NONE',
+  };
   return {
     ...config,
     ...userConfig,