...
|
...
|
@@ -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) => {
|
...
|
...
|
@@ -51,7 +70,7 @@ const baseShopFav = (req, res) => { |
|
|
listModel.getShopData(req, shopId, uid, isApp).then(result => {
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
collect: result.goBrand && result.goBrand.isFavorite === 'Y' ? true : false,
|
|
|
collect: result.goBrand && result.goBrand.is_favorite === 'Y' ? true : false,
|
|
|
});
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -80,6 +99,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 => {
|
...
|
...
|
@@ -146,7 +172,7 @@ const shopFav = (req, res) => { |
|
|
listModel.getShopFav(req, shopId, uid, isApp).then(result => {
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
collect: result.isFavorite === 'Y',
|
|
|
collect: result.is_favorite === 'Y',
|
|
|
});
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -321,12 +347,34 @@ 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.headers.origin;
|
|
|
|
|
|
if (req.headers.referer) {
|
|
|
let refererSplit = _.split(req.headers.referer, '?');
|
|
|
|
|
|
let shopIdSplit = _.split(refererSplit[1], '&');
|
|
|
let shopId = '';
|
|
|
|
|
|
_.forEach(shopIdSplit, value => {
|
|
|
if (_.startsWith(value, 'shop_id')) {
|
|
|
shopId = value;
|
|
|
return;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
refer = refererSplit[0] + '?' + shopId;
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
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":{},"url":""},"priority":"Y"}}`; // eslint-disable-line
|
|
|
}
|
|
|
|
|
|
if (!id) {
|
...
|
...
|
@@ -399,32 +447,65 @@ 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 (!uid || uid === 'undefined') {
|
|
|
uid = _getUidFromUserAgent(req);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (req.user.uid) {
|
|
|
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.headers.origin;
|
|
|
|
|
|
if (req.headers.referer) {
|
|
|
let refererSplit = _.split(req.headers.referer, '?');
|
|
|
|
|
|
let shopIdSplit = _.split(refererSplit[1], '&');
|
|
|
let shopId = '';
|
|
|
|
|
|
_.forEach(shopIdSplit, value => {
|
|
|
if (_.startsWith(value, 'shop_id')) {
|
|
|
shopId = value;
|
|
|
return;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (req.yoho.isApp) {
|
|
|
toUrl += '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
|
|
|
refer = refererSplit[0] + '?' + shopId;
|
|
|
}
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
...
|
...
|
|