preference.js
1.53 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
/*
* @Author: Targaryen
* @Date: 2016-05-18 11:42:11
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-30 13:48:17
*/
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const yhchannelMap = {
boys: '1',
girls: '2',
kids: '3',
lifestyle: '4'
};
const _formatProduct = (data) => {
let list = [];
_.forEach(data, function(value) {
if (!value.product_skn || !value.goods_list || !value.goods_list.length) {
return;
}
value.goodsId = value.goods_list[0].goods_id;
let goods = {
salePrice: value.sales_price ? value.sales_price : '',
price: value.market_price ? value.market_price : '',
url: helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`),
thumb: value.default_images,
name: value.product_name
};
// 市场价和售价一样,则不显示市场价
if (goods.salePrice === goods.price) {
goods.price = false;
}
list.push(goods);
});
return list;
};
module.exports = (data) => {
let finalResult = {};
return api.get('', {
method: 'h5.preference.Search',
productskn: data.productskn,
yhchannel: yhchannelMap[data.yhchannel],
brandId: data.brandId
}).then(result => {
if (result) {
finalResult.recommendList = _formatProduct(result);
}
return finalResult;
});
};