search-process.js
10.9 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/**
* 搜索相关数据处理
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/7/29
*/
const logger = global.yoho.logger;
const _ = require('lodash');
/**
* 根据频道判断出性别
*/
const getGenderByChannel = (channel) => {
channel = channel ? channel : 'boys';
switch (channel) {
case 'boys': // 男
return '1,3';
case 'girls': // 女
return '2,3';
default: // 其它
return '1,2,3';
}
};
/**
* seo 获取性别
*/
const _getGenderForSeo = (gender) => {
let seoGender = '男生|女生';
switch (gender) {
case '1,3':
seoGender = '男生';
break;
case '2,3':
seoGender = '女生';
break;
default:
break;
}
return seoGender;
};
// 频道转换
const getChannelType = (channel) => {
channel = channel ? channel : 'boys';
switch (channel) {
case 'boys': // 男
return '1';
case 'girls': // 女
return '2';
case 'kids': // 童装
return '3';
case 'lifestyle': // 创意生活
return '4';
default: // all
return '1,2,3,4';
}
};
// 排序转换
const getTypeCont = (type, order) => {
switch (type) {
case 'price':
return order === '0' ? 's_p_desc' : 's_p_asc';
case 'discount':
return order === '0' ? 'p_d_desc' : 'p_d_asc';
case 'sale':
return order === '0' ? 's_n_desc' : 's_n_asc';
case 'newest':
return order === '0' ? 's_t_desc' : 's_t_asc';
case 'stock':
return order === '0' ? 's_s_desc' : 's_s_asc';
case 'all':
return order === '0' ? 'd_s_desc' : 'd_s_asc';
case 'category':
return order === '0' ? 's_t_desc' : 's_t_asc';
case 'new':
return order === '0' ? 's_t_desc' : 's_t_asc';
case 'hot':
return order === '0' ? 's_n_desc' : 's_n_asc';
case 'popularity':
return order === '0' ? 'h_v_desc' : 'h_v_asc';
default:
return order === '0' ? 's_t_desc' : 's_t_asc';
}
};
/**
* @param 查询参数 queryParams
* @param 接口数据 apiData
*/
const getFilterValueForSeo = (queryParams, apiData) => {
let seoParams = {};
let seniors = [];
_.forEach(queryParams, (value, key) => {
if (_.find(['color', 'size', 'style'], o => {
return key === o;
})) {
let colorObj = _.find(_.get(apiData, `filter.${key}`, []), o => {
return _.parseInt(value) === _.get(o, `${key}_id`);
});
seoParams[`${key}`] = _.get(colorObj, `${key}_name`, '');
}
if (key === 'brand') {
let brands = _.get(apiData, 'filter.brand', []);
let brandObj = _.find(brands, brand => {
return _.parseInt(value) === brand.id;
});
seoParams.brand = _.get(brandObj, 'brand_name', '');
}
if (key === 'gender') {
seoParams.channel = _getGenderForSeo(value);
}
if (key === 'sort' || key === 'category_id') {
let sorts = _.get(apiData, 'filter.group_sort', []);
let testSorts = _.cloneDeep(sorts);
_.forEach(sorts, sort => {
let sortSub = _.get(sort, 'sub', []);
if (sortSub) {
_.forEach(sortSub, subSort => {
testSorts.push(subSort);
});
}
});
let sortObj = _.find(testSorts, sort => {
return _.find(_.split(sort.category_id, ','), o => {
return value === o;
});
});
seoParams.sort = _.get(sortObj, 'category_name', '');
}
if (key === 'price') {
seoParams.price = `¥${_.replace(value, ',', '-')}`;
}
if (key === 'standard') {
let paramGroups = _.split(value, ',');
_.forEach(paramGroups, paramGroup => {
let paramValues = _.split(paramGroup, '_');
let standards = _.get(apiData, 'standard', []);
let standardObj = _.find(standards, o => {
return paramValues[0] === o.standard_id;
});
let standardSeObj = _.find(_.get(standardObj, 'sub', []), o => {
return paramValues[1] === o.standard_id;
});
seniors.push(_.get(standardSeObj, 'standard_name', ''));
});
}
});
if (seoParams.style) {
seniors.push(seoParams.style);
}
seoParams.senior = _.join(seniors, ',');
return seoParams;
};
/**
* 品类列表页 SEO 数据
* @param {*} gender
* @param {*} sort_name
*/
const getListSeoData = (params) => {
let seoData = {
title: '潮流服装配饰,创意生活用品_男生|女生|潮童服装,鞋履,配饰品牌正品-YOHO!BUY有货',
keywords: '潮流服装配饰,创意生活用品,男生服装配饰,女生服装配饰,潮童服装配饰',
description: '潮流服装配饰及创意生活正品网购!YOHO!BUY有货提供男生、女生、潮童服装配饰。100%品牌正品保证,支持货到付款。'
};
let seoParams = {
color: '',
size: '',
style: '',
brand: '',
gender: '',
sort: '',
price: '',
senior: '',
channel: ''
};
if (params) {
_.assign(seoParams, params);
let baseInfo = `${seoParams.brand}${seoParams.sort}`;
seoData = {
title: `${baseInfo ? baseInfo + '|' : ''}新款${seoParams.brand}${seoParams.channel}${seoParams.color}${seoParams.size}${seoParams.sort}${seoParams.price},${seoParams.brand}${seoParams.senior}${seoParams.sort}品牌正品|YOHO!BUY有货`, // eslint-disable-line
keywords: `${baseInfo ? baseInfo + ',' : ''}新款${seoParams.brand}${seoParams.channel}${seoParams.color}${seoParams.size}${seoParams.sort}${seoParams.price},${seoParams.brand}${seoParams.senior}${seoParams.sort}品牌正品`, // eslint-disable-line
description: `${baseInfo}正品网购!YOHO!BUY有货提供新款${seoParams.brand}${seoParams.channel}${seoParams.color}${seoParams.size}${seoParams.sort}${seoParams.price},${seoParams.brand}${seoParams.senior}${seoParams.sort}100%品牌正品保证,支持货到付款。` // eslint-disable-line
};
}
return seoData;
};
/**
* 获取筛选的参数,不包括方法名
*/
const getSearchParamsWithoutMethod = (params) => {
let finalParams = {
limit: params.limit || 24,
status: params.status || 1,
sales: params.sales || 'Y',
stocknumber: params.stocknumber || 1,
attribute_not: params.attribute_not || 2
};
if (params.query) { // 模糊查询参数
let queryString = '';
try {
queryString = decodeURIComponent(params.query).replace(/\+/g, ',');
} catch (e) {
logger.error('decodeURIComponent params query: ' + e);
}
finalParams.query = queryString;
}
if (params.yh_channel || params.channel) { // 频道
finalParams.yh_channel = params.yh_channel || getChannelType(params.channel);
}
if ((params.brand_id && params.brand_id !== '0') || (params.brand && params.brand !== '0')) {
// 品牌ID
finalParams.brand = params.brand_id || params.brand;
}
if (params.shop_id && params.shop_id !== '0') { // 店铺ID
finalParams.shop_id = params.shop_id;
}
if (params.type) { // 排序类型
finalParams.type = params.type;
}
if (params.type !== 'default') { // 排序参数
finalParams.order = params.order ? getTypeCont(params.type || '', params.order) : 's_t_asc';
}
if (params.limited) {
finalParams.limited = params.limited;
}
if (params.page) {
finalParams.page = params.page;
}
if (params.gender) {
finalParams.gender = params.gender;
}
if (params.color && params.color !== '0') {
finalParams.color = params.color;
}
if (params.price && params.price !== '0') {
finalParams.price = params.price;
}
if (params.size && params.size !== '0') {
finalParams.size = params.size;
}
if (params.p_d) {
finalParams.p_d = params.p_d;
}
if (params.sort && params.sort !== '0') {
finalParams.sort = params.sort;
}
if (params.msort && params.msort !== '0') {
finalParams.msort = params.msort;
}
if (params.misort && params.misort !== '0') {
finalParams.misort = params.misort;
}
if (params.tags_filter) {
finalParams.tags_filter = params.tags_filter;
}
if (params.category_id && params.category_id !== '0') {
finalParams.category_id = params.category_id;
}
if ((params.age_level && params.age_level !== '0') ||
(params.ageLevel && params.ageLevel !== '0')) {
finalParams.age_level = params.age_level || params.ageLevel;
}
if (params.outlets) {
finalParams.outlets = params.outlets;
}
if (params.new) { // newArrival
finalParams.new = params.new;
}
if (params.style) {
finalParams.style = params.style;
}
if (params.standard) {
finalParams.standard = params.standard;
}
if (params.specialoffer) {
finalParams.specialoffer = params.specialoffer;
}
if (params.productPool || params.filter_poolId) { // 商品池
finalParams.productPool = params.productPool || params.filter_poolId;
}
if (params.promotion) {
finalParams.promotion = params.promotion;
}
if (params.promotion_id) {
finalParams.promotion_id = params.promotion_id;
}
if (params.app_type && params.app_type === '1') {
finalParams.app_type = 1;
}
if (params.coupon_id) { // 个人中心优惠券立即使用 - 商品列表
finalParams.coupon_id = params.coupon_id;
}
if (params.coupon_code) { // 个人中心优惠券立即使用 - 商品列表
finalParams.coupon_code = params.coupon_code;
}
if (params.specialsale_id) { // sale 要用到的参数,预留
finalParams.specialsale_id = params.specialsale_id;
}
if (params.coin) { // 学生返币查询参数处理
delete finalParams.filter_poolId;
if (params.type === 'newest') {
delete finalParams.order;
delete finalParams.type;
}
}
if (params.isblknew) {
finalParams.app_type = 1;
if (params.type === 'default') {
finalParams.order = 's_t_asc';
}
}
if (params.shelveTime) {
finalParams.shelveTime = params.shelveTime;
}
return finalParams;
};
module.exports = {
getGenderByChannel,
getChannelType,
getTypeCont,
getFilterValueForSeo,
getListSeoData,
getSearchParamsWithoutMethod
};