Authored by 郭成尧

Merge branch 'feature/seo4' into 'release/6.3'

Feature/seo4



See merge request !1155
@@ -279,7 +279,10 @@ const category = (req, res, next) => { @@ -279,7 +279,10 @@ const category = (req, res, next) => {
279 localCss: true, 279 localCss: true,
280 appPath: appPath, 280 appPath: appPath,
281 introText: req.query.intro_text 281 introText: req.query.intro_text
282 - }, searchProcess.getListSeoData(req.query.gender, seoTitle))); 282 + }, searchProcess.getListSeoData({
  283 + gender: req.query.gender,
  284 + sort_name: seoTitle
  285 + })));
283 }).catch(next); 286 }).catch(next);
284 }; 287 };
285 288
@@ -337,17 +340,18 @@ const listNew = (req, res, next) => { @@ -337,17 +340,18 @@ const listNew = (req, res, next) => {
337 let categoryIntroRedis = []; 340 let categoryIntroRedis = [];
338 341
339 let responseResult = { 342 let responseResult = {
340 - list: productProcess.processProductList(result.data.product_list || [], { 343 + list: productProcess.processProductList(_.get(result, 'data.product_list', []), {
341 isApp: params.isApp || (params.appVersion && params.appVersion !== 'false'), 344 isApp: params.isApp || (params.appVersion && params.appVersion !== 'false'),
342 gender: _coverChannel[params.coverChannel], 345 gender: _coverChannel[params.coverChannel],
343 showSimilar: params.shop_id || params.material === 'true' ? false : true 346 showSimilar: params.shop_id || params.material === 'true' ? false : true
344 }) 347 })
345 }; 348 };
346 -  
347 - let seoTitle = _.get(result, 'data.filter.group_sort[0].sub[0].category_name'); 349 + let seoParams = searchProcess.getFilterValueForSeo(initialData, _.get(result, 'data', {}));
  350 + let seoRenderData = searchProcess.getListSeoData(seoParams);
  351 + let seoTitle = _.get(seoParams, 'sort');
348 let paramsTitle = params.title || params.sort_name; // 可能会配置的标题,优先级最高 352 let paramsTitle = params.title || params.sort_name; // 可能会配置的标题,优先级最高
349 353
350 - if (!seoTitle || !initialData.category_id) { 354 + if (!seoTitle) {
351 seoTitle = '商品列表'; 355 seoTitle = '商品列表';
352 } 356 }
353 357
@@ -387,7 +391,7 @@ const listNew = (req, res, next) => { @@ -387,7 +391,7 @@ const listNew = (req, res, next) => {
387 localCss: true, 391 localCss: true,
388 appPath: appPath, 392 appPath: appPath,
389 categoryIntro: categoryIntro 393 categoryIntro: categoryIntro
390 - }, searchProcess.getListSeoData(req.query.gender, seoTitle))); 394 + }, seoRenderData));
391 })().catch(next); 395 })().catch(next);
392 }; 396 };
393 397
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 * @author: wsl<shuiling.wang@yoho.cn> 3 * @author: wsl<shuiling.wang@yoho.cn>
4 * @date: 2016/7/29 4 * @date: 2016/7/29
5 */ 5 */
  6 +const _ = require('lodash');
6 7
7 /** 8 /**
8 * 根据频道判断出性别 9 * 根据频道判断出性别
@@ -20,6 +21,26 @@ const getGenderByChannel = (channel) => { @@ -20,6 +21,26 @@ const getGenderByChannel = (channel) => {
20 } 21 }
21 }; 22 };
22 23
  24 +/**
  25 + * seo 获取性别
  26 + */
  27 +const _getGenderForSeo = (gender) => {
  28 + let seoGender = '男生|女生';
  29 +
  30 + switch (gender) {
  31 + case '1,3':
  32 + seoGender = '男生';
  33 + break;
  34 + case '2,3':
  35 + seoGender = '女生';
  36 + break;
  37 + default:
  38 + break;
  39 + }
  40 +
  41 + return seoGender;
  42 +};
  43 +
23 // 频道转换 44 // 频道转换
24 const getChannelType = (channel) => { 45 const getChannelType = (channel) => {
25 channel = channel ? channel : 'boys'; 46 channel = channel ? channel : 'boys';
@@ -67,22 +88,115 @@ const getTypeCont = (type, order) => { @@ -67,22 +88,115 @@ const getTypeCont = (type, order) => {
67 }; 88 };
68 89
69 /** 90 /**
  91 + *
  92 + * @param 查询参数 queryParams
  93 + * @param 接口数据 apiData
  94 + */
  95 +const getFilterValueForSeo = (queryParams, apiData) => {
  96 + let seoParams = {
  97 + color: '',
  98 + size: '',
  99 + style: '',
  100 + brand: '',
  101 + gender: '',
  102 + sort: '',
  103 + price: '',
  104 + senior: ''
  105 + };
  106 + let seniors = [];
  107 +
  108 + _.forEach(queryParams, (value, key) => {
  109 + if (_.find(['color', 'size', 'style'], o => {
  110 + return key === o;
  111 + })) {
  112 + let colorObj = _.find(_.get(apiData, `filter.${key}`, []), o => {
  113 + return _.parseInt(value) === _.get(o, `${key}_id`);
  114 + });
  115 +
  116 + seoParams[`${key}`] = _.get(colorObj, `${key}_name`, '');
  117 + }
  118 + if (key === 'brand') {
  119 + let brands = _.get(apiData, 'filter.brand', []);
  120 + let brandObj = _.find(brands, brand => {
  121 + return _.parseInt(value) === brand.id;
  122 + });
  123 +
  124 + seoParams.brand = _.get(brandObj, 'brand_name', '');
  125 + }
  126 + if (key === 'gender') {
  127 + seoParams.channel = _getGenderForSeo(value);
  128 + }
  129 + if (key === 'sort' || key === 'category_id') {
  130 + let sorts = _.get(apiData, 'filter.group_sort', []);
  131 + let testSorts = _.cloneDeep(sorts);
  132 +
  133 + _.forEach(sorts, sort => {
  134 + let sortSub = _.get(sort, 'sub', []);
  135 +
  136 + if (sortSub) {
  137 + _.forEach(sortSub, subSort => {
  138 + testSorts.push(subSort);
  139 + });
  140 + }
  141 + });
  142 +
  143 + let sortObj = _.find(testSorts, sort => {
  144 + return _.find(_.split(sort.category_id, ','), o => {
  145 + return value === o;
  146 + });
  147 + });
  148 +
  149 + seoParams.sort = _.get(sortObj, 'category_name', '');
  150 + }
  151 + if (key === 'price') {
  152 + seoParams.price = `¥${_.replace(value, ',', '-')}`;
  153 + }
  154 + if (key === 'standard') {
  155 + let paramGroups = _.split(value, ',');
  156 +
  157 + _.forEach(paramGroups, paramGroup => {
  158 + let paramValues = _.split(paramGroup, '_');
  159 + let standards = _.get(apiData, 'standard', []);
  160 + let standardObj = _.find(standards, o => {
  161 + return paramValues[0] === o.standard_id;
  162 + });
  163 + let standardSeObj = _.find(_.get(standardObj, 'sub', []), o => {
  164 + return paramValues[1] === o.standard_id;
  165 + });
  166 +
  167 + seniors.push(_.get(standardSeObj, 'standard_name', ''));
  168 + });
  169 + }
  170 + });
  171 +
  172 + if (seoParams.style) {
  173 + seniors.push(seoParams.style);
  174 + }
  175 +
  176 + seoParams.senior = _.join(seniors, ',');
  177 +
  178 + return seoParams;
  179 +};
  180 +
  181 +/**
70 * 品类列表页 SEO 数据 182 * 品类列表页 SEO 数据
71 * @param {*} gender 183 * @param {*} gender
72 * @param {*} sort_name 184 * @param {*} sort_name
73 */ 185 */
74 -const getListSeoData = (gender, sort_name) => { 186 +const getListSeoData = (params) => {
75 let seoData = { 187 let seoData = {
76 title: '潮流服装配饰,创意生活用品_男生|女生|潮童服装,鞋履,配饰品牌正品-YOHO!BUY有货', 188 title: '潮流服装配饰,创意生活用品_男生|女生|潮童服装,鞋履,配饰品牌正品-YOHO!BUY有货',
77 keywords: '潮流服装配饰,创意生活用品,男生服装配饰,女生服装配饰,潮童服装配饰', 189 keywords: '潮流服装配饰,创意生活用品,男生服装配饰,女生服装配饰,潮童服装配饰',
78 description: '潮流服装配饰及创意生活正品网购!YOHO!BUY有货提供男生、女生、潮童服装配饰。100%品牌正品保证,支持货到付款。' 190 description: '潮流服装配饰及创意生活正品网购!YOHO!BUY有货提供男生、女生、潮童服装配饰。100%品牌正品保证,支持货到付款。'
79 }; 191 };
80 192
81 - if (gender && sort_name) { 193 + if (params) {
  194 + let baseInfo = `${params.brand}${params.sort}`;
  195 +
82 seoData = { 196 seoData = {
83 - title: `${sort_name}|新款${sort_name},${sort_name}品牌正品|YOHO!BUY有货`,  
84 - keywords: `${sort_name},新款${sort_name}${sort_name}品牌正品`,  
85 - description: `有货网${sort_name}专卖店销售正品新款${sort_name},支持货到付款。了解新款${sort_name}${sort_name}品牌价格、评价、图片等信息,网购超低折扣新款${sort_name}就上有货网。` // eslint-disable-line 197 + 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
  198 + keywords: `${baseInfo ? baseInfo + ',' : ''}新款${params.brand}${params.channel}${params.color}${params.size}${params.sort}${params.price},${params.brand}${params.senior}${params.sort}品牌正品`, // eslint-disable-line
  199 + 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
86 }; 200 };
87 } 201 }
88 return seoData; 202 return seoData;
@@ -220,6 +334,7 @@ module.exports = { @@ -220,6 +334,7 @@ module.exports = {
220 getGenderByChannel, 334 getGenderByChannel,
221 getChannelType, 335 getChannelType,
222 getTypeCont, 336 getTypeCont,
  337 + getFilterValueForSeo,
223 getListSeoData, 338 getListSeoData,
224 getSearchParamsWithoutMethod 339 getSearchParamsWithoutMethod
225 }; 340 };