plusstar.js
6.33 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
'use strict';
const _ = require('lodash');
const productProcess = require('../../../utils/product-process');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取潮流优选tab
* @return {[array]}
*/
getAllChannels(params) {
let gender = params.gender - 1 || 0;
return this.get({
data: {
method: 'app.blk.getAllChannels',
app_type: params.app_type
},
api: global.yoho.API,
param: {cache: true}
}).then(result => {
let data = {channel: []};
if (result.code !== 200) {
return data;
}
if (gender === 3 && result.data.length === 3) {
// 1:男,2:女,3:童装,4:创意生活
// 如果为3,说明童装没有配置,只配置了创意生活。所以要减一
gender = 2;
}
_.forEach(result.data, (res, index) => {
data.channel.push({
id: res.channel_id,
mame: res.channel_name,
code: res.content_code,
focus: index === gender ? true : false
});
});
return data;
});
}
/**
* 通过skn查询商品详情
* @param {[string || array]} productSkn 商品skn
* @return {[array]}
*/
getProductBatch(param, options) {
param.productSkn = _.isArray(param.productSkn) ? param.productSkn : [param.productSkn];
return this.get({
data: {
method: 'h5.product.batch',
productSkn: param.productSkn.join(','),
yh_channel: param.yh_channel,
page: param.page,
limit: param.limit
},
api: global.yoho.API,
param: {cache: true}
}).then(result => {
let data = {};
if (result && result.data) {
data = {
page_total: result.data.page_total,
product_list: productProcess.processProductList(result.data.product_list, options)
};
}
return data;
});
}
/**
* 商品推荐获取
* @param {[int]} yh_channel 当前频道
* @param {[int]} uid 用户id
* @return {[array]}
*/
getFashionPrefer(params) {
return this.get({
data: Object.assign({
method: 'h5.product.fashionPrefer'
}, params),
api: global.yoho.API
});
}
/**
* 获取资源位数据
* @param {[string]} content_code
* @return {[array]}
*/
getResources(params, options) {
params = params || {};
if (options.isApp) {
params.platform = 'iphone';
}
return this.get({
url: 'operations/api/v5/resource/get',
data: params,
api: global.yoho.ServiceAPI,
param: {cache: true}
}).then(result => {
let data = {
goods: {},
recommend: {}
};
let list = {};
let productSkns = [];
if (result && result.code !== 200) {
return data;
}
_.forEach(result.data, (res) => {
list = {};
switch (res.template_name) {
case 'focus':
list = {
data: res.data
};
if (res.focus_type * 1 === 1) {
data.focus1 = list;
data.focus1.id = res.template_id;
} else {
data.focus2 = list;
data.focus2.id = res.template_id;
}
break;
case 'title_image' :
if (typeof data[res.template_name] === 'undefined') {
data[res.template_name] = [];
}
list = {
id: res.template_id,
title: res.data.title,
moreUrl: res.data.more_url,
moreName: res.data.more_name,
image: res.data.image
};
data.title_image.push(list);
break;
case 'titleFloor':
list = {
name: res.data.title.name,
moreUrl: res.data.title.more_url,
moreName: res.data.title.more_name
};
if (res.data.title.name === '热门商品') {
data.goods.title = list;
data.goods.id = res.template_id;
} else if (res.data.title.name === '热门品类') {
data.recommend.title = list;
data.recommend.id = res.template_id;
}
break;
case 'recommend_content_five':
data.recommend.data = res.data.list;
break;
case 'goods':
_.forEach(res.data, (skn) => {
productSkns.push(skn.id);
});
data[res.template_name].productSkns = productSkns;
break;
default:
break;
}
});
return data;
});
}
getResourcesData(params, options) {
return Promise.all([
this.getResources(params, options),
this.getFashionPrefer(params)
]).then(result => {
let skns = result[0] && result[0].goods && result[0].goods.productSkns || [];
let preferSkns = result[1] && result[1].data || [];
if (result[0] && result[0].goods && result[0].goods.productSkns) {
result[0].goods.productSkns = _.uniq(skns.concat(preferSkns));
}
return result[0];
});
}
};