|
@@ -77,12 +77,15 @@ class GoodsService extends CrudService {
|
|
if (sell_num) pipline.push({ $sort: { sell_num } });
|
|
if (sell_num) pipline.push({ $sort: { sell_num } });
|
|
if (sell_money) pipline.push({ $sort: { sell_money } });
|
|
if (sell_money) pipline.push({ $sort: { sell_money } });
|
|
// 分页处理
|
|
// 分页处理
|
|
- if (parseInt(skip)) pipline.push({ $skip: parseInt(skip) });
|
|
|
|
- if (parseInt(limit)) pipline.push({ $limit: parseInt(limit) });
|
|
|
|
- pipline.push({ $sort: { createdAt: -1 } });
|
|
|
|
- const list = await this.goodsModel.aggregate(pipline);
|
|
|
|
- const total = await this.goodsModel.count();
|
|
|
|
- return { list, total };
|
|
|
|
|
|
+ const qPipline = _.cloneDeep(pipline);
|
|
|
|
+ if (parseInt(skip)) qPipline.push({ $skip: parseInt(skip) });
|
|
|
|
+ if (parseInt(limit)) qPipline.push({ $limit: parseInt(limit) });
|
|
|
|
+ qPipline.push({ $sort: { createdAt: -1 } });
|
|
|
|
+ const list = await this.goodsModel.aggregate(qPipline);
|
|
|
|
+ const tPipline = _.cloneDeep(pipline);
|
|
|
|
+ tPipline.push({ $count: 'total' });
|
|
|
|
+ const total = await this.goodsModel.aggregate(tPipline);
|
|
|
|
+ return { list, total: _.get(_.head(total), 'total', 0) };
|
|
}
|
|
}
|
|
|
|
|
|
async indexActTagsGoods() {
|
|
async indexActTagsGoods() {
|