lrf 2 years ago
parent
commit
1fae115284
2 changed files with 13 additions and 22 deletions
  1. 11 11
      app/service/shop/goodsJoinAct.js
  2. 2 11
      app/service/view/goods.js

+ 11 - 11
app/service/shop/goodsJoinAct.js

@@ -96,17 +96,17 @@ class GoodsJoinActService extends CrudService {
     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) };
+    // 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: res, total: _.get(_.head(total), 'total', 0) };
   }
 }
 

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

@@ -103,22 +103,13 @@ class GoodsService extends CrudService {
         sort: '$data.sort',
       },
     });
-    sort.sort = 1;
-    sort = { ...sort, sort: 1, create_time: -1 };
+    if (Object.keys(sort).length <= 0) sort = { sort: -1, create_time: -1 };
     pipline.push({ $sort: sort });
     // 分页处理
     const qPipline = _.cloneDeep(pipline);
     if (parseInt(skip)) qPipline.push({ $skip: parseInt(skip) });
     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 ];
-        delete i.spec_file;
-      }
-      return i;
-    });
+    const list = await this.goodsModel.aggregate(qPipline);
     const tPipline = _.cloneDeep(pipline);
     tPipline.push({ $count: 'total' });
     const total = await this.goodsModel.aggregate(tPipline);