|
@@ -84,13 +84,26 @@ class GoodsService extends CrudService {
|
|
|
pipline.push({
|
|
|
$group: {
|
|
|
_id: '$_id',
|
|
|
- name: { $first: '$name' },
|
|
|
- view_num: { $first: '$view_num' },
|
|
|
- sell_num: { $first: '$sell_num' },
|
|
|
- sell_money: { $min: '$sell_money' },
|
|
|
- file: { $first: '$file' },
|
|
|
- spec_file: { $first: '$spec_file' },
|
|
|
- createdAt: { $first: '$createdAt' },
|
|
|
+ data: { $min: '$$CURRENT' },
|
|
|
+ // name: { $first: '$name' },
|
|
|
+ // view_num: { $first: '$view_num' },
|
|
|
+ // sell_num: { $first: '$sell_num' },
|
|
|
+ // sell_money: { $min: '$sell_money' },
|
|
|
+ // flow_money: { $first: '$flow_money' },
|
|
|
+ // file: { $first: '$file' },
|
|
|
+ // spec_file: { $first: '$spec_file' },
|
|
|
+ // createdAt: { $first: '$createdAt' },
|
|
|
+ },
|
|
|
+ });
|
|
|
+ pipline.push({
|
|
|
+ $project: {
|
|
|
+ name: '$data.name',
|
|
|
+ view_num: '$data.view_num',
|
|
|
+ sell_num: '$data.sell_num',
|
|
|
+ sell_money: '$data.sell_money',
|
|
|
+ flow_money: '$data.flow_money',
|
|
|
+ createdAt: '$data.createdAt',
|
|
|
+ file: { $concatArrays: [ '$data.spec_file', '$data.file' ] },
|
|
|
},
|
|
|
});
|
|
|
sort.sort = 1;
|
|
@@ -99,14 +112,7 @@ class GoodsService extends CrudService {
|
|
|
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 ];
|
|
|
- }
|
|
|
- return i;
|
|
|
- });
|
|
|
+ const list = await this.goodsModel.aggregate(qPipline);
|
|
|
const tPipline = _.cloneDeep(pipline);
|
|
|
tPipline.push({ $count: 'total' });
|
|
|
const total = await this.goodsModel.aggregate(tPipline);
|