im.js
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const _ = require('lodash');
/**
* im 接口数据的 处理
*/
/**
* function: 处理 订单返回的数据
*/
exports.handleOrderList = (data, w, h) => {
if (_.isEmpty(data)) {
return;
}
function replaceWH(img) {
return img.replace(/(^https?:|\{width\}|\{height\})/g, function($0) {
const dict = {
'{width}': w,
'{height}': h,
'http:': '',
'https:': ''
};
return dict[$0];
});
}
data.forEach(order => {
order.goods = order.ordersGoodsBoList.map(good => {
return {
id: good.productSku,
name: good.productName,
thumb: replaceWH(good.imgUrl),
color: good.colorName,
size: good.sizeName,
count: good.buyNumber,
price: good.lastPrice,
tariffPrice: good.tariffPrice
};
});
order.count = order.ordersGoodsBoList.reduce((sum, good) => {
return sum + good.buyNumber;
}, 0);
});
};