...
|
...
|
@@ -15,6 +15,25 @@ const helpers = global.yoho.helpers; |
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
|
|
|
/**
|
|
|
* 从 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 _baseShop = (req, res, shopInfo, shopId) => {
|
...
|
...
|
@@ -30,9 +49,9 @@ const _baseShop = (req, res, shopInfo, shopId) => { |
|
|
goodList: result,
|
|
|
showDownloadApp: true,
|
|
|
pageFooter: true,
|
|
|
title: shopInfo.shopName + '|' + shopInfo.shopName + '潮流服装服饰-Yoho!Buy有货',
|
|
|
keywords: shopInfo.shopName + ',' + shopInfo.shopName + '服装服饰,' + shopInfo.shopName + '潮流服装服饰',
|
|
|
description: shopInfo.shopName + '|Yoho!Buy有货' + shopInfo.shopName + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
|
|
|
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
|
|
|
});
|
...
|
...
|
@@ -44,8 +63,14 @@ const _baseShop = (req, res, shopInfo, shopId) => { |
|
|
* 基础模板收藏
|
|
|
*/
|
|
|
const baseShopFav = (req, res) => {
|
|
|
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 isApp = req.query.app_version || req.query.appVersion || false;
|
|
|
let uid = isApp ? req.query.uid : req.user.uid;
|
|
|
let uid = req.user.uid || req.query.uid || req.cookies.appUid || _getUidFromUserAgent(req);
|
|
|
let shopId = req.query.shopId;
|
|
|
|
|
|
listModel.getShopData(req, shopId, uid, isApp).then(result => {
|
...
|
...
|
@@ -80,6 +105,13 @@ const _shop = (req, res, shopId) => { |
|
|
navTitle: false
|
|
|
}))
|
|
|
};
|
|
|
} else {
|
|
|
uid = req.query.uid;
|
|
|
req.session.appUid = uid;
|
|
|
res.cookie('appUid', uid, {
|
|
|
domain: 'yohobuy.com',
|
|
|
expires: new Date(Date.now() + 2592000000) // 有效期一年
|
|
|
});
|
|
|
}
|
|
|
|
|
|
listModel.getShopData(req, shopId, uid, isApp).then(result => {
|
...
|
...
|
@@ -90,7 +122,7 @@ const _shop = (req, res, shopId) => { |
|
|
} else {
|
|
|
listModel.searchProductBySkn(result.hotListproductSkn).then(hotList => {
|
|
|
result = _.assign(result, pageHeader, {
|
|
|
hotList: productProcess.processProductList(hotList)
|
|
|
hotList: productProcess.processProductList(hotList, {isApp: isApp})
|
|
|
});
|
|
|
|
|
|
_.forEach(result.hotList, (value, key) => {
|
...
|
...
|
@@ -106,9 +138,9 @@ const _shop = (req, res, shopId) => { |
|
|
shopHeadHide: true,
|
|
|
gender: req.query.gender,
|
|
|
channel: req.query.channel,
|
|
|
title: result.storeName + '|' + result.storeName + '潮流服装服饰-Yoho!Buy有货',
|
|
|
keywords: result.storeName + ',' + result.storeName + '服装服饰,' + result.storeName + '潮流服装服饰',
|
|
|
description: result.storeName + '|Yoho!Buy有货' + result.storeName + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
|
|
|
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
|
|
|
});
|
...
|
...
|
@@ -122,6 +154,12 @@ const _shop = (req, res, shopId) => { |
|
|
* app设置cookie
|
|
|
*/
|
|
|
const shopAppCookie = (req, res) => {
|
|
|
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.query.uid;
|
|
|
|
|
|
req.session.appUid = uid;
|
...
|
...
|
@@ -139,14 +177,20 @@ const shopAppCookie = (req, res) => { |
|
|
* 前端请求判断shop是否收藏
|
|
|
*/
|
|
|
const shopFav = (req, res) => {
|
|
|
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 isApp = req.query.app_version || req.query.appVersion || false;
|
|
|
let uid = isApp ? req.query.uid : req.user.uid;
|
|
|
let uid = req.user.uid || req.query.uid || req.cookies.appUid || _getUidFromUserAgent(req);
|
|
|
let shopId = req.query.shopId;
|
|
|
|
|
|
listModel.getShopFav(req, shopId, uid, isApp).then(result => {
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
collect: result.is_favorite === 'Y',
|
|
|
collect: _.get(result, 'is_favorite', '') === 'Y'
|
|
|
});
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -206,7 +250,7 @@ const brand = (req, res, next) => { |
|
|
}, params);
|
|
|
|
|
|
// 无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面
|
|
|
if (brandLogo.type === '2' && brandLogo.shopId) {
|
|
|
if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) {
|
|
|
_shop(req, res, brandLogo.shopId);
|
|
|
} else { // 获取品牌店铺信息
|
|
|
listModel.getBrandShops(brandId).then(brandShop => {
|
...
|
...
|
@@ -321,12 +365,19 @@ const favoriteBrand = (req, res, next) => { |
|
|
let opt = req.query.opt || 'ok';
|
|
|
let type = req.query.type || 'product';
|
|
|
let appVersion = req.query.appVersion || false;
|
|
|
let refer = req.get('Referer') || `${global.yoho.config.siteUrl}/${req.cookies._Channel || ''}`;
|
|
|
let refer = req.get('referer');
|
|
|
|
|
|
let url = helpers.urlFormat('/signin.html') + '?refer=' + refer;
|
|
|
|
|
|
if (appVersion === 'true') {
|
|
|
uid = req.cookies.appUid;
|
|
|
url = `${url}&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":${decodeURI(req.cookies.refer)},"param":{}},"requesturl":{"param":{},"url":""},"priority":"Y"}}`; // eslint-disable-line
|
|
|
if (appVersion && appVersion !== 'false') {
|
|
|
uid = req.query.uid ? crypto.decrypt('', req.query.uid) : req.cookies.appUid;
|
|
|
|
|
|
if (!uid || uid === 'undefined') {
|
|
|
uid = _getUidFromUserAgent(req);
|
|
|
}
|
|
|
|
|
|
url = `${refer}&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"${refer}","param":{}},"requesturl":{"param":{"method":"app.favorite.add","id":"${id}","fav_id":"${id}","type":"shop"},"url":"${_.get(global, 'yoho.API.ApiUrl', '')}"},"priority":"Y"}}`; // eslint-disable-line
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!id) {
|
...
|
...
|
@@ -399,32 +450,49 @@ const userCoupon = (req, res, next) => { |
|
|
}
|
|
|
|
|
|
let cryptCouponId = crypto.decrypt('', req.query.couponID);
|
|
|
let uid = req.user.uid;
|
|
|
|
|
|
if (req.yoho.isApp !== 'false') {
|
|
|
uid = req.query.uid ? crypto.decrypt('', req.query.uid) : req.cookies.appUid;
|
|
|
|
|
|
if (req.user.uid) {
|
|
|
if (!uid || uid === 'undefined') {
|
|
|
uid = _getUidFromUserAgent(req);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (uid) {
|
|
|
listModel.receiveCoupon(
|
|
|
req.user.uid,
|
|
|
uid,
|
|
|
cryptCouponId
|
|
|
).then(result => {
|
|
|
res.json(result);
|
|
|
return;
|
|
|
}).catch(next);
|
|
|
} else {
|
|
|
let refer = req.headers.referer || req.headers.origin;
|
|
|
let toUrl = helpers.urlFormat('/signin.html', {refer: refer});
|
|
|
let refer = req.get('referer');
|
|
|
|
|
|
if (req.yoho.isApp) {
|
|
|
toUrl += '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
|
|
|
if (req.yoho.isApp !== 'false') {
|
|
|
let toUrl = refer + '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
|
|
|
refer +
|
|
|
'","param":{}},"requesturl":{"param":{"method":"app.promotion.getCoupon","couponId":"' +
|
|
|
cryptCouponId +
|
|
|
'"},"url":"' +
|
|
|
_.get(global, 'yoho.API.ApiUrl', '') +
|
|
|
'"},"priority":"Y"}}';
|
|
|
|
|
|
res.json({
|
|
|
code: 4401,
|
|
|
url: toUrl
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: 4401,
|
|
|
url: helpers.urlFormat('/signin.html', {refer: refer})
|
|
|
});
|
|
|
}
|
|
|
|
|
|
res.json({
|
|
|
code: 4401,
|
|
|
url: toUrl
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
...
|
...
|
|