Authored by 刘传洋

seo

@@ -15,7 +15,13 @@ const search = require(`${mRoot}/search`); @@ -15,7 +15,13 @@ const search = require(`${mRoot}/search`);
15 * @return {[type]} [description] 15 * @return {[type]} [description]
16 */ 16 */
17 exports.index = (req, res, next) => { 17 exports.index = (req, res, next) => {
18 - let resData = {}; 18 + let resData = {
  19 + title: '潮流商品搜索 | YOHO!BUY 有货',
  20 + keywords: 'Yoho! 有货,潮流,时尚,流行,购物,B2C,正品,购物网站,网上购物,货到付款,' +
  21 + '品牌服饰,男士护肤,黑框眼镜,匡威,板鞋,i.t,izzue,5cm,eastpak,vans,lylescott,g-shock,' +
  22 + 'new balance,lacoste,melissa,casio,卡西欧手表,舒雅,jasonwood,odm,AAAA,香港购物,日本潮流',
  23 + description: '潮流商品搜索,上衣,衬衫,TEE,卫衣,冲锋衣,风衣,羽绒服,裤子,休闲鞋,板鞋,配饰,复古眼镜'
  24 + };
19 25
20 search.getSearchData(req.query, req.yoho.channel).then(result => { 26 search.getSearchData(req.query, req.yoho.channel).then(result => {
21 Object.assign(resData, result); 27 Object.assign(resData, result);
@@ -94,14 +94,6 @@ exports.getListData = (params, channel) => { @@ -94,14 +94,6 @@ exports.getListData = (params, channel) => {
94 goods: productProcess.processProductList(result[2].data.product_list, 94 goods: productProcess.processProductList(result[2].data.product_list,
95 Object.assign({showDiscount: false}, params)) 95 Object.assign({showDiscount: false}, params))
96 }); 96 });
97 -  
98 - // 获取高级筛选条件  
99 - /* if (finalResult.list && finalResult.list.filters) {  
100 - Object.assign(finalResult.list.filters, searchHandler.handleSeniorFilterData({  
101 - style: _.get(result[2], 'data.filter.style', []),  
102 - standard: _.get(result[2], 'data.standard', [])  
103 - }, params));  
104 - }*/  
105 } 97 }
106 98
107 // 分类介绍 99 // 分类介绍
@@ -113,7 +105,12 @@ exports.getListData = (params, channel) => { @@ -113,7 +105,12 @@ exports.getListData = (params, channel) => {
113 if (result[4] && result[4].code === 200) { 105 if (result[4] && result[4].code === 200) {
114 Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[4].data)); 106 Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[4].data));
115 } 107 }
116 - return finalResult; 108 +
  109 + let seo = searchHandler.getListSeo(channel,
  110 + _.get(finalResult, 'list.leftContent.allSort.list'),
  111 + _.get(finalResult, 'list.filters.checkedConditions.conditions'));
  112 +
  113 + return Object.assign({}, seo, finalResult);
117 }); 114 });
118 }; 115 };
119 116
@@ -158,14 +155,6 @@ exports.getListNewData = (params, channel) => { @@ -158,14 +155,6 @@ exports.getListNewData = (params, channel) => {
158 goods: productProcess.processProductList(result[2].data.product_list, 155 goods: productProcess.processProductList(result[2].data.product_list,
159 Object.assign({showDiscount: false}, params)) 156 Object.assign({showDiscount: false}, params))
160 }); 157 });
161 -  
162 - // 获取高级筛选条件  
163 - /* if (finalResult.list && finalResult.list.filters) {  
164 - Object.assign(finalResult.list.filters, searchHandler.handleSeniorFilterData({  
165 - style: _.get(result[2], 'data.filter.style', []),  
166 - standard: _.get(result[2], 'data.standard', [])  
167 - }, params));  
168 - }*/  
169 } 158 }
170 159
171 // 新品上架 160 // 新品上架
@@ -173,7 +162,9 @@ exports.getListNewData = (params, channel) => { @@ -173,7 +162,9 @@ exports.getListNewData = (params, channel) => {
173 Object.assign(finalResult.list.leftContent, searchHandler.handleWeekNew(result[3].data, params)); 162 Object.assign(finalResult.list.leftContent, searchHandler.handleWeekNew(result[3].data, params));
174 } 163 }
175 164
176 - return finalResult; 165 + let seo = searchHandler.getNewSeo(channel, _.get(finalResult, 'list.leftContent.newSales.list'));
  166 +
  167 + return Object.assign({}, seo, finalResult);
177 }); 168 });
178 }; 169 };
179 170
@@ -251,21 +242,14 @@ exports.getBrandData = (params, extra, channel) => { @@ -251,21 +242,14 @@ exports.getBrandData = (params, extra, channel) => {
251 goods: productProcess.processProductList(result[2].data.product_list, 242 goods: productProcess.processProductList(result[2].data.product_list,
252 Object.assign({showDiscount: false}, params)) 243 Object.assign({showDiscount: false}, params))
253 }); 244 });
254 -  
255 - // 获取高级筛选条件  
256 - /* if (finalResult.list && finalResult.list.filters) {  
257 -  
258 - Object.assign(finalResult.list.filters, searchHandler.handleSeniorFilterData({  
259 - style: _.get(result[2], 'data.filter.style', []),  
260 - standard: _.get(result[2], 'data.standard', [])  
261 - }, params));  
262 - }*/  
263 } 245 }
264 246
265 // 品牌页不显示品牌筛选项 247 // 品牌页不显示品牌筛选项
266 delete finalResult.brand.filters.brand; 248 delete finalResult.brand.filters.brand;
267 249
268 - return finalResult; 250 + let seo = searchHandler.getBrandSeo(channel, extra);
  251 +
  252 + return Object.assign({}, seo, finalResult);
269 }); 253 });
270 }; 254 };
271 255
@@ -131,8 +131,8 @@ const getSortList = (params) => { @@ -131,8 +131,8 @@ const getSortList = (params) => {
131 } 131 }
132 return ret; 132 return ret;
133 }); 133 });
134 - }  
135 - }); 134 + /*}
  135 + });*/
136 }; 136 };
137 137
138 /** 138 /**
@@ -61,7 +61,8 @@ const handleCheckedData = (params, origin, param) => { @@ -61,7 +61,8 @@ const handleCheckedData = (params, origin, param) => {
61 61
62 dest.push({ 62 dest.push({
63 name: value.name, 63 name: value.name,
64 - href: handleFilterUrl(tempPatam) 64 + href: handleFilterUrl(tempPatam),
  65 + itemType: param
65 }); 66 });
66 } 67 }
67 }); 68 });
@@ -120,6 +121,7 @@ const handleBrandCheckedData = (params, origin) => { @@ -120,6 +121,7 @@ const handleBrandCheckedData = (params, origin) => {
120 }; 121 };
121 122
122 checked.href = handleFilterUrl(params, tempParam); 123 checked.href = handleFilterUrl(params, tempParam);
  124 + checked.itemType = 'brand';
123 if (checkedCount === 0) { 125 if (checkedCount === 0) {
124 dest[0] = checked; 126 dest[0] = checked;
125 } else if (checkedCount === 1) { 127 } else if (checkedCount === 1) {
@@ -383,11 +385,13 @@ exports.handleSortData = (origin, params) => { @@ -383,11 +385,13 @@ exports.handleSortData = (origin, params) => {
383 name: `全部${value.sort_name}`, 385 name: `全部${value.sort_name}`,
384 num: value.count, 386 num: value.count,
385 href: handleFilterUrl(params, {msort: value.sort_id}, {misort: true}), 387 href: handleFilterUrl(params, {msort: value.sort_id}, {misort: true}),
386 - childActive: (params.msort === value.sort_id) && !params.misort 388 + childActive: (params.msort === value.sort_id) && !params.misort,
  389 + sortId: value.sort_id
387 } 390 }
388 ], 391 ],
389 href: handleFilterUrl(params, {msort: value.sort_id}), 392 href: handleFilterUrl(params, {msort: value.sort_id}),
390 - active: params.msort === value.sort_id 393 + active: params.msort === value.sort_id,
  394 + sortId: value.sort_id
391 }; 395 };
392 396
393 allCount += parseInt(value.count, 10); 397 allCount += parseInt(value.count, 10);
@@ -397,7 +401,8 @@ exports.handleSortData = (origin, params) => { @@ -397,7 +401,8 @@ exports.handleSortData = (origin, params) => {
397 name: subValue.sort_name, 401 name: subValue.sort_name,
398 num: subValue.count, 402 num: subValue.count,
399 href: handleFilterUrl(params, {msort: value.sort_id, misort: subValue.sort_id}), 403 href: handleFilterUrl(params, {msort: value.sort_id, misort: subValue.sort_id}),
400 - childActive: params.misort === subValue.sort_id 404 + childActive: params.misort === subValue.sort_id,
  405 + sortId: subValue.sort_id
401 }); 406 });
402 if (params.misort === subValue.sort_id) { 407 if (params.misort === subValue.sort_id) {
403 category.active = true; 408 category.active = true;
@@ -1161,3 +1166,127 @@ exports.handleNextPage = (params, total) => { @@ -1161,3 +1166,127 @@ exports.handleNextPage = (params, total) => {
1161 'imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90' 1166 'imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90'
1162 }; 1167 };
1163 }; 1168 };
  1169 +
  1170 +const getChannelName = channel => {
  1171 +
  1172 + let channelName = '';
  1173 +
  1174 + switch(channel){
  1175 + case 'boys':
  1176 + channelName = '男生';
  1177 + break;
  1178 + case 'girls':
  1179 + channelName = '女生';
  1180 + break;
  1181 + case 'kids':
  1182 + channelName = '潮童';
  1183 + break;
  1184 + case 'lifestyle':
  1185 + channelName = '创意生活';
  1186 + break;
  1187 + default:
  1188 + channelName = '男生';
  1189 + }
  1190 +
  1191 + return channelName;
  1192 +};
  1193 +
  1194 +/**
  1195 + * 列表页seo
  1196 + * @param channel
  1197 + * @param sorts
  1198 + * @param checked
  1199 + * @returns {{title: string, keywords: string, description: string}}
  1200 + */
  1201 +exports.getListSeo = (channel, sorts, checked) => {
  1202 + let channelName = getChannelName(channel),
  1203 + brandName = '',
  1204 + priceName = '',
  1205 + msortName = '',
  1206 + misortName = '';
  1207 +
  1208 + _.forEach(sorts, val => {
  1209 + if(val.active) {
  1210 + msortName = val && val.name;
  1211 + _.forEach(val.childList, sub => {
  1212 + if(sub.childActive && sub.sortId !== val.sortId) {
  1213 + misortName = sub && sub.name;
  1214 + return false;
  1215 + }
  1216 + });
  1217 + return false;
  1218 + }
  1219 + });
  1220 +
  1221 + _.forEach(checked, ck => {
  1222 + if(ck.itemType === 'price') {
  1223 + priceName = ck.name;
  1224 + } else if(ck.itemType === 'brand') {
  1225 + brandName = ck.name;
  1226 + }
  1227 + });
  1228 +
  1229 + let bmpcm = brandName + misortName + priceName + channelName + msortName,
  1230 + bm = brandName + misortName,
  1231 + bmp = brandName + misortName + priceName,
  1232 + cmbm = channelName + msortName + brandName + misortName,
  1233 + cm = channelName + msortName;
  1234 +
  1235 + let title = (bmpcm ? bmpcm + '|' : '') + 'YOHO!BUY 有货 100%正品保证',
  1236 + keywords = (bm ? bm + ',' : '') + (bmp ? bmp + ',' : '') + cmbm,
  1237 + description = bmp + '正品网购。' + (cm ? cm + ',' : '') + bm + '官方授权!YOHO! 有货中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。';
  1238 +
  1239 + return {
  1240 + title: title,
  1241 + keywords: keywords,
  1242 + description: description
  1243 + };
  1244 +};
  1245 +
  1246 +/**
  1247 + * 新品到页 seo
  1248 + * @param channel
  1249 + * @param dlist
  1250 + * @returns {{title: string, keywords: string, description: string}}
  1251 + */
  1252 +exports.getNewSeo = (channel, dlist) => {
  1253 +
  1254 + let channelName = getChannelName(channel),
  1255 + nlabel = '';
  1256 +
  1257 + _.forEach(dlist, d => {
  1258 + if(d && d.active) {
  1259 + nlabel = d.name || '';
  1260 + return false;
  1261 + }
  1262 + });
  1263 +
  1264 + let newTitle = channelName + nlabel;
  1265 +
  1266 + return {
  1267 + title: newTitle + '新品上架-YOHO!BUY 有货 100%正品保证',
  1268 + keywords: newTitle + '新品上架',
  1269 + description: newTitle + '新品上架,正品网购,官方授权!YOHO! 有货中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。'
  1270 + }
  1271 +};
  1272 +
  1273 +exports.getBrandSeo = (channel, brandInfo) => {
  1274 +
  1275 + let c = getChannelName(channel),
  1276 + bcn = brandInfo && brandInfo.brandNameCn,
  1277 + b = brandInfo && brandInfo.brandNameEn,
  1278 + bb = b + ' ' + bcn,
  1279 + bc = b + c,
  1280 + bbc = b + bcn + c,
  1281 + title = bb || b || '',
  1282 + keywords = (b ? b + ',' : '') + ((b && bcn) ? (bb + ',') : '') + bc || '' + '品牌',
  1283 + desc = b + '正品网购。' + bbc || '' + '品牌官方授权!YOHO! 有货中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。';
  1284 +
  1285 + title += (title ? (title + '|') : '') + c + '品牌|YOHO!BUY 有货 100%正品保证';
  1286 +
  1287 + return {
  1288 + title: title,
  1289 + keywords: keywords,
  1290 + description: desc
  1291 + };
  1292 +};
@@ -119,7 +119,7 @@ exports.processProductList = (list, options) => { @@ -119,7 +119,7 @@ exports.processProductList = (list, options) => {
119 119
120 120
121 // 商品信息有问题,则不显示 121 // 商品信息有问题,则不显示
122 - if (!product.product_skn || !product.goods_list.length) { 122 + if (!product || !product.product_skn || !product.goods_list.length) {
123 return; 123 return;
124 } 124 }
125 125