newsale.js
3.38 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const serviceAPI = global.yoho.ServiceAPI;
const logger = global.yoho.logger;
const getHotRank = (codeKey) => {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: codeKey
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
let formData = {};
if (result.data[0].data.length === 1) {
formData.url = result.data[0].data[0].url;
formData.img = result.data[0].data[0].src;
} else {
let list = [];
_.forEach(result.data[0].data, function(val) {
list.push({
url: val.url,
img: val.src
});
});
formData.list = list;
}
return formData;
} else {
logger.error('getHotRank data return code is not 200');
return {};
}
});
};
const selectHotrank = (yhChannel, gender, sort, tabId, limit, page, notab) => {
let param = {
method: 'app.search.top',
gender: gender,
yh_channel: yhChannel,
page: page,
limit: limit
};
if (sort) {
param.sort = sort;
}
if (tabId) {
param.tab_id = tabId;
}
return api.get('', param, {
cache: true
}).then((result) => {
if (result && result.code === 200 && result.data.product_list) {
let formData = {};
if (notab && parseInt(notab, 10) === 0 && result.data.tabs) {
let tabs = [];
_.forEach(result.data.tabs, function(val, index) {
let obj = {};
if (index === 0) {
obj = _.assign(obj, {
focus: true
});
}
obj = _.assign(obj, {
title: val,
dataId: index
});
tabs.push(obj);
});
formData.tabs = tabs;
}
if (result.data.product_list && result.data.product_list.length !== 0) {
let goods = [];
_.forEach(result.data.product_list, function(data, index) {
let one = {};
if (data === null || !data.product_skn || !data.goods_list[0]) {
return false;
}
one = _.assign(one, {
url: '/product/pro_' + data.product_id + '_' + data.goods_list[0].goods_id +
'/' + data.cn_alphabet + '.html',
thumb: data.default_images,
rank: limit * (page - 1) + index + 1,
name: data.product_name,
salePrice: data.sales_price
});
if (data.sales_phrase) {
one = _.assign(one, {
sales_phrase: data.sales_phrase
});
}
goods.push(one);
});
formData.goods = goods;
}
return formData;
}
});
};
module.exports = {
getHotRank,
selectHotrank
};