Authored by 郭成尧

'shop-brand-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,13 @@ const _baseShop = (req, res, shopInfo, shopId) => { @@ -53,12 +56,13 @@ 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 +
  60 + // title: shopInfo.shop_name + '|' + shopInfo.shop_name + '潮流服装服饰-Yoho!Buy有货',
  61 + // keywords: shopInfo.shop_name + ',' + shopInfo.shop_name + '服装服饰,' + shopInfo.shop_name + '潮流服装服饰',
  62 + // description: shopInfo.shop_name + '|Yoho!Buy有货' + shopInfo.shop_name + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
59 shopId: shopId, 63 shopId: shopId,
60 shopPage: true 64 shopPage: true
61 - }); 65 + }, result.seoResult));
62 }); 66 });
63 67
64 }; 68 };
@@ -142,19 +146,20 @@ const _shop = (req, res, shopId) => { @@ -142,19 +146,20 @@ const _shop = (req, res, shopId) => {
142 // 有领券功能,不缓存 146 // 有领券功能,不缓存
143 res.set('Cache-Control', 'no-cache'); 147 res.set('Cache-Control', 'no-cache');
144 148
145 - res.render('shop/index', { 149 + res.render('shop/index', Object.assign({
146 module: 'product', 150 module: 'product',
147 page: 'shop', 151 page: 'shop',
148 shopIndex: result, 152 shopIndex: result,
149 shopHeadHide: true, 153 shopHeadHide: true,
150 gender: req.query.gender, 154 gender: req.query.gender,
151 channel: req.query.channel, 155 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%品牌正品保证,支持货到付款。', 156 +
  157 + // title: result.seoTitle + '|' + result.seoTitle + '潮流服装服饰-Yoho!Buy有货',
  158 + // keywords: result.seoTitle + ',' + result.seoTitle + '服装服饰,' + result.seoTitle + '潮流服装服饰',
  159 + // description: result.seoTitle + '|Yoho!Buy有货' + result.seoTitle + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
155 shopId: shopId, 160 shopId: shopId,
156 shopPage: true 161 shopPage: true
157 - }); 162 + }, result.seoResult));
158 163
159 }); 164 });
160 } 165 }
@@ -272,11 +277,13 @@ const brand = (req, res, next) => { @@ -272,11 +277,13 @@ const brand = (req, res, next) => {
272 if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) { 277 if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) {
273 _shop(req, res, brandLogo.shopId); 278 _shop(req, res, brandLogo.shopId);
274 } else { // 获取品牌店铺信息 279 } else { // 获取品牌店铺信息
275 - listModel.getBrandShops(brandId).then(brandShop => { 280 + listModel.getBrandShops(brandId, req).then(brandShop => {
276 if (brandId === 0) { 281 if (brandId === 0) {
277 params.query = domain; 282 params.query = domain;
278 } 283 }
279 284
  285 + params.seoResult = brandShop.seoResult;
  286 +
280 // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺 287 // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺
281 if (req.query.from === 'search' || brandShop.length > 0) { 288 if (req.query.from === 'search' || brandShop.length > 0) {
282 params = _.assign({ 289 params = _.assign({
@@ -303,7 +310,7 @@ const brand = (req, res, next) => { @@ -303,7 +310,7 @@ const brand = (req, res, next) => {
303 res.set('Cache-Control', 'no-cache'); 310 res.set('Cache-Control', 'no-cache');
304 } 311 }
305 312
306 - res.render('search/goods-list', { 313 + res.render('search/goods-list', Object.assign({
307 module: 'product', 314 module: 'product',
308 page: 'search-list', 315 page: 'search-list',
309 pageHeader: headerModel.setNav({ 316 pageHeader: headerModel.setNav({
@@ -312,12 +319,13 @@ const brand = (req, res, next) => { @@ -312,12 +319,13 @@ const brand = (req, res, next) => {
312 goodList: params, 319 goodList: params,
313 showDownloadApp: true, 320 showDownloadApp: true,
314 pageFooter: true, 321 pageFooter: true,
315 - title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货',  
316 - keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰',  
317 - description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。', 322 +
  323 + // title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货',
  324 + // keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰',
  325 + // description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
318 domain: req.query.domain, 326 domain: req.query.domain,
319 shopPage: true 327 shopPage: true
320 - }); 328 + }, params.seoResult));
321 }); 329 });
322 } 330 }
323 }).catch(next); 331 }).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;
@@ -175,6 +179,70 @@ const _shopCouponsList = (shopId, uid) => { @@ -175,6 +179,70 @@ const _shopCouponsList = (shopId, uid) => {
175 }; 179 };
176 180
177 /** 181 /**
  182 + * 处理店铺或者品牌 seo 数据
  183 + * @param channel
  184 + * @param info
  185 + * @param qs
  186 + * @returns {{}}
  187 + * @private
  188 + */
  189 +const _getBrandShopSeo = (channel, info, qs) => {
  190 +
  191 + let resData = {},
  192 + ctype = {
  193 + boys: {fashionType: '男装', brandType: '男生品牌'},
  194 + girls: {fashionType: '女装', brandType: '女生品牌'},
  195 + kids: {fashionType: '童装', brandType: '潮童品牌'},
  196 + lifestyle: {fashionType: '创意生活', brandType: '创意生活品牌'}
  197 + };
  198 + let params = {
  199 + nameEn: '',
  200 + name: ''
  201 + };
  202 +
  203 +
  204 + if (info) {
  205 + Object.assign(params, {
  206 + nameEn: _.get(info, 'brand_name_en', ''),
  207 + nameCn: _.get(info, 'brand_name_cn', ''),
  208 + name: _.get(info, 'brand_name', '')
  209 + });
  210 + params.name = `${params.nameEn} ${params.nameCn} ${params.name}`;
  211 + if (info.shop_name) {
  212 + Object.assign(params, {
  213 + nameEn: info.shop_name,
  214 + name: info.shop_name
  215 + });
  216 + }
  217 + }
  218 +
  219 + if (qs && qs.gender) {
  220 + if (qs.gender === '1,3') {
  221 + channel = 'boys';
  222 + } else if (qs.gender === '2,3') {
  223 + channel = 'girls';
  224 + }
  225 +
  226 + Object.assign(params, ctype[channel] || ctype.boys);
  227 + Object.assign(resData, {
  228 + title: `${params.nameEn} | ${params.name} ${params.brandType}`,
  229 + keywords: `${params.nameEn}, ${params.name} ${params.fashionType},${params.nameEn} ${params.brandType}`,
  230 + description: `${params.nameEn}正品网购。${params.name}官方授权!`
  231 + });
  232 + } else {
  233 + Object.assign(resData, {
  234 + title: `${params.nameEn} | ${params.name}官网`,
  235 + keywords: `${params.nameEn}, ${params.name}官网`,
  236 + description: `${params.nameEn}正品网购。${params.name}官方授权!`
  237 + });
  238 + }
  239 +
  240 + resData.title += resData.title ? ' | YOHO!有货 100%正品保证' : '';
  241 + resData.description += resData.description ? ' YOHO! 有货中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。' : ''; // eslint-disable-line
  242 + return resData;
  243 +};
  244 +
  245 +/**
178 * TODO TAR 店铺和品牌收藏状态调用新的接口 246 * TODO TAR 店铺和品牌收藏状态调用新的接口
179 * 调用接口获取品牌或者店铺的收藏状态 247 * 调用接口获取品牌或者店铺的收藏状态
180 * @private 248 * @private
@@ -476,8 +544,11 @@ const _formShopData = (data, shopId, isApp) => { @@ -476,8 +544,11 @@ const _formShopData = (data, shopId, isApp) => {
476 */ 544 */
477 const getBaseShopData = (params, shopInfo) => { 545 const getBaseShopData = (params, shopInfo) => {
478 546
  547 + /* tar add 161109 seo-info */
  548 + let seoResult = _getBrandShopSeo(params.channel, shopInfo, params);
479 let finalResult = { 549 let finalResult = {
480 - cartUrl: helpers.urlFormat('/cart/index/index') 550 + cartUrl: helpers.urlFormat('/cart/index/index'),
  551 + seoResult: seoResult
481 }; 552 };
482 553
483 let shopId = params.shop_id || shopInfo.shops_id; 554 let shopId = params.shop_id || shopInfo.shops_id;
@@ -530,6 +601,8 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -530,6 +601,8 @@ const getShopData = (req, shopId, uid, isApp) => {
530 601
531 return _getShopInfo(shopId, uid).then(shopInfoResult => { 602 return _getShopInfo(shopId, uid).then(shopInfoResult => {
532 603
  604 + let seoResult = _getBrandShopSeo(channel, shopInfoResult, req.query);
  605 +
533 /* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */ 606 /* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
534 if (shopInfoResult && shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) { 607 if (shopInfoResult && shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) {
535 return { 608 return {
@@ -596,7 +669,8 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -596,7 +669,8 @@ const getShopData = (req, shopId, uid, isApp) => {
596 uid: uid ? crypto.encryption('', uid + '') : '', 669 uid: uid ? crypto.encryption('', uid + '') : '',
597 coverChannel: channel, 670 coverChannel: channel,
598 shopCoupons: shopCoupons, 671 shopCoupons: shopCoupons,
599 - shopCouponsOne: shopCoupons.length === 1 672 + shopCouponsOne: shopCoupons.length === 1,
  673 + seoResult: seoResult
600 } 674 }
601 ); 675 );
602 }); 676 });
@@ -707,9 +781,10 @@ const getBrandLogoByDomain = (domain) => { @@ -707,9 +781,10 @@ const getBrandLogoByDomain = (domain) => {
707 /** 781 /**
708 * 根据brandId 获取相关店铺列表 782 * 根据brandId 获取相关店铺列表
709 * @param brandId 783 * @param brandId
  784 + * @param req
710 * @return array 785 * @return array
711 */ 786 */
712 -const getBrandShops = (brandId) => { 787 +const getBrandShops = (brandId, req) => {
713 return api.get('', { 788 return api.get('', {
714 method: 'app.shop.queryShopsByBrandId', 789 method: 'app.shop.queryShopsByBrandId',
715 brand_id: brandId 790 brand_id: brandId
@@ -718,7 +793,9 @@ const getBrandShops = (brandId) => { @@ -718,7 +793,9 @@ const getBrandShops = (brandId) => {
718 cache: true 793 cache: true
719 }).then(result => { 794 }).then(result => {
720 if (_.isArray(result.data)) { 795 if (_.isArray(result.data)) {
721 - return _processBrandShops(result.data); 796 + let seoResult = _getBrandShopSeo(req.channel, result.data[0], req.query);
  797 +
  798 + return Object.assign(_processBrandShops(result.data), {seoResult: seoResult});
722 } else { 799 } else {
723 return []; 800 return [];
724 } 801 }