...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
* @author: wsl<shuiling.wang@yoho.cn>
|
|
|
* @date: 2016/7/29
|
|
|
*/
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
/**
|
|
|
* 根据频道判断出性别
|
...
|
...
|
@@ -20,6 +21,26 @@ const getGenderByChannel = (channel) => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 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';
|
...
|
...
|
@@ -67,22 +88,115 @@ const getTypeCont = (type, order) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param 查询参数 queryParams
|
|
|
* @param 接口数据 apiData
|
|
|
*/
|
|
|
const getFilterValueForSeo = (queryParams, apiData) => {
|
|
|
let seoParams = {
|
|
|
color: '',
|
|
|
size: '',
|
|
|
style: '',
|
|
|
brand: '',
|
|
|
gender: '',
|
|
|
sort: '',
|
|
|
price: '',
|
|
|
senior: ''
|
|
|
};
|
|
|
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 = (gender, sort_name) => {
|
|
|
const getListSeoData = (params) => {
|
|
|
let seoData = {
|
|
|
title: '潮流服装配饰,创意生活用品_男生|女生|潮童服装,鞋履,配饰品牌正品-YOHO!BUY有货',
|
|
|
keywords: '潮流服装配饰,创意生活用品,男生服装配饰,女生服装配饰,潮童服装配饰',
|
|
|
description: '潮流服装配饰及创意生活正品网购!YOHO!BUY有货提供男生、女生、潮童服装配饰。100%品牌正品保证,支持货到付款。'
|
|
|
};
|
|
|
|
|
|
if (gender && sort_name) {
|
|
|
if (params) {
|
|
|
let baseInfo = `${params.brand}${params.sort}`;
|
|
|
|
|
|
seoData = {
|
|
|
title: `${sort_name}|新款${sort_name},${sort_name}品牌正品|YOHO!BUY有货`,
|
|
|
keywords: `${sort_name},新款${sort_name},${sort_name}品牌正品`,
|
|
|
description: `有货网${sort_name}专卖店销售正品新款${sort_name},支持货到付款。了解新款${sort_name}、${sort_name}品牌价格、评价、图片等信息,网购超低折扣新款${sort_name}就上有货网。` // eslint-disable-line
|
|
|
title: `${baseInfo ? baseInfo + '|' : ''}新款${params.brand}${params.channel}${params.color}${params.size}${params.sort}${params.price},${params.brand}${params.senior}${params.sort}品牌正品|YOHO!BUY有货`, // eslint-disable-line
|
|
|
keywords: `${baseInfo ? baseInfo + ',' : ''}新款${params.brand}${params.channel}${params.color}${params.size}${params.sort}${params.price},${params.brand}${params.senior}${params.sort}品牌正品`, // eslint-disable-line
|
|
|
description: `${baseInfo}正品网购!YOHO!BUY有货提供新款${params.brand}${params.channel}${params.color}${params.size}${params.sort}${params.price},${params.brand}${params.senior}${params.sort}100%品牌正品保证,支持货到付款。` // eslint-disable-line
|
|
|
};
|
|
|
}
|
|
|
return seoData;
|
...
|
...
|
@@ -220,6 +334,7 @@ module.exports = { |
|
|
getGenderByChannel,
|
|
|
getChannelType,
|
|
|
getTypeCont,
|
|
|
getFilterValueForSeo,
|
|
|
getListSeoData,
|
|
|
getSearchParamsWithoutMethod
|
|
|
}; |
...
|
...
|
|