lrf 2 rokov pred
rodič
commit
822699e1e2
1 zmenil súbory, kde vykonal 21 pridanie a 15 odobranie
  1. 21 15
      app/service/view/goods.js

+ 21 - 15
app/service/view/goods.js

@@ -84,13 +84,26 @@ class GoodsService extends CrudService {
     pipline.push({
     pipline.push({
       $group: {
       $group: {
         _id: '$_id',
         _id: '$_id',
-        name: { $first: '$name' },
-        view_num: { $first: '$view_num' },
-        sell_num: { $first: '$sell_num' },
-        sell_money: { $min: '$sell_money' },
-        file: { $first: '$file' },
-        spec_file: { $first: '$spec_file' },
-        createdAt: { $first: '$createdAt' },
+        data: { $min: '$$CURRENT' },
+        // name: { $first: '$name' },
+        // view_num: { $first: '$view_num' },
+        // sell_num: { $first: '$sell_num' },
+        // sell_money: { $min: '$sell_money' },
+        // flow_money: { $first: '$flow_money' },
+        // file: { $first: '$file' },
+        // spec_file: { $first: '$spec_file' },
+        // createdAt: { $first: '$createdAt' },
+      },
+    });
+    pipline.push({
+      $project: {
+        name: '$data.name',
+        view_num: '$data.view_num',
+        sell_num: '$data.sell_num',
+        sell_money: '$data.sell_money',
+        flow_money: '$data.flow_money',
+        createdAt: '$data.createdAt',
+        file: { $concatArrays: [ '$data.spec_file', '$data.file' ] },
       },
       },
     });
     });
     sort.sort = 1;
     sort.sort = 1;
@@ -99,14 +112,7 @@ class GoodsService extends CrudService {
     const qPipline = _.cloneDeep(pipline);
     const qPipline = _.cloneDeep(pipline);
     if (parseInt(skip)) qPipline.push({ $skip: parseInt(skip) });
     if (parseInt(skip)) qPipline.push({ $skip: parseInt(skip) });
     if (parseInt(limit)) qPipline.push({ $limit: parseInt(limit) });
     if (parseInt(limit)) qPipline.push({ $limit: parseInt(limit) });
-    let list = await this.goodsModel.aggregate(qPipline);
-    // 处理合并图片
-    list = list.map(i => {
-      if (_.isArray(i.spec_file)) {
-        i.file = [ ...i.spec_file, ...i.file ];
-      }
-      return i;
-    });
+    const list = await this.goodsModel.aggregate(qPipline);
     const tPipline = _.cloneDeep(pipline);
     const tPipline = _.cloneDeep(pipline);
     tPipline.push({ $count: 'total' });
     tPipline.push({ $count: 'total' });
     const total = await this.goodsModel.aggregate(tPipline);
     const total = await this.goodsModel.aggregate(tPipline);