Authored by 郭成尧

Merge branch 'release/newSearch'

... ... @@ -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 = '';
if (req.yoho.isApp) {
toUrl += '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
_.forEach(shopIdSplit, value => {
if (_.startsWith(value, 'shop_id')) {
shopId = value;
return;
}
});
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})
});
}
}
};
... ...
... ... @@ -182,7 +182,7 @@ const receiveCoupon = (uid, couponId) => {
method: 'app.promotion.getCoupon',
couponId: couponId,
uid: uid
}, {code: 200}).then(result => {
}).then(result => {
return result;
});
};
... ... @@ -500,7 +500,7 @@ const getShopData = (req, shopId, uid, isApp) => {
return _getShopInfo(shopId, uid).then(shopInfoResult => {
/* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
if (shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) {
if (shopInfoResult && shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) {
return {
goBrand: shopInfoResult
};
... ... @@ -547,6 +547,7 @@ const getShopData = (req, shopId, uid, isApp) => {
shopFilterSearchData,
{
shopId: shopId,
uid: uid ? crypto.encryption('', uid + '') : '',
coverChannel: channel,
shopCoupons: shopCoupons,
shopCouponsOne: shopCoupons.length === 1
... ...
... ... @@ -10,6 +10,7 @@
<input type="hidden" name="brand" value="{{brand}}">
<input type="hidden" name="favId" value="{{favId}}">
<input type="hidden" name="coverChannel" value="{{coverChannel}}">
<input type="hidden" name="uid" value="{{uid}}">
{{#unless appVersion}}
<div class="search-area">
... ...
... ... @@ -2,7 +2,8 @@ var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper'),
tip = require('../../plugin/tip');
var appVersion = $('input[name="app_version"]').val();
var appVersion = $('input[name="app_version"]').val(),
uid = $('input[name="uid"]').val();
$('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function() {
var that = this,
... ... @@ -19,7 +20,8 @@ $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function(
url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
data: {
couponID: code,
app_version: appVersion
app_version: appVersion,
uid: uid
},
xhrFields: {
withCredentials: true
... ...
... ... @@ -36,6 +36,7 @@ var $subNav = $('.home-sub-nav'),
brand = $('input[name="brand"]').val(),
coverChannel = $('input[name="coverChannel"]').val(),
favId = $('input[name="favId"]').val();
uid = $('input[name="uid"]').val();
var winH = $(window).height(),
noResult = '<p class="no-result">未找到相关搜索结果</p>';
... ... @@ -916,8 +917,8 @@ $nav2.on('touchstart', 'li', function(e) {
// // stopPropagation(e);
// });
$('#shop-category').click(function () {
let subGroup = $('.sub-group');
$('#shop-category').click(function() {
var subGroup = $('.sub-group');
if (subGroup.hasClass('hide')) {
$('.sub-group').removeClass('hide');
... ... @@ -948,7 +949,8 @@ $collect.on('touchstart', function() {
id: favId ? favId : shopId,
appVersion: appVersion,
opt: opt,
type: 'shop'
type: 'shop',
uid: uid
},
xhrFields: {
withCredentials: true
... ...