Authored by 郭成尧

'mg-shop-seo'

@@ -38,13 +38,16 @@ const _getUidFromUserAgent = (req) => { @@ -38,13 +38,16 @@ const _getUidFromUserAgent = (req) => {
38 */ 38 */
39 const _baseShop = (req, res, shopInfo, shopId) => { 39 const _baseShop = (req, res, shopInfo, shopId) => {
40 40
41 - listModel.getBaseShopData(req.query, shopInfo).then(result => { 41 + listModel.getBaseShopData(Object.assign(req.query, {
  42 + channel: req.yoho.channel
  43 + }), shopInfo).then(result => {
42 if (result && result.baseShopHome && result.baseShopHome.banner) { 44 if (result && result.baseShopHome && result.baseShopHome.banner) {
43 if (result.baseShopHome.banner.indexOf('?') < 0) { 45 if (result.baseShopHome.banner.indexOf('?') < 0) {
44 result.baseShopHome.banner += '?imageMogr2/auto-orient/strip/thumbnail/x150/crop/640x150'; 46 result.baseShopHome.banner += '?imageMogr2/auto-orient/strip/thumbnail/x150/crop/640x150';
45 } 47 }
46 } 48 }
47 - res.render('search/goods-list', { 49 +
  50 + res.render('search/goods-list', Object.assign({
48 module: 'product', 51 module: 'product',
49 page: 'search-list', 52 page: 'search-list',
50 pageHeader: headerModel.setNav({ 53 pageHeader: headerModel.setNav({
@@ -53,12 +56,9 @@ const _baseShop = (req, res, shopInfo, shopId) => { @@ -53,12 +56,9 @@ const _baseShop = (req, res, shopInfo, shopId) => {
53 goodList: result, 56 goodList: result,
54 showDownloadApp: true, 57 showDownloadApp: true,
55 pageFooter: true, 58 pageFooter: true,
56 - title: shopInfo.shop_name + '|' + shopInfo.shop_name + '潮流服装服饰-Yoho!Buy有货',  
57 - keywords: shopInfo.shop_name + ',' + shopInfo.shop_name + '服装服饰,' + shopInfo.shop_name + '潮流服装服饰',  
58 - description: shopInfo.shop_name + '|Yoho!Buy有货' + shopInfo.shop_name + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',  
59 shopId: shopId, 59 shopId: shopId,
60 shopPage: true 60 shopPage: true
61 - }); 61 + }, result.seoResult));
62 }); 62 });
63 63
64 }; 64 };
@@ -142,19 +142,16 @@ const _shop = (req, res, shopId) => { @@ -142,19 +142,16 @@ const _shop = (req, res, shopId) => {
142 // 有领券功能,不缓存 142 // 有领券功能,不缓存
143 res.set('Cache-Control', 'no-cache'); 143 res.set('Cache-Control', 'no-cache');
144 144
145 - res.render('shop/index', { 145 + res.render('shop/index', Object.assign({
146 module: 'product', 146 module: 'product',
147 page: 'shop', 147 page: 'shop',
148 shopIndex: result, 148 shopIndex: result,
149 shopHeadHide: true, 149 shopHeadHide: true,
150 gender: req.query.gender, 150 gender: req.query.gender,
151 channel: req.query.channel, 151 channel: req.query.channel,
152 - title: result.seoTitle + '|' + result.seoTitle + '潮流服装服饰-Yoho!Buy有货',  
153 - keywords: result.seoTitle + ',' + result.seoTitle + '服装服饰,' + result.seoTitle + '潮流服装服饰',  
154 - description: result.seoTitle + '|Yoho!Buy有货' + result.seoTitle + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',  
155 shopId: shopId, 152 shopId: shopId,
156 shopPage: true 153 shopPage: true
157 - }); 154 + }, result.seoResult));
158 155
159 }); 156 });
160 } 157 }
@@ -273,11 +270,13 @@ const brand = (req, res, next) => { @@ -273,11 +270,13 @@ const brand = (req, res, next) => {
273 if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) { 270 if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) {
274 _shop(req, res, brandLogo.shopId); 271 _shop(req, res, brandLogo.shopId);
275 } else { // 获取品牌店铺信息 272 } else { // 获取品牌店铺信息
276 - listModel.getBrandShops(brandId).then(brandShop => { 273 + listModel.getBrandShops(brandId, req).then(brandShop => {
277 if (brandId === 0) { 274 if (brandId === 0) {
278 params.query = domain; 275 params.query = domain;
279 } 276 }
280 277
  278 + params.seoResult = brandShop.seoResult;
  279 +
281 // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺 280 // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺
282 if (req.query.from === 'search' || brandShop.length > 0) { 281 if (req.query.from === 'search' || brandShop.length > 0) {
283 params = _.assign({ 282 params = _.assign({
@@ -304,7 +303,7 @@ const brand = (req, res, next) => { @@ -304,7 +303,7 @@ const brand = (req, res, next) => {
304 res.set('Cache-Control', 'no-cache'); 303 res.set('Cache-Control', 'no-cache');
305 } 304 }
306 305
307 - res.render('search/goods-list', { 306 + res.render('search/goods-list', Object.assign({
308 module: 'product', 307 module: 'product',
309 page: 'search-list', 308 page: 'search-list',
310 pageHeader: headerModel.setNav({ 309 pageHeader: headerModel.setNav({
@@ -313,12 +312,9 @@ const brand = (req, res, next) => { @@ -313,12 +312,9 @@ const brand = (req, res, next) => {
313 goodList: params, 312 goodList: params,
314 showDownloadApp: true, 313 showDownloadApp: true,
315 pageFooter: true, 314 pageFooter: true,
316 - title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货',  
317 - keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰',  
318 - description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',  
319 domain: req.query.domain, 315 domain: req.query.domain,
320 shopPage: true 316 shopPage: true
321 - }); 317 + }, params.seoResult));
322 }); 318 });
323 } 319 }
324 }).catch(next); 320 }).catch(next);
@@ -51,7 +51,11 @@ const _processBrandShops = (list) => { @@ -51,7 +51,11 @@ const _processBrandShops = (list) => {
51 */ 51 */
52 const _modifyWapUrl = (origin, shopId) => { 52 const _modifyWapUrl = (origin, shopId) => {
53 if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) { 53 if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) {
54 - return helpers.urlFormat('', {filter_poolId: origin.categoryId, shop_id: shopId, title: origin.categoryName}, 'search'); //eslint-disable-line 54 + return helpers.urlFormat('', {
  55 + filter_poolId: origin.categoryId,
  56 + shop_id: shopId,
  57 + title: origin.categoryName
  58 + }, 'search'); //eslint-disable-line
55 } else { 59 } else {
56 if (_.has(origin, 'url')) { 60 if (_.has(origin, 'url')) {
57 return origin.url; 61 return origin.url;
@@ -135,7 +139,71 @@ const _getShopCategory = (shopId, channel, gender) => { @@ -135,7 +139,71 @@ const _getShopCategory = (shopId, channel, gender) => {
135 }; 139 };
136 140
137 /** 141 /**
138 - * TODO TAR 店铺和品牌收藏状态调用新的接口 142 + * 处理店铺或者品牌 seo 数据
  143 + * @param channel
  144 + * @param info
  145 + * @param qs
  146 + * @returns {{}}
  147 + * @private
  148 + */
  149 +const _getBrandShopSeo = (channel, info, qs) => {
  150 +
  151 + let resData = {},
  152 + ctype = {
  153 + boys: {fashionType: '男装', brandType: '男生品牌'},
  154 + girls: {fashionType: '女装', brandType: '女生品牌'},
  155 + kids: {fashionType: '童装', brandType: '潮童品牌'},
  156 + lifestyle: {fashionType: '创意生活', brandType: '创意生活品牌'}
  157 + };
  158 + let params = {
  159 + nameEn: '',
  160 + name: ''
  161 + };
  162 +
  163 +
  164 + if (info) {
  165 + Object.assign(params, {
  166 + nameEn: _.get(info, 'brand_name_en', ''),
  167 + nameCn: _.get(info, 'brand_name_cn', ''),
  168 + name: _.get(info, 'brand_name', '')
  169 + });
  170 + params.name = `${params.nameEn} ${params.nameCn} ${params.name}`;
  171 + if (info.shop_name) {
  172 + Object.assign(params, {
  173 + nameEn: info.shop_name,
  174 + name: info.shop_name
  175 + });
  176 + }
  177 + }
  178 +
  179 + if (qs && qs.gender) {
  180 + if (qs.gender === '1,3') {
  181 + channel = 'boys';
  182 + } else if (qs.gender === '2,3') {
  183 + channel = 'girls';
  184 + }
  185 +
  186 + Object.assign(params, ctype[channel] || ctype.boys);
  187 + Object.assign(resData, {
  188 + title: `${params.nameEn} | ${params.name} ${params.brandType}`,
  189 + keywords: `${params.nameEn}, ${params.name} ${params.fashionType},${params.nameEn} ${params.brandType}`,
  190 + description: `${params.nameEn}正品网购。${params.name}官方授权!`
  191 + });
  192 + } else {
  193 + Object.assign(resData, {
  194 + title: `${params.nameEn} | ${params.name}官网`,
  195 + keywords: `${params.nameEn}, ${params.name}官网`,
  196 + description: `${params.nameEn}正品网购。${params.name}官方授权!`
  197 + });
  198 + }
  199 +
  200 + resData.title += resData.title ? ' | YOHO!有货 100%正品保证' : '';
  201 + resData.description += resData.description ? ' YOHO! 有货中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。' : ''; // eslint-disable-line
  202 + return resData;
  203 +};
  204 +
  205 +/**
  206 + *
139 * 调用接口获取品牌或者店铺的收藏状态 207 * 调用接口获取品牌或者店铺的收藏状态
140 * @private 208 * @private
141 */ 209 */
@@ -436,8 +504,11 @@ const _formShopData = (data, shopId, isApp) => { @@ -436,8 +504,11 @@ const _formShopData = (data, shopId, isApp) => {
436 */ 504 */
437 const getBaseShopData = (params, shopInfo) => { 505 const getBaseShopData = (params, shopInfo) => {
438 506
  507 + /* tar add 161109 seo-info */
  508 + let seoResult = _getBrandShopSeo(params.channel, shopInfo, params);
439 let finalResult = { 509 let finalResult = {
440 - cartUrl: helpers.urlFormat('/cart/index/index') 510 + cartUrl: helpers.urlFormat('/cart/index/index'),
  511 + seoResult: seoResult
441 }; 512 };
442 513
443 let shopId = params.shop_id || shopInfo.shops_id; 514 let shopId = params.shop_id || shopInfo.shops_id;
@@ -490,6 +561,8 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -490,6 +561,8 @@ const getShopData = (req, shopId, uid, isApp) => {
490 561
491 return _getShopInfo(shopId, uid).then(shopInfoResult => { 562 return _getShopInfo(shopId, uid).then(shopInfoResult => {
492 563
  564 + let seoResult = _getBrandShopSeo(channel, shopInfoResult, req.query);
  565 +
493 /* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */ 566 /* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
494 if (shopInfoResult && shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) { 567 if (shopInfoResult && shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) {
495 return { 568 return {
@@ -551,7 +624,8 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -551,7 +624,8 @@ const getShopData = (req, shopId, uid, isApp) => {
551 { 624 {
552 shopId: shopId, 625 shopId: shopId,
553 uid: uid ? crypto.encryption('', uid + '') : '', 626 uid: uid ? crypto.encryption('', uid + '') : '',
554 - coverChannel: channel 627 + coverChannel: channel,
  628 + seoResult: seoResult
555 } 629 }
556 ); 630 );
557 }); 631 });
@@ -662,9 +736,10 @@ const getBrandLogoByDomain = (domain) => { @@ -662,9 +736,10 @@ const getBrandLogoByDomain = (domain) => {
662 /** 736 /**
663 * 根据brandId 获取相关店铺列表 737 * 根据brandId 获取相关店铺列表
664 * @param brandId 738 * @param brandId
  739 + * @param req
665 * @return array 740 * @return array
666 */ 741 */
667 -const getBrandShops = (brandId) => { 742 +const getBrandShops = (brandId, req) => {
668 return api.get('', { 743 return api.get('', {
669 method: 'app.shop.queryShopsByBrandId', 744 method: 'app.shop.queryShopsByBrandId',
670 brand_id: brandId 745 brand_id: brandId
@@ -673,7 +748,9 @@ const getBrandShops = (brandId) => { @@ -673,7 +748,9 @@ const getBrandShops = (brandId) => {
673 cache: true 748 cache: true
674 }).then(result => { 749 }).then(result => {
675 if (_.isArray(result.data)) { 750 if (_.isArray(result.data)) {
676 - return _processBrandShops(result.data); 751 + let seoResult = _getBrandShopSeo(req.channel, result.data[0], req.query);
  752 +
  753 + return Object.assign(_processBrandShops(result.data), {seoResult: seoResult});
677 } else { 754 } else {
678 return []; 755 return [];
679 } 756 }
@@ -784,9 +861,8 @@ const getShopCategory = (params) => { @@ -784,9 +861,8 @@ const getShopCategory = (params) => {
784 861
785 /** 862 /**
786 * 获取店铺优惠券列表 863 * 获取店铺优惠券列表
787 - * @param {[int]} shop_id 店铺id  
788 - * @param {[int]} uid 当前用户id,空则不传  
789 * @return {[array]} 864 * @return {[array]}
  865 + * @param params
790 */ 866 */
791 const shopCouponsList = (params) => { 867 const shopCouponsList = (params) => {
792 return api.get('', Object.assign({ 868 return api.get('', Object.assign({