recent-view.js
1.75 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* recent view model
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/10/11
*/
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const helper = global.yoho.helpers;
const index = (skn, limit) => {
return api.get('', {
method: 'h5.product.batch',
productSkn: skn,
limit: limit
}).then(result => {
if (result.code === 200) {
let data = [];
let historyProduct = result.data.product_list;
_.forEach(historyProduct, hp => {
if (!hp) {
return;
}
let mp = hp.market_price;
let sp = hp.sales_price;
let defaultGoods = _.find(hp.goods_list, {is_default: 'Y'});
// 无默认商品取商品列表第一个
if (!defaultGoods) {
defaultGoods = hp.goods_list[0];
}
data.push({
market_price: mp === sp ? '' : `¥${helper.round(mp, 2)}`,
price: `¥${helper.round(sp, 2)}`,
product_name: hp.product_name,
url: helper.urlFormat(
`/product/pro_${hp.product_id}_${defaultGoods.goods_id}/${hp.cn_alphabet}.html`, null, 'item'),
pic_url: helper.image(defaultGoods.images_url, 280, 382, 2, 70)
});
});
return {
code: 200,
data: data,
message: result.message
};
} else {
// get list error
return {
code: result.code,
message: result.message,
data: []
};
}
});
};
module.exports = {
index
};