|
@@ -45,16 +45,15 @@ class GoodsService extends CrudService {
|
|
|
|
|
|
async indexGoodsList(condition, { skip = 0, limit = 20 } = {}) {
|
|
async indexGoodsList(condition, { skip = 0, limit = 20 } = {}) {
|
|
condition = this.dealFilter(condition);
|
|
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 { view_num, sell_num, sell_money, name, shop, tags } = condition;
|
|
const sort = {};
|
|
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 (name) pipline.push({ $match: { name: new RegExp(name) } });
|
|
if (shop) pipline.push({ $match: { shop } });
|
|
if (shop) pipline.push({ $match: { shop } });
|
|
if (tags) pipline.push({ $match: { tags: { $elemMatch: { $elemMatch: { $eq: tags } } } } });
|
|
if (tags) pipline.push({ $match: { tags: { $elemMatch: { $elemMatch: { $eq: tags } } } } });
|
|
-
|
|
|
|
pipline.push({ $addFields: { goods_id: { $toString: '$_id' } } });
|
|
pipline.push({ $addFields: { goods_id: { $toString: '$_id' } } });
|
|
// 表关联
|
|
// 表关联
|
|
pipline.push({
|
|
pipline.push({
|
|
@@ -85,13 +84,10 @@ class GoodsService extends CrudService {
|
|
createdAt: { $first: '$createdAt' },
|
|
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);
|
|
const qPipline = _.cloneDeep(pipline);
|
|
- qPipline.push({ $sort: { createdAt: -1 } });
|
|
|
|
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);
|
|
let list = await this.goodsModel.aggregate(qPipline);
|