lrf před 2 roky
rodič
revize
b7ce834d3d
1 změnil soubory, kde provedl 6 přidání a 10 odebrání
  1. 6 10
      app/service/view/goods.js

+ 6 - 10
app/service/view/goods.js

@@ -45,16 +45,15 @@ class GoodsService extends CrudService {
 
   async indexGoodsList(condition, { skip = 0, limit = 20 } = {}) {
     condition = this.dealFilter(condition);
-    const pipline = [{ $sort: { sort: 1 } }, { $match: { status: { $ne: '0' } } }];
+    const pipline = [{ $match: { status: { $ne: '0' } } }]; // { $sort: { sort: 1 } },
     const { view_num, sell_num, sell_money, name, shop, tags } = condition;
     const sort = {};
-    if (view_num) sort.view_num = view_num;
-    if (sell_num) sort.sell_num = sell_num;
-    if (sell_money) sort.sell_money = sell_money;
+    if (view_num) sort.view_num = parseInt(view_num);
+    if (sell_num) sort.sell_num = parseInt(sell_num);
+    if (sell_money) sort.sell_money = parseInt(sell_money);
     if (name) pipline.push({ $match: { name: new RegExp(name) } });
     if (shop) pipline.push({ $match: { shop } });
     if (tags) pipline.push({ $match: { tags: { $elemMatch: { $elemMatch: { $eq: tags } } } } });
-
     pipline.push({ $addFields: { goods_id: { $toString: '$_id' } } });
     // 表关联
     pipline.push({
@@ -85,13 +84,10 @@ class GoodsService extends CrudService {
         createdAt: { $first: '$createdAt' },
       },
     });
-    // 排序处理
-    if (view_num) pipline.push({ $sort: { view_num } });
-    if (sell_num) pipline.push({ $sort: { sell_num } });
-    if (sell_money) pipline.push({ $sort: { sell_money } });
+    sort.sort = 1;
+    pipline.push({ $sort: sort });
     // 分页处理
     const qPipline = _.cloneDeep(pipline);
-    qPipline.push({ $sort: { createdAt: -1 } });
     if (parseInt(skip)) qPipline.push({ $skip: parseInt(skip) });
     if (parseInt(limit)) qPipline.push({ $limit: parseInt(limit) });
     let list = await this.goodsModel.aggregate(qPipline);