Authored by htoooth

解决seo的问题。

@@ -36,6 +36,7 @@ const _getProductAdditionInfoAsync = (data) => { @@ -36,6 +36,7 @@ const _getProductAdditionInfoAsync = (data) => {
36 let uid = data.uid ? data.uid : 0; 36 let uid = data.uid ? data.uid : 0;
37 let skn = data.erpProductId; 37 let skn = data.erpProductId;
38 let brandId = data.brand.id ? data.brand.id : 0; 38 let brandId = data.brand.id ? data.brand.id : 0;
  39 + let index = 0;
39 40
40 // 获取相关数据 41 // 获取相关数据
41 let promiseData = [ 42 let promiseData = [
@@ -53,13 +54,18 @@ const _getProductAdditionInfoAsync = (data) => { @@ -53,13 +54,18 @@ const _getProductAdditionInfoAsync = (data) => {
53 54
54 let result = yield Promise.all(promiseData); 55 let result = yield Promise.all(promiseData);
55 56
56 - cachedRequestData['ItemData::getProductBanner'] = result[0];  
57 - cachedRequestData['ItemData::sizeInfo'] = result[1];  
58 - cachedRequestData['ItemData::getProductComfort'] = result[2];  
59 - cachedRequestData['ItemData::getProductModelCard'] = result[3];  
60 - cachedRequestData['ItemData::getProductModelTry'] = result[4];  
61 - cachedRequestData['BrandData::getBannerInfo'] = result[5];  
62 - cachedRequestData['FavoriteData::getUidProductFav'] = result[6]; 57 + [
  58 + 'ItemData::getProductBanner',
  59 + 'ItemData::sizeInfo',
  60 + 'ItemData::getProductComfort',
  61 + 'ItemData::getProductModelCard',
  62 + 'ItemData::getProductModelTry',
  63 + 'BrandData::getBannerInfo',
  64 + 'FavoriteData::getUidProductFav'
  65 + ].forEach(key => {
  66 + cachedRequestData[key] = result[index++];
  67 + });
  68 +
63 69
64 return null; 70 return null;
65 })(); 71 })();
@@ -82,11 +88,8 @@ const _getProductFavoriteDataAsync = (uid, pid, bid) => { @@ -82,11 +88,8 @@ const _getProductFavoriteDataAsync = (uid, pid, bid) => {
82 88
83 if (uid) { 89 if (uid) {
84 if (pid) { 90 if (pid) {
85 - let productData = _getCacheDataByName('FavoriteData::getUidProductFav'); 91 + let productData = yield favoriteProductService.isFavoriteAsync(uid, pid);
86 92
87 - if (!productData) {  
88 - productData = yield favoriteProductService.isFavoriteAsync(uid, pid);  
89 - }  
90 result.product = productData.code === 200 && productData.data ? true : false; 93 result.product = productData.code === 200 && productData.data ? true : false;
91 } 94 }
92 95
@@ -133,8 +136,6 @@ const _getTagsDataByProductInfo = (data) => { @@ -133,8 +136,6 @@ const _getTagsDataByProductInfo = (data) => {
133 case 'yearEnd':// 年终大促 136 case 'yearEnd':// 年终大促
134 tags.isYearEndPromotion = true; 137 tags.isYearEndPromotion = true;
135 break; 138 break;
136 - default:  
137 - break;  
138 } 139 }
139 } 140 }
140 ); 141 );
@@ -157,7 +158,7 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => { @@ -157,7 +158,7 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => {
157 level: value.vipLevel, 158 level: value.vipLevel,
158 price: value.vipPrice, 159 price: value.vipPrice,
159 name: value.vipTitle, 160 name: value.vipTitle,
160 - cur: value.vipLevel === vipLevel ? true : false 161 + cur: value.vipLevel === vipLevel
161 }); 162 });
162 }); 163 });
163 } 164 }
@@ -165,14 +166,14 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => { @@ -165,14 +166,14 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => {
165 vipData.unLogin = false; 166 vipData.unLogin = false;
166 167
167 if (!uid) { 168 if (!uid) {
168 - vipData.unLogin = helpers.urlFormat('signin.html'); 169 + vipData.unLogin = helpers.urlFormat('/signin.html');
169 } 170 }
170 171
171 if (!vipLevel && uid) { 172 if (!vipLevel && uid) {
172 vipData.normalUser = true; 173 vipData.normalUser = true;
173 } 174 }
174 175
175 - vipData.vipSchedualUrl = helpers.urlFormat('home/vip', { 176 + vipData.vipSchedualUrl = helpers.urlFormat('/home/vip', {
176 t: _.random(10000, 9999999) 177 t: _.random(10000, 9999999)
177 }); 178 });
178 } 179 }
@@ -242,7 +243,7 @@ const _getConsultCommentDataByProductInfo = (data) => { @@ -242,7 +243,7 @@ const _getConsultCommentDataByProductInfo = (data) => {
242 consultComment.commentNum = 0; 243 consultComment.commentNum = 0;
243 if (data.commentBoWrapper) { 244 if (data.commentBoWrapper) {
244 consultComment.comments = []; 245 consultComment.comments = [];
245 - consultComment.commentUrl = helpers.urlFormat('/home/commnet'); 246 + consultComment.commentUrl = helpers.urlFormat('/home/comment');
246 } 247 }
247 248
248 return consultComment; 249 return consultComment;
@@ -282,8 +283,8 @@ const _getBrandDataByProductBaseInfo = (data) => { @@ -282,8 +283,8 @@ const _getBrandDataByProductBaseInfo = (data) => {
282 } 283 }
283 284
284 // banner的logo 285 // banner的logo
285 - if (bannerInfo.logo) {  
286 - logo = helpers.image(bannerInfo.logo); 286 + if (bannerInfo && bannerInfo.logo) {
  287 + logo = helpers.getForceSourceUrl(bannerInfo.logo);
287 } 288 }
288 289
289 let homeUrl = 'javascript:void(0)'; 290 let homeUrl = 'javascript:void(0)';
@@ -295,7 +296,7 @@ const _getBrandDataByProductBaseInfo = (data) => { @@ -295,7 +296,7 @@ const _getBrandDataByProductBaseInfo = (data) => {
295 // 导航的品牌banner 296 // 导航的品牌banner
296 return { 297 return {
297 brandId: brandId, 298 brandId: brandId,
298 - bgColor: bannerInfo.colorValue ? bannerInfo.colorValue : '#000000', 299 + bgColor: bannerInfo && bannerInfo.colorValue ? bannerInfo.colorValue : '#000000',
299 bgImg: bgImg, 300 bgImg: bgImg,
300 logo: logo, 301 logo: logo,
301 alt: data.brand.brandName, 302 alt: data.brand.brandName,
@@ -374,19 +375,19 @@ const _getSkuDataByProductBaseInfo = (data) => { @@ -374,19 +375,19 @@ const _getSkuDataByProductBaseInfo = (data) => {
374 goodsGroup.size.push({ 375 goodsGroup.size.push({
375 name: size.sizeName, 376 name: size.sizeName,
376 sku: size.goodsSizeSkuId, 377 sku: size.goodsSizeSkuId,
377 - num: parseInt(size.goodsSizeStorageNum, 10), 378 + num: parseInt(size.goodsSizeStorageNum),
378 goodsId: size.goodsId 379 goodsId: size.goodsId
379 }); 380 });
380 381
381 // 单个sku商品的总数 382 // 单个sku商品的总数
382 - goodsGroup.total += parseInt(size.goodsSizeStorageNum, 10); 383 + goodsGroup.total += parseInt(size.goodsSizeStorageNum);
383 384
384 if (goodsGroup.total > 0 && !chooseSkuFlag) { // 默认选中该sku商品 385 if (goodsGroup.total > 0 && !chooseSkuFlag) { // 默认选中该sku商品
385 goodsGroup.focus = true; 386 goodsGroup.focus = true;
386 chooseSkuFlag = true;// 选中sku商品 387 chooseSkuFlag = true;// 选中sku商品
387 } 388 }
388 389
389 - totalStorageNum += parseInt(size.goodsSizeStorageNum, 10); 390 + totalStorageNum += parseInt(size.goodsSizeStorageNum);
390 391
391 }); 392 });
392 393
@@ -435,41 +436,33 @@ const _getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => { @@ -435,41 +436,33 @@ const _getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => {
435 // 显示获取限购码按钮 436 // 显示获取限购码按钮
436 switch (showStatus) { 437 switch (showStatus) {
437 case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码) 438 case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码)
438 - {  
439 - if (isBeginSale) {  
440 - result.buyNow = true;  
441 - result.dis = true;  
442 - } else {  
443 - result.openSoon = true;  
444 - result.hasLimitedCode = false;  
445 - }  
446 - break;  
447 - }  
448 - case 2: // 开售后,限购码已抢光(用户未领取限购码)  
449 - { 439 + if (isBeginSale) {
450 result.buyNow = true; 440 result.buyNow = true;
451 result.dis = true; 441 result.dis = true;
452 - result.limitedCodeSoldOut = true;  
453 - result.getLimitedCode = false; 442 + } else {
  443 + result.openSoon = true;
454 result.hasLimitedCode = false; 444 result.hasLimitedCode = false;
455 - break;  
456 } 445 }
  446 + break;
  447 + case 2: // 开售后,限购码已抢光(用户未领取限购码)
  448 + result.buyNow = true;
  449 + result.dis = true;
  450 + result.limitedCodeSoldOut = true;
  451 + result.getLimitedCode = false;
  452 + result.hasLimitedCode = false;
  453 + break;
457 case 3: // 开售后,商品已经售罄 454 case 3: // 开售后,商品已经售罄
458 - {  
459 - result.soldOut = true;  
460 - result.getLimitedCode = false;  
461 - break;  
462 - } 455 + result.soldOut = true;
  456 + result.getLimitedCode = false;
  457 + break;
463 case 4:// 开售后,立即购买(用户已领取限购码) 458 case 4:// 开售后,立即购买(用户已领取限购码)
464 - {  
465 - result.buyNow = true;  
466 - result.dis = false;  
467 - result.hasLimitedCode = true;  
468 - if (uid) { // 限购码失效  
469 - result.getLimitedCodeDis = true;  
470 - }  
471 - break; 459 + result.buyNow = true;
  460 + result.dis = false;
  461 + result.hasLimitedCode = true;
  462 + if (uid) { // 限购码失效
  463 + result.getLimitedCodeDis = true;
472 } 464 }
  465 + break;
473 case 5: // 开售前,限购码已被抢光(用户未领取限购码) 466 case 5: // 开售前,限购码已被抢光(用户未领取限购码)
474 result.openSoon = true; 467 result.openSoon = true;
475 result.hasLimitedCode = true; 468 result.hasLimitedCode = true;
@@ -490,9 +483,6 @@ const _getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => { @@ -490,9 +483,6 @@ const _getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => {
490 if (uid) { // 限购码失效 483 if (uid) { // 限购码失效
491 result.getLimitedCodeDis = true; 484 result.getLimitedCodeDis = true;
492 } 485 }
493 - break;  
494 - default:  
495 - break;  
496 } 486 }
497 487
498 488
@@ -651,7 +641,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -651,7 +641,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
651 let showStatus = 1; 641 let showStatus = 1;
652 642
653 if (origin.showStatus) { 643 if (origin.showStatus) {
654 - showStatus = parseInt(origin.showStatus, 10); 644 + showStatus = parseInt(origin.showStatus);
655 } 645 }
656 646
657 let fashTopGoods = _getFashionTopGoodsStatus(uid, showStatus, isBeginSale); 647 let fashTopGoods = _getFashionTopGoodsStatus(uid, showStatus, isBeginSale);
@@ -751,9 +741,6 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -751,9 +741,6 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
751 banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg; 741 banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
752 break; 742 break;
753 } 743 }
754 - default:  
755 - break;  
756 -  
757 } 744 }
758 } 745 }
759 } 746 }
@@ -761,7 +748,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -761,7 +748,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
761 statGoodsInfo.imageUrl = result.img; 748 statGoodsInfo.imageUrl = result.img;
762 statGoodsInfo.productUrl = result.weixinUrl; 749 statGoodsInfo.productUrl = result.weixinUrl;
763 statGoodsInfo.smallSortId = result.smallSortId; 750 statGoodsInfo.smallSortId = result.smallSortId;
764 - statGoodsInfo.soldOut = parseInt(soldOut, 10); 751 + statGoodsInfo.soldOut = parseInt(soldOut);
765 752
766 return { 753 return {
767 goodsInfo: result, 754 goodsInfo: result,
@@ -823,19 +810,13 @@ const _getBasicDescription = (productDescBo) => { @@ -823,19 +810,13 @@ const _getBasicDescription = (productDescBo) => {
823 810
824 switch (productDescBo.gender) { 811 switch (productDescBo.gender) {
825 case 1: 812 case 1:
826 - {  
827 - sex = '男款';  
828 - break;  
829 - } 813 + sex = '男款';
  814 + break;
830 case 2: 815 case 2:
831 - {  
832 - sex = '女款';  
833 - break;  
834 - } 816 + sex = '女款';
  817 + break;
835 default: 818 default:
836 - {  
837 - sex = '通用';  
838 - } 819 + sex = '通用';
839 } 820 }
840 821
841 let basic = []; 822 let basic = [];
@@ -1214,25 +1195,17 @@ const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => { @@ -1214,25 +1195,17 @@ const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => {
1214 switch (maxSortId) { 1195 switch (maxSortId) {
1215 case 1: 1196 case 1:
1216 case 2: 1197 case 2:
1217 - {  
1218 - attributeIds = [3, 4];  
1219 - break;  
1220 - } 1198 + attributeIds = [3, 4];
  1199 + break;
1221 1200
1222 case 3: 1201 case 3:
1223 - {  
1224 - attributeIds = [6, 10];  
1225 - break;  
1226 - } 1202 + attributeIds = [6, 10];
  1203 + break;
1227 case 6: 1204 case 6:
1228 - {  
1229 - attributeIds = [13];  
1230 - break;  
1231 - } 1205 + attributeIds = [13];
  1206 + break;
1232 default: 1207 default:
1233 - {  
1234 - attributeIds = [];  
1235 - } 1208 + attributeIds = [];
1236 } 1209 }
1237 1210
1238 let sizeInfos = []; 1211 let sizeInfos = [];
@@ -1270,9 +1243,9 @@ const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => { @@ -1270,9 +1243,9 @@ const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => {
1270 /** 1243 /**
1271 * 商品尺码信息 1244 * 商品尺码信息
1272 * 1245 *
1273 - * @param string $productSkn  
1274 - * @param int $maxSortId  
1275 - * @return array 1246 + * @param productSkn
  1247 + * @param maxSortId
  1248 + * @return object
1276 */ 1249 */
1277 const _getSizeInfo = (productSkn, maxSortId)=> { 1250 const _getSizeInfo = (productSkn, maxSortId)=> {
1278 let result = {}; 1251 let result = {};
@@ -1323,10 +1296,45 @@ const _getSizeInfo = (productSkn, maxSortId)=> { @@ -1323,10 +1296,45 @@ const _getSizeInfo = (productSkn, maxSortId)=> {
1323 }; 1296 };
1324 1297
1325 /** 1298 /**
  1299 + * 获取seo信息
  1300 + *
  1301 + * @param array $goodsInfo
  1302 + * @param array $navs
  1303 + * @return array
  1304 + */
  1305 +const _getSeoByGoodsInfo = function(goodsInfo, navs) {
  1306 + let title = '';
  1307 + let keywords = '';
  1308 + let brandName = '';
  1309 + let sortName = '';
  1310 + let description = '';
  1311 +
  1312 + if (!_.isEmpty(goodsInfo.brandName)) {
  1313 + title = goodsInfo.brandName + ' ';
  1314 + brandName = goodsInfo.brandName;
  1315 + }
  1316 +
  1317 + if (!_.isEmpty(navs) && navs[1].name) {
  1318 + sortName = navs[1].name;
  1319 + title += navs[1].name + '|';
  1320 + }
  1321 +
  1322 + title += goodsInfo.name + '正品 ';
  1323 + keywords = brandName + sortName + ',' + brandName + '官网专卖店,' + brandName + '官方授权店,' +
  1324 + brandName + '正品,' + brandName + '打折,' + brandName + '折扣店,' + brandName + '真品,' + brandName + '代购';
  1325 + description = !goodsInfo.shareDesc ? goodsInfo.name : goodsInfo.shareDesc;
  1326 +
  1327 + return {
  1328 + title: title,
  1329 + keywords: keywords,
  1330 + description: description
  1331 + };
  1332 +};
  1333 +
  1334 +/**
1326 * 获取某一个商品详情主页面 1335 * 获取某一个商品详情主页面
1327 */ 1336 */
1328 const showMainAsync = data => { 1337 const showMainAsync = data => {
1329 -  
1330 return co(function * () { 1338 return co(function * () {
1331 let result = {}; 1339 let result = {};
1332 let currentUserProductInfo = _.curry(_detailDataPkg)(_, data.uid, data.vipLevel); 1340 let currentUserProductInfo = _.curry(_detailDataPkg)(_, data.uid, data.vipLevel);
@@ -1334,28 +1342,29 @@ const showMainAsync = data => { @@ -1334,28 +1342,29 @@ const showMainAsync = data => {
1334 // 获取商品信息 1342 // 获取商品信息
1335 let productInfo = yield productAPI.getProductAsync(data.pid, data.uid).then(currentUserProductInfo); 1343 let productInfo = yield productAPI.getProductAsync(data.pid, data.uid).then(currentUserProductInfo);
1336 1344
1337 - if (!productInfo || !productInfo.goodsInfo) {  
1338 - return result; 1345 + if (!productInfo || _.isEmpty(productInfo)) {
  1346 + return Promise.reject({
  1347 + code: 404
  1348 + });
1339 } 1349 }
1340 -  
1341 let requestData = yield Promise.all([ 1350 let requestData = yield Promise.all([
1342 _getSortNavAsync(productInfo.goodsInfo.smallSortId, data.gender), 1351 _getSortNavAsync(productInfo.goodsInfo.smallSortId, data.gender),
1343 HeaderModel.requestHeaderData(data.channel) 1352 HeaderModel.requestHeaderData(data.channel)
1344 ]); 1353 ]);
1345 1354
1346 - // 获取商品尺寸相关  
1347 - let sizeInfo = _getSizeInfo(productInfo.goodsInfo, productInfo.goodsInfo.maxSortId);  
1348 -  
1349 // 分类导航 1355 // 分类导航
1350 let navs = requestData[0]; 1356 let navs = requestData[0];
  1357 + const seo = _getSeoByGoodsInfo(productInfo.goodsInfo, navs);
  1358 +
  1359 + result.seo = seo;
1351 1360
1352 - result.headerData = requestData[1]; 1361 + // 获取商品尺寸相关
  1362 + let sizeInfo = _getSizeInfo(productInfo.goodsInfo, productInfo.goodsInfo.maxSortId);
1353 1363
  1364 + result.headerData = requestData[1].headerData;
1354 result.productDetailPage = true; 1365 result.productDetailPage = true;
1355 result.detail = Object.assign(productInfo, sizeInfo); 1366 result.detail = Object.assign(productInfo, sizeInfo);
1356 - result.statGoodsInfo = Object.assign({  
1357 - fullSortName: navs.map(x => x.name).join('-')  
1358 - }, 1367 + result.statGoodsInfo = Object.assign({fullSortName: navs.map(x => x.name).join('-')},
1359 productInfo.statGoodsInfo 1368 productInfo.statGoodsInfo
1360 ); 1369 );
1361 1370
@@ -1374,6 +1383,7 @@ const showMainAsync = data => { @@ -1374,6 +1383,7 @@ const showMainAsync = data => {
1374 1383
1375 module.exports = { 1384 module.exports = {
1376 indexCommentAsync: commentService.indexAsync, // 获取评论列表 1385 indexCommentAsync: commentService.indexAsync, // 获取评论列表
  1386 + getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表
1377 indexConsultAsync: consultService.indexAsync, // 获取咨询列表 1387 indexConsultAsync: consultService.indexAsync, // 获取咨询列表
1378 createConsultAsync: consultService.createAsync, // 添加咨询 1388 createConsultAsync: consultService.createAsync, // 添加咨询
1379 showMainAsync: showMainAsync, // 获取某一个商品详情主页面 1389 showMainAsync: showMainAsync, // 获取某一个商品详情主页面