Authored by 周少峰

Merge branch 'master' into feature/students

@@ -29,6 +29,11 @@ class DetailAction extends YohoAction { @@ -29,6 +29,11 @@ class DetailAction extends YohoAction {
29 let gid = req.params[1]; 29 let gid = req.params[1];
30 let uid = req.user.uid || ''; 30 let uid = req.user.uid || '';
31 let vipLevel = detailHelper.vipLevel(req.user.vip); 31 let vipLevel = detailHelper.vipLevel(req.user.vip);
  32 + let saveCurrentGoodsInCookies = _.partial(service.saveRecentGoodInCookies,
  33 + req.cookies._browse,
  34 + req.cookies._browseskn,
  35 + this.response
  36 + );
32 37
33 return service.showMainAsync({ 38 return service.showMainAsync({
34 pid: pid, 39 pid: pid,
@@ -37,7 +42,8 @@ class DetailAction extends YohoAction { @@ -37,7 +42,8 @@ class DetailAction extends YohoAction {
37 gender: this.guessUserGender(), 42 gender: this.guessUserGender(),
38 uid: uid, 43 uid: uid,
39 isStudent: req.user.isStudent, 44 isStudent: req.user.isStudent,
40 - vipLevel: vipLevel 45 + vipLevel: vipLevel,
  46 + saveInCookies: saveCurrentGoodsInCookies
41 }).then(result=> { 47 }).then(result=> {
42 const seo = result.seo; 48 const seo = result.seo;
43 49
@@ -531,6 +531,29 @@ function _getSortNavAsync(smallSortId, gender) { @@ -531,6 +531,29 @@ function _getSortNavAsync(smallSortId, gender) {
531 })(); 531 })();
532 } 532 }
533 533
  534 +// 保存在 gids 和 skns ,最近流览功能
  535 +const saveRecentGoodInCookies = (oldGids, oldSkns, res, addGids, addSkns) => {
  536 + oldGids = (oldGids || '').split(',');
  537 + oldSkns = (oldSkns || '').split(',');
  538 + addSkns = `${addSkns}-${addGids}`;
  539 +
  540 + _.remove(oldGids, addGids);
  541 + _.remove(oldSkns, addSkns);
  542 +
  543 + oldGids.unshift(addGids);
  544 + oldSkns.unshift(addSkns);
  545 +
  546 + res.cookie('_browse', oldGids.splice(0, 30).join(','), {
  547 + maxAge: 2000000000,
  548 + domain: 'yohobuy.com'
  549 + });
  550 +
  551 + res.cookie('_browseskn', oldSkns.splice(0, 30).join(','), {
  552 + maxAge: 2000000000,
  553 + domain: 'yohobuy.com'
  554 + });
  555 +};
  556 +
534 /** 557 /**
535 * 详情页数据格式化 558 * 详情页数据格式化
536 * @param origin Object 原始数据 559 * @param origin Object 原始数据
@@ -632,7 +655,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -632,7 +655,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
632 if (origin.brand) { 655 if (origin.brand) {
633 result.brandImg = helpers.image(origin.brand.brandIco, 47, 47); 656 result.brandImg = helpers.image(origin.brand.brandIco, 47, 47);
634 result.brandName = origin.brand.brandName; 657 result.brandName = origin.brand.brandName;
635 - result.brandUrl = helpers.urlFormat('', {}, origin.brand.brandDomain); 658 + result.brandUrl = helpers.urlFormat('', null, origin.brand.brandDomain);
636 banner = _getBrandDataByProductBaseInfo(origin); 659 banner = _getBrandDataByProductBaseInfo(origin);
637 if (banner.isCollect && favoriteData.brand) { 660 if (banner.isCollect && favoriteData.brand) {
638 banner.isCollect = favoriteData.brand; 661 banner.isCollect = favoriteData.brand;
@@ -723,7 +746,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -723,7 +746,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
723 // 分享相关,产品的链接 746 // 分享相关,产品的链接
724 result.weixinUrl = helpers.urlFormat(origin.productUrl, {}, 'item'); 747 result.weixinUrl = helpers.urlFormat(origin.productUrl, {}, 'item');
725 result.shareTitle = result.name; 748 result.shareTitle = result.name;
726 - result.shareImg = result.img; 749 + result.shareImg = 'http:' + result.img;
727 result.shareDesc = result.phrase; 750 result.shareDesc = result.phrase;
728 751
729 // 统计需要的商品信息 752 // 统计需要的商品信息
@@ -746,18 +769,19 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -746,18 +769,19 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
746 769
747 if (domainBrand.type && domainBrand.shopId) { 770 if (domainBrand.type && domainBrand.shopId) {
748 switch (parseInt(domainBrand.type, 10)) { 771 switch (parseInt(domainBrand.type, 10)) {
749 - case 1: 772 + case 1: {
750 // 多品店不显示 773 // 多品店不显示
751 banner = []; 774 banner = [];
752 break; 775 break;
753 - case 2: 776 + }
  777 + case 2: {
754 // 单品店显示新版的店铺banner 778 // 单品店显示新版的店铺banner
755 let basisData = yield shopService.basisTemplateAsync(domainBrand.shopId); 779 let basisData = yield shopService.basisTemplateAsync(domainBrand.shopId);
756 780
757 banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg; 781 banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
758 break; 782 break;
759 - default:  
760 - { 783 + }
  784 + default: {
761 break; 785 break;
762 } 786 }
763 } 787 }
@@ -1378,12 +1402,17 @@ const showMainAsync = (data) => { @@ -1378,12 +1402,17 @@ const showMainAsync = (data) => {
1378 HeaderModel.requestHeaderData(data.channel) 1402 HeaderModel.requestHeaderData(data.channel)
1379 ]); 1403 ]);
1380 1404
1381 - // 分类导航 1405 + // 分类导航 ,seo
1382 let navs = requestData[0]; 1406 let navs = requestData[0];
1383 const seo = _getSeoByGoodsInfo(productInfo.goodsInfo, navs); 1407 const seo = _getSeoByGoodsInfo(productInfo.goodsInfo, navs);
1384 1408
1385 result.seo = seo; 1409 result.seo = seo;
1386 1410
  1411 + // 最近浏览功能 ,限量商品不能使用这个功能
  1412 + if (!_.has(productInfo, 'goodsInfo.fashionTopGoods')) {
  1413 + data.saveInCookies(data.gid, _.get(productInfo, 'goodsInfo.skn', ''));
  1414 + }
  1415 +
1387 // 获取商品尺寸相关 1416 // 获取商品尺寸相关
1388 let sizeInfo = _getSizeInfo(productInfo.goodsInfo, productInfo.goodsInfo.maxSortId); 1417 let sizeInfo = _getSizeInfo(productInfo.goodsInfo, productInfo.goodsInfo.maxSortId);
1389 1418
@@ -1413,5 +1442,6 @@ module.exports = { @@ -1413,5 +1442,6 @@ module.exports = {
1413 indexConsultAsync: consultService.indexAsync, // 获取咨询列表 1442 indexConsultAsync: consultService.indexAsync, // 获取咨询列表
1414 createConsultAsync: consultService.createAsync, // 添加咨询 1443 createConsultAsync: consultService.createAsync, // 添加咨询
1415 showMainAsync: showMainAsync, // 获取某一个商品详情主页面 1444 showMainAsync: showMainAsync, // 获取某一个商品详情主页面
1416 - indexHotAreaAsync: hotAreaService.indexAsync // 获取某一个商品的热区数据 1445 + indexHotAreaAsync: hotAreaService.indexAsync, // 获取某一个商品的热区数据
  1446 + saveRecentGoodInCookies // 保存最近的商品
1417 }; 1447 };
@@ -22,7 +22,7 @@ module.exports = { @@ -22,7 +22,7 @@ module.exports = {
22 }, 22 },
23 subDomains: { 23 subDomains: {
24 host: '.yohobuy.com', 24 host: '.yohobuy.com',
25 - default: '//yohobuy.com', 25 + default: '//www.yohobuy.com',
26 guang: '//guang.yohobuy.com', 26 guang: '//guang.yohobuy.com',
27 list: '//list.yohobuy.com', 27 list: '//list.yohobuy.com',
28 search: '//search.yohobuy.com', 28 search: '//search.yohobuy.com',
@@ -100,7 +100,7 @@ if (isProduction) { @@ -100,7 +100,7 @@ if (isProduction) {
100 useOneapm: true, 100 useOneapm: true,
101 useCache: true, 101 useCache: true,
102 interfaceShunt: { 102 interfaceShunt: {
103 - useInterfaceShunt: true, 103 + useInterfaceShunt: false,
104 tencentServers: { 104 tencentServers: {
105 api: ['123.206.1.98', '123.206.2.80'], 105 api: ['123.206.1.98', '123.206.2.80'],
106 service: ['123.206.1.98', '123.206.2.80'] 106 service: ['123.206.1.98', '123.206.2.80']
@@ -13,7 +13,12 @@ module.exports = () => { @@ -13,7 +13,12 @@ module.exports = () => {
13 }; 13 };
14 const channel = req.query.channel || req.cookies._Channel || 'boys'; 14 const channel = req.query.channel || req.cookies._Channel || 'boys';
15 15
  16 + // 用于头部颜色控制
16 yoho.pageChannel[channel] = true; 17 yoho.pageChannel[channel] = true;
  18 +
  19 + // 当前频道设置
  20 + yoho.channel = channel;
  21 +
17 yoho.isApp = req.query.app_version || req.query.appVersion; 22 yoho.isApp = req.query.app_version || req.query.appVersion;
18 23
19 Object.assign(res.locals, yoho); 24 Object.assign(res.locals, yoho);
1 'use strict'; 1 'use strict';
2 2
3 -const _ = require('lodash');  
4 const Fp = require('lodash/fp'); 3 const Fp = require('lodash/fp');
5 const cookie = global.yoho.cookie; 4 const cookie = global.yoho.cookie;
6 5
7 module.exports = () => { 6 module.exports = () => {
8 return (req, res, next) => { 7 return (req, res, next) => {
9 - // 从 SESSION 中获取到当前登录用户的 UID  
10 - if (req.session && _.isNumber(req.session._LOGIN_UID)) {  
11 - req.user.uid = req.session._LOGIN_UID;  
12 - }  
13 8
14 // session 没有读取到的时候,从 cookie 读取 UID 9 // session 没有读取到的时候,从 cookie 读取 UID
15 - if (!req.user.uid && req.cookies._UID) { 10 + if (req.cookies._UID) {
16 req.user.uid = cookie.getUid(req); 11 req.user.uid = cookie.getUid(req);
17 - }  
18 12
19 - // 获得vip 信息  
20 - if (req.user.uid && req.cookies._UID) {  
21 let getVip = Fp.pipe(Fp.split('::'), Fp.nth(2)); 13 let getVip = Fp.pipe(Fp.split('::'), Fp.nth(2));
22 14
23 req.user.vip = getVip(req.cookies._UID); 15 req.user.vip = getVip(req.cookies._UID);
@@ -27,6 +19,10 @@ module.exports = () => { @@ -27,6 +19,10 @@ module.exports = () => {
27 if (req.user.uid && req.cookies.isStudent) { 19 if (req.user.uid && req.cookies.isStudent) {
28 req.user.isStudent = req.cookies.isStudent; 20 req.user.isStudent = req.cookies.isStudent;
29 } 21 }
  22 + // 从 SESSION 中获取到当前登录用户的 UID
  23 + // if (req.session && _.isNumber(req.session._LOGIN_UID)) {
  24 + // req.user.uid = req.session._LOGIN_UID;
  25 + // }
30 26
31 next(); 27 next();
32 }; 28 };