lrf 2 anni fa
parent
commit
9c0e554f5c
1 ha cambiato i file con 11 aggiunte e 2 eliminazioni
  1. 11 2
      app/service/view/goods.js

+ 11 - 2
app/service/view/goods.js

@@ -100,10 +100,11 @@ class GoodsService extends CrudService {
         name: '$data.name',
         view_num: '$data.view_num',
         sell_num: '$data.sell_num',
+        file: '$data.file',
         sell_money: '$data.sell_money',
         flow_money: '$data.flow_money',
         createdAt: '$data.createdAt',
-        file: { $concatArrays: [ '$data.spec_file', '$data.file' ] },
+        spec_file: '$data.spec_file',
       },
     });
     sort.sort = 1;
@@ -112,7 +113,15 @@ class GoodsService extends CrudService {
     const qPipline = _.cloneDeep(pipline);
     if (parseInt(skip)) qPipline.push({ $skip: parseInt(skip) });
     if (parseInt(limit)) qPipline.push({ $limit: parseInt(limit) });
-    const list = await this.goodsModel.aggregate(qPipline);
+    let list = await this.goodsModel.aggregate(qPipline);
+    // 处理合并图片
+    list = list.map(i => {
+      if (_.isArray(i.spec_file)) {
+        i.file = [ ...i.spec_file, ...i.file ];
+        delete i.spec_file;
+      }
+      return i;
+    });
     const tPipline = _.cloneDeep(pipline);
     tPipline.push({ $count: 'total' });
     const total = await this.goodsModel.aggregate(tPipline);