Authored by 郭成尧

del-base-shop

... ... @@ -15,26 +15,6 @@ const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
const redShopPrcs = require(`${utils}/redshop-process`);
const co = require('bluebird').coroutine;
const tdk = require('../../../utils/getTDK');
/**
* 从 useragent 获取 uid
* @returns {*}
* @private
*/
const _getUidFromUserAgent = (req) => {
let userAgent = _.split(req.headers['user-agent'], ';');
let uidString = '';
_.forEach(userAgent, value => {
if (_.startsWith(value, 'uid')) {
uidString = value;
return;
}
});
return _.split(uidString, '=')[1];
};
const shop = {
... ... @@ -74,350 +54,6 @@ const shop = {
}
})().catch(next);
},
index(req, res, next) {
let params = Object.assign({}, req.query);
let domain = req.query.domain;
let brandId = 0;
let brandLogo = {};
let title = '';
let uid = req.user.uid || 0;
let shopEnter;
if (req.query.shop_id) {
return shop.shop(req, res, next);
}
if (!domain) {
res.redirect('/?go=1');
return;
}
listModel.getBrandLogoByDomain(domain).then(result => {
if (!result) {
return next();
}
brandLogo = result;
return co(function*() {
title = brandLogo.name;
if (brandLogo && brandLogo.id) {
brandId = brandLogo.id;
}
if (brandLogo && brandLogo.shopId) {
let TDKObj = yield tdk('shop', brandLogo.shopId, req);
if (TDKObj[0]) {
req.tdk = {
title: TDKObj[1],
keywords: TDKObj[2],
description: TDKObj[3]
};
}
}
params.brand = brandId;
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.brand","params":{"brand_id":"${brandId}"}}`;
let searchParam = Object.assign({
isApp: req.yoho.isApp,
brand: brandId,
type: 'default',
order: '0',
page: 1,
limit: 4,
}, params);
if (uid) {
searchParam.uid = uid;
}
if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) {
req.query.shop_id = brandLogo.shopId;
shop.shop(req, res, next);
return false;
} else if (req.query.from === 'search') {
return Promise.all([
listModel.getBrandShops(brandLogo.brandDomain, req),
searchModel.getSearchData(searchParam)
]).then(shopResult => {
let brandShop = shopResult[0];
let newGoods = shopResult[1];
params.newGoods = newGoods.list || [];
params.suggestion = newGoods.suggestion || [];
// 推荐词条件判断 redmine: 18567
if (params.suggestion && params.suggestion.isNeedSuggestion &&
params.suggestion.termsSuggestion.length) {
params.newquery = params.suggestion.termsSuggestion[0].name;
}
if (brandId === 0) {
params.query = domain;
}
if (req.query.app_type && parseInt(req.query.app_type, 10) === 1) {
shopEnter = false;
} else {
shopEnter = true;
}
if (brandShop.length > 0 || brandLogo && shopEnter) {
params = _.assign({
brandWay: _.isEmpty(brandShop) ? brandLogo : brandShop,
search: {
default: req.query.query || req.query.domain,
url: helpers.urlFormat('', null, 'search')
}
}, params);
}
return true;
});
} else {
params.brandHome = {
title: result.name,
id: result.id
};
return Promise.all([
listModel.getBrandBanner(brandId),
searchModel.getSearchData(searchParam)
]).then(brandResult => {
let brandBanner = brandResult[0];
let newGoods = brandResult[1];
if (!brandBanner || !newGoods) {
res.set('Cache-Control', 'no-cache');
}
// 品牌没有 Banner 整个头部不显示
if (!brandBanner) {
params.brandHome = null;
} else {
params.brandHome.banner = brandBanner;
}
params.newGoods = newGoods.list;
return true;
});
}
})();
}).then((isBrand) => {
if (isBrand) {
params.isBrand = isBrand;
res.render('newshop/brand', {
module: 'product',
page: 'brand-index',
pageHeader: headerModel.setNav({
navTitle: title !== '' ? title : domain
}),
brandInfo: params.brandHome,
newGoods: params.newGoods,
suggestion: params.suggestion || [],
showDownloadApp: true,
pageFooter: true,
title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货',
keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰',
description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
domain: req.query.domain,
shopPage: true,
_noLazy: true,
localCss: true
});
}
}).catch(next);
},
shop(req, res, next) {
let isApp = req.query.app_version || req.query.appVersion || false;
let shopId = req.query.shop_id;
let uid = req.user.uid || req.query.uid;
let channel = req.yoho.channel || 'boys';
let pageHeader = {};
let appType = req.query.app_type;
// pagecache前端判断
if (!isApp) {
pageHeader = {
pageHeader: _.assign({
shopPage: {
text: '分类',
url: helpers.urlFormat('/product/index/category', {
shop_id: shopId
})
}
}, headerModel.setNav({
navTitle: false
}))
};
}
return listModel.getShopIntro(shopId).then(shopInfoResult => {
let searchParam = {
isApp: req.yoho.isApp,
shop_id: shopId,
app_type: appType,
type: 'default',
order: '0',
page: 1,
limit: 4
};
let shopInfo = shopInfoResult;
let seoResult = listModel.getBrandShopSeo(channel, shopInfoResult, req.query);
if (uid) {
searchParam.uid = uid;
}
/* 红人店铺直接跳转 */
if (shopInfoResult && shopInfoResult.is_red_shop) {
shop.redShop(req, res, next);
return false;
}
// Hi Here
/* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
if (shopInfoResult && shopInfoResult.shop_template_type) {
if (parseInt(shopInfoResult.shop_template_type, 10) === 1) {
return Promise.all([
listModel.getBaseShopData(req.query, shopInfo),
searchModel.getSearchData(searchParam)
]).then(fResult => {
let baseShop = fResult[0];
let newGoods = fResult[1];
baseShop.newGoods = newGoods.list;
if (baseShop && baseShop.baseShopHome && baseShop.baseShopHome.banner) {
if (baseShop.baseShopHome.banner.indexOf('?') < 0) {
baseShop.baseShopHome.banner +=
'?imageMogr2/auto-orient/strip/thumbnail/x150/crop/640x150';
}
}
let appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.shop","params":{"shop_template_type":"1","shop_id":"' +
shopId + '","shop_name":"' + shopInfo.shop_name + '"}}';
if (shopInfoResult.is_red_shop === 1) {
appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.shop","params":{"shop_template_type":"1","is_red_shop":"1","shop_id":"' +
shopId + '","shop_name":"' + shopInfo.shop_name + '"}}';
}
if (shopId) {
baseShop.shopId = shopId;
}
res.render('newshop/shop-base', {
module: 'product',
page: 'shop.base',
pageHeader: headerModel.setNav({
navTitle: shopInfo.shop_name
}),
goodList: baseShop,
showDownloadApp: true,
pageFooter: true,
title: shopInfo.shop_name + '|' + shopInfo.shop_name + '潮流服装服饰-Yoho!Buy有货',
keywords: shopInfo.shop_name + ',' + shopInfo.shop_name + '服装服饰,' +
shopInfo.shop_name + '潮流服装服饰',
description: shopInfo.shop_name + '|Yoho!Buy有货' + shopInfo.shop_name +
'潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
shopPage: true,
_noLazy: true,
appPath: appPath,
localCss: true
});
});
} else if (parseInt(shopInfoResult.shop_template_type, 10) === 2) {
// 经典装修店铺
return Promise.all([
listModel.getShopDecorator(shopId).then(),
listModel.getShopCategoryApi(shopId, channel)
]).then(fResult => {
let shopDeco = fResult[0];
let shopCategory = fResult[1];
let shopData = {
decorator: shopDeco, // 店铺装修资源数据
shopInfo: shopInfo, // 店铺信息
shopCategory: shopCategory
};
let result = listModel.formShopData(shopData, shopId, isApp);
result = _.assign(result, pageHeader,
{shopId: shopId, coverChannel: channel, seoResult: seoResult});
res.render('newshop/shop-classics', {
module: 'product',
page: 'shop.classics',
shopIndex: result,
shopHeadHide: true,
gender: req.query.gender,
channel: req.query.channel,
title: result.seoTitle + '|' + result.seoTitle + '潮流服装服饰-Yoho!Buy有货',
keywords: result.seoTitle + ',' + result.seoTitle + '服装服饰,' + result.seoTitle + '潮流服装服饰',
description: result.seoTitle + '|Yoho!Buy有货' + result.seoTitle +
'潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
shopPage: true,
appPath: 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.shop","params":{"shop_template_type":"2","shop_id":"' +
shopId + '","shop_name":"' + result.seoTitle + '"}}',
localCss: true,
isMarsApp: req.yoho.isMarsApp
});
});
} else {
shop.redShop(req, res, next);
}
} else {
shop.redShop(req, res, next);
}
}).catch(next);
},
_getUidFromUserAgent(req) {
let userAgent = _.split(req.headers['user-agent'], ';');
let uidString = '';
_.forEach(userAgent, value => {
if (_.startsWith(value, 'uid')) {
uidString = value;
return;
}
});
return _.split(uidString, '=')[1];
},
/**
*
* 基础模板收藏
*/
baseShopFav(req, res, next) {
let allowOrigin = _.get(req, 'headers.origin', null) ?
req.headers.origin : req.protocol + '://' + req.headers.host;
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
let uid = req.user.uid || req.query.uid || _getUidFromUserAgent(req);
let shopId = req.query.shopId;
return listModel.getShopIntro(shopId, uid).then(result => {
res.json(Object.assign({code: 200}, result));
}).catch(next);
},
/**
* 店铺和品牌收藏
... ...
... ... @@ -132,22 +132,6 @@ ellipsis.init();
tip.show('网络断开连接了~');
}
});
} else if ($('.shopId').val() && $('.shopId').val() !== 'undefined') {
$.ajax({
url: '/product/index/baseShopFav',
data: {
shopId: $('.shopId').val()
},
dataType: 'json',
success: function(data) {
if (data.collect) {
$('.brand-header .btn-col').addClass('coled');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
}());
... ...
... ... @@ -112,23 +112,6 @@ C_ID = window._ChannelVary[window.cookie('_Channel')];
tip.show('网络断开连接了~');
}
});
} else if ($('.shopId').val().length > 0) {
$.ajax({
url: '/product/index/baseShopFav',
data: {
shopId: $('.shopId').val()
},
dataType: 'json',
success: function(data) {
if (data.is_favorite === 'Y') {
$('.brand-header .btn-col').addClass('coled');
}
$('.con').html(data.shop_intro);
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
}());
... ...