|
@@ -63,7 +63,9 @@ class GoodsService extends CrudService {
|
|
|
// 格式化平铺后的数据
|
|
|
// 2022-10-17反馈-问题6:将规格图片也拿出来
|
|
|
// TODO: 整理规格图片与正常的商品图片
|
|
|
- pipline.push({ $project: { name: 1, view_num: 1, sell_num: 1, file: 1, sell_money: { $toDouble: '$specs.sell_money' }, createdAt: '$meta.createdAt' }, spec_file: '$specs.file' });
|
|
|
+ pipline.push({
|
|
|
+ $project: { name: 1, view_num: 1, sell_num: 1, file: 1, sell_money: { $toDouble: '$specs.sell_money' }, createdAt: '$meta.createdAt', spec_file: '$specs.file' },
|
|
|
+ });
|
|
|
pipline.push({
|
|
|
$group: {
|
|
|
_id: '$_id',
|
|
@@ -72,7 +74,7 @@ class GoodsService extends CrudService {
|
|
|
sell_num: { $first: '$sell_num' },
|
|
|
sell_money: { $min: '$sell_money' },
|
|
|
file: { $first: '$file' },
|
|
|
- spec_file: { $first: 'spec_file' },
|
|
|
+ spec_file: { $first: '$spec_file' },
|
|
|
createdAt: { $first: '$createdAt' },
|
|
|
},
|
|
|
});
|
|
@@ -85,7 +87,14 @@ class GoodsService extends CrudService {
|
|
|
qPipline.push({ $sort: { createdAt: -1 } });
|
|
|
if (parseInt(skip)) qPipline.push({ $skip: parseInt(skip) });
|
|
|
if (parseInt(limit)) qPipline.push({ $limit: parseInt(limit) });
|
|
|
- const list = await this.goodsModel.aggregate(qPipline);
|
|
|
+ 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 tPipline = _.cloneDeep(pipline);
|
|
|
tPipline.push({ $count: 'total' });
|
|
|
const total = await this.goodsModel.aggregate(tPipline);
|