Authored by 郭成尧

Merge branch 'release/newSearch'

@@ -15,6 +15,25 @@ const helpers = global.yoho.helpers; @@ -15,6 +15,25 @@ const helpers = global.yoho.helpers;
15 const productProcess = require(`${utils}/product-process`); 15 const productProcess = require(`${utils}/product-process`);
16 16
17 /** 17 /**
  18 + * 从 useragent 获取 uid
  19 + * @returns {*}
  20 + * @private
  21 + */
  22 +const _getUidFromUserAgent = (req) => {
  23 + let userAgent = _.split(req.headers['user-agent'], ';');
  24 + let uidString = '';
  25 +
  26 + _.forEach(userAgent, value => {
  27 + if (_.startsWith(value, 'uid')) {
  28 + uidString = value;
  29 + return;
  30 + }
  31 + });
  32 +
  33 + return _.split(uidString, '=')[1];
  34 +};
  35 +
  36 +/**
18 * 店铺 - 基础模板 37 * 店铺 - 基础模板
19 */ 38 */
20 const _baseShop = (req, res, shopInfo, shopId) => { 39 const _baseShop = (req, res, shopInfo, shopId) => {
@@ -51,7 +70,7 @@ const baseShopFav = (req, res) => { @@ -51,7 +70,7 @@ const baseShopFav = (req, res) => {
51 listModel.getShopData(req, shopId, uid, isApp).then(result => { 70 listModel.getShopData(req, shopId, uid, isApp).then(result => {
52 res.json({ 71 res.json({
53 code: 200, 72 code: 200,
54 - collect: result.goBrand && result.goBrand.isFavorite === 'Y' ? true : false, 73 + collect: result.goBrand && result.goBrand.is_favorite === 'Y' ? true : false,
55 }); 74 });
56 }); 75 });
57 }; 76 };
@@ -80,6 +99,13 @@ const _shop = (req, res, shopId) => { @@ -80,6 +99,13 @@ const _shop = (req, res, shopId) => {
80 navTitle: false 99 navTitle: false
81 })) 100 }))
82 }; 101 };
  102 + } else {
  103 + uid = req.query.uid;
  104 + req.session.appUid = uid;
  105 + res.cookie('appUid', uid, {
  106 + domain: 'yohobuy.com',
  107 + expires: new Date(Date.now() + 2592000000) // 有效期一年
  108 + });
83 } 109 }
84 110
85 listModel.getShopData(req, shopId, uid, isApp).then(result => { 111 listModel.getShopData(req, shopId, uid, isApp).then(result => {
@@ -146,7 +172,7 @@ const shopFav = (req, res) => { @@ -146,7 +172,7 @@ const shopFav = (req, res) => {
146 listModel.getShopFav(req, shopId, uid, isApp).then(result => { 172 listModel.getShopFav(req, shopId, uid, isApp).then(result => {
147 res.json({ 173 res.json({
148 code: 200, 174 code: 200,
149 - collect: result.isFavorite === 'Y', 175 + collect: result.is_favorite === 'Y',
150 }); 176 });
151 }); 177 });
152 }; 178 };
@@ -321,12 +347,34 @@ const favoriteBrand = (req, res, next) => { @@ -321,12 +347,34 @@ const favoriteBrand = (req, res, next) => {
321 let opt = req.query.opt || 'ok'; 347 let opt = req.query.opt || 'ok';
322 let type = req.query.type || 'product'; 348 let type = req.query.type || 'product';
323 let appVersion = req.query.appVersion || false; 349 let appVersion = req.query.appVersion || false;
324 - let refer = req.get('Referer') || `${global.yoho.config.siteUrl}/${req.cookies._Channel || ''}`; 350 + let refer = req.headers.origin;
  351 +
  352 + if (req.headers.referer) {
  353 + let refererSplit = _.split(req.headers.referer, '?');
  354 +
  355 + let shopIdSplit = _.split(refererSplit[1], '&');
  356 + let shopId = '';
  357 +
  358 + _.forEach(shopIdSplit, value => {
  359 + if (_.startsWith(value, 'shop_id')) {
  360 + shopId = value;
  361 + return;
  362 + }
  363 + });
  364 +
  365 + refer = refererSplit[0] + '?' + shopId;
  366 + }
  367 +
325 let url = helpers.urlFormat('/signin.html') + '?refer=' + refer; 368 let url = helpers.urlFormat('/signin.html') + '?refer=' + refer;
326 369
327 - if (appVersion === 'true') {  
328 - uid = req.cookies.appUid;  
329 - url = `${url}&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":${decodeURI(req.cookies.refer)},"param":{}},"requesturl":{"param":{},"url":""},"priority":"Y"}}`; // eslint-disable-line 370 + if (appVersion) {
  371 + uid = req.query.uid ? crypto.decrypt('', req.query.uid) : req.cookies.appUid;
  372 +
  373 + if (!uid || uid === 'undefined') {
  374 + uid = _getUidFromUserAgent(req);
  375 + }
  376 +
  377 + url = `${refer}&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"${refer}","param":{}},"requesturl":{"param":{},"url":""},"priority":"Y"}}`; // eslint-disable-line
330 } 378 }
331 379
332 if (!id) { 380 if (!id) {
@@ -399,32 +447,65 @@ const userCoupon = (req, res, next) => { @@ -399,32 +447,65 @@ const userCoupon = (req, res, next) => {
399 } 447 }
400 448
401 let cryptCouponId = crypto.decrypt('', req.query.couponID); 449 let cryptCouponId = crypto.decrypt('', req.query.couponID);
  450 + let uid = req.user.uid;
  451 +
  452 + if (req.yoho.isApp !== 'false') {
  453 + uid = req.query.uid ? crypto.decrypt('', req.query.uid) : req.cookies.appUid;
  454 +
  455 + if (!uid || uid === 'undefined') {
  456 + uid = _getUidFromUserAgent(req);
  457 + }
  458 + }
402 459
403 - if (req.user.uid) { 460 + if (uid) {
404 listModel.receiveCoupon( 461 listModel.receiveCoupon(
405 - req.user.uid, 462 + uid,
406 cryptCouponId 463 cryptCouponId
407 ).then(result => { 464 ).then(result => {
408 res.json(result); 465 res.json(result);
  466 + return;
409 }).catch(next); 467 }).catch(next);
410 } else { 468 } else {
411 - let refer = req.headers.referer || req.headers.origin;  
412 - let toUrl = helpers.urlFormat('/signin.html', {refer: refer}); 469 + let refer = req.headers.origin;
  470 +
  471 + if (req.headers.referer) {
  472 + let refererSplit = _.split(req.headers.referer, '?');
  473 +
  474 + let shopIdSplit = _.split(refererSplit[1], '&');
  475 + let shopId = '';
  476 +
  477 + _.forEach(shopIdSplit, value => {
  478 + if (_.startsWith(value, 'shop_id')) {
  479 + shopId = value;
  480 + return;
  481 + }
  482 + });
413 483
414 - if (req.yoho.isApp) {  
415 - toUrl += '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + 484 + refer = refererSplit[0] + '?' + shopId;
  485 + }
  486 +
  487 + if (req.yoho.isApp !== 'false') {
  488 + let toUrl = refer + '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
416 refer + 489 refer +
417 '","param":{}},"requesturl":{"param":{"method":"app.promotion.getCoupon","couponId":"' + 490 '","param":{}},"requesturl":{"param":{"method":"app.promotion.getCoupon","couponId":"' +
418 cryptCouponId + 491 cryptCouponId +
419 '"},"url":"' + 492 '"},"url":"' +
420 _.get(global, 'yoho.API.ApiUrl', '') + 493 _.get(global, 'yoho.API.ApiUrl', '') +
421 '"},"priority":"Y"}}'; 494 '"},"priority":"Y"}}';
  495 +
  496 + res.json({
  497 + code: 4401,
  498 + url: toUrl
  499 + });
  500 +
  501 + } else {
  502 + res.json({
  503 + code: 4401,
  504 + url: helpers.urlFormat('/signin.html', {refer: refer})
  505 + });
422 } 506 }
423 507
424 - res.json({  
425 - code: 4401,  
426 - url: toUrl  
427 - }); 508 +
428 } 509 }
429 510
430 }; 511 };
@@ -182,7 +182,7 @@ const receiveCoupon = (uid, couponId) => { @@ -182,7 +182,7 @@ const receiveCoupon = (uid, couponId) => {
182 method: 'app.promotion.getCoupon', 182 method: 'app.promotion.getCoupon',
183 couponId: couponId, 183 couponId: couponId,
184 uid: uid 184 uid: uid
185 - }, {code: 200}).then(result => { 185 + }).then(result => {
186 return result; 186 return result;
187 }); 187 });
188 }; 188 };
@@ -500,7 +500,7 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -500,7 +500,7 @@ const getShopData = (req, shopId, uid, isApp) => {
500 return _getShopInfo(shopId, uid).then(shopInfoResult => { 500 return _getShopInfo(shopId, uid).then(shopInfoResult => {
501 501
502 /* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */ 502 /* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
503 - if (shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) { 503 + if (shopInfoResult && shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) {
504 return { 504 return {
505 goBrand: shopInfoResult 505 goBrand: shopInfoResult
506 }; 506 };
@@ -547,6 +547,7 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -547,6 +547,7 @@ const getShopData = (req, shopId, uid, isApp) => {
547 shopFilterSearchData, 547 shopFilterSearchData,
548 { 548 {
549 shopId: shopId, 549 shopId: shopId,
  550 + uid: uid ? crypto.encryption('', uid + '') : '',
550 coverChannel: channel, 551 coverChannel: channel,
551 shopCoupons: shopCoupons, 552 shopCoupons: shopCoupons,
552 shopCouponsOne: shopCoupons.length === 1 553 shopCouponsOne: shopCoupons.length === 1
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 <input type="hidden" name="brand" value="{{brand}}"> 10 <input type="hidden" name="brand" value="{{brand}}">
11 <input type="hidden" name="favId" value="{{favId}}"> 11 <input type="hidden" name="favId" value="{{favId}}">
12 <input type="hidden" name="coverChannel" value="{{coverChannel}}"> 12 <input type="hidden" name="coverChannel" value="{{coverChannel}}">
  13 + <input type="hidden" name="uid" value="{{uid}}">
13 14
14 {{#unless appVersion}} 15 {{#unless appVersion}}
15 <div class="search-area"> 16 <div class="search-area">
@@ -2,7 +2,8 @@ var $ = require('yoho-jquery'), @@ -2,7 +2,8 @@ var $ = require('yoho-jquery'),
2 Swiper = require('yoho-swiper'), 2 Swiper = require('yoho-swiper'),
3 tip = require('../../plugin/tip'); 3 tip = require('../../plugin/tip');
4 4
5 -var appVersion = $('input[name="app_version"]').val(); 5 +var appVersion = $('input[name="app_version"]').val(),
  6 + uid = $('input[name="uid"]').val();
6 7
7 $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function() { 8 $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function() {
8 var that = this, 9 var that = this,
@@ -19,7 +20,8 @@ $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function( @@ -19,7 +20,8 @@ $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function(
19 url: location.protocol + '//m.yohobuy.com/product/index/userCoupon', 20 url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
20 data: { 21 data: {
21 couponID: code, 22 couponID: code,
22 - app_version: appVersion 23 + app_version: appVersion,
  24 + uid: uid
23 }, 25 },
24 xhrFields: { 26 xhrFields: {
25 withCredentials: true 27 withCredentials: true
@@ -36,6 +36,7 @@ var $subNav = $('.home-sub-nav'), @@ -36,6 +36,7 @@ var $subNav = $('.home-sub-nav'),
36 brand = $('input[name="brand"]').val(), 36 brand = $('input[name="brand"]').val(),
37 coverChannel = $('input[name="coverChannel"]').val(), 37 coverChannel = $('input[name="coverChannel"]').val(),
38 favId = $('input[name="favId"]').val(); 38 favId = $('input[name="favId"]').val();
  39 + uid = $('input[name="uid"]').val();
39 40
40 var winH = $(window).height(), 41 var winH = $(window).height(),
41 noResult = '<p class="no-result">未找到相关搜索结果</p>'; 42 noResult = '<p class="no-result">未找到相关搜索结果</p>';
@@ -916,8 +917,8 @@ $nav2.on('touchstart', 'li', function(e) { @@ -916,8 +917,8 @@ $nav2.on('touchstart', 'li', function(e) {
916 // // stopPropagation(e); 917 // // stopPropagation(e);
917 // }); 918 // });
918 919
919 -$('#shop-category').click(function () {  
920 - let subGroup = $('.sub-group'); 920 +$('#shop-category').click(function() {
  921 + var subGroup = $('.sub-group');
921 922
922 if (subGroup.hasClass('hide')) { 923 if (subGroup.hasClass('hide')) {
923 $('.sub-group').removeClass('hide'); 924 $('.sub-group').removeClass('hide');
@@ -948,7 +949,8 @@ $collect.on('touchstart', function() { @@ -948,7 +949,8 @@ $collect.on('touchstart', function() {
948 id: favId ? favId : shopId, 949 id: favId ? favId : shopId,
949 appVersion: appVersion, 950 appVersion: appVersion,
950 opt: opt, 951 opt: opt,
951 - type: 'shop' 952 + type: 'shop',
  953 + uid: uid
952 }, 954 },
953 xhrFields: { 955 xhrFields: {
954 withCredentials: true 956 withCredentials: true