lrf 2 years ago
parent
commit
9bc011b658
1 changed files with 33 additions and 2 deletions
  1. 33 2
      app/service/shop/goodsJoinAct.js

+ 33 - 2
app/service/shop/goodsJoinAct.js

@@ -60,21 +60,52 @@ class GoodsJoinActService extends CrudService {
       pipeline.push({ $match: { 'shopInfo.name': new RegExp(shop_name) } });
     }
     pipeline.push({ $sort: { 'meta.createdAt': -1 } });
+    // 找价格最低的规格的金额
+    pipeline.push({
+      $lookup: {
+        from: 'goodsSpec',
+        localField: 'goods',
+        foreignField: 'goods',
+        pipeline: [
+          {
+            $group: {
+              _id: '$goods',
+              data: { $min: '$$CURRENT' },
+            },
+          },
+          { $project: { name: '$data.name', file: '$data.file', sell_money: '$data.sell_money' } },
+        ],
+        as: 'specInfo',
+      },
+    });
+    pipeline.push({ $unwind: '$specInfo' });
     pipeline.push({
       $project: {
-        statsu: 1,
         platformAct: 1,
         shop: '$shopInfo',
         goods: '$goodsInfo',
+        sell_money: { $toString: '$specInfo.sell_money' },
+        spec_file: '$specInfo.file',
       },
     });
     const qPipeline = _.cloneDeep(pipeline);
     if (parseInt(skip)) qPipeline.push({ $skip: parseInt(skip) });
     if (parseInt(limit)) qPipeline.push({ $limit: parseInt(limit) });
-    const list = await this.model.aggregate(qPipeline);
+    const res = await this.model.aggregate(qPipeline);
     const tPipeline = _.cloneDeep(pipeline);
     tPipeline.push({ $count: 'total' });
     const total = await this.model.aggregate(tPipeline);
+    // 整理图片
+    const list = [];
+    for (const r of res) {
+      const i = _.cloneDeep(r);
+      const { spec_file = [] } = i;
+      const goods_file = _.get(r, 'goods.file', []);
+      const nf = [ ...spec_file, ...goods_file ];
+      delete i.spec_file;
+      i.goods.file = nf;
+      list.push(i);
+    }
     return { data: list, total: _.get(_.head(total), 'total', 0) };
   }
 }