Authored by 周少峰

Merge branch 'master' into feature/students

... ... @@ -29,6 +29,11 @@ class DetailAction extends YohoAction {
let gid = req.params[1];
let uid = req.user.uid || '';
let vipLevel = detailHelper.vipLevel(req.user.vip);
let saveCurrentGoodsInCookies = _.partial(service.saveRecentGoodInCookies,
req.cookies._browse,
req.cookies._browseskn,
this.response
);
return service.showMainAsync({
pid: pid,
... ... @@ -37,7 +42,8 @@ class DetailAction extends YohoAction {
gender: this.guessUserGender(),
uid: uid,
isStudent: req.user.isStudent,
vipLevel: vipLevel
vipLevel: vipLevel,
saveInCookies: saveCurrentGoodsInCookies
}).then(result=> {
const seo = result.seo;
... ...
... ... @@ -531,6 +531,29 @@ function _getSortNavAsync(smallSortId, gender) {
})();
}
// 保存在 gids 和 skns ,最近流览功能
const saveRecentGoodInCookies = (oldGids, oldSkns, res, addGids, addSkns) => {
oldGids = (oldGids || '').split(',');
oldSkns = (oldSkns || '').split(',');
addSkns = `${addSkns}-${addGids}`;
_.remove(oldGids, addGids);
_.remove(oldSkns, addSkns);
oldGids.unshift(addGids);
oldSkns.unshift(addSkns);
res.cookie('_browse', oldGids.splice(0, 30).join(','), {
maxAge: 2000000000,
domain: 'yohobuy.com'
});
res.cookie('_browseskn', oldSkns.splice(0, 30).join(','), {
maxAge: 2000000000,
domain: 'yohobuy.com'
});
};
/**
* 详情页数据格式化
* @param origin Object 原始数据
... ... @@ -632,7 +655,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
if (origin.brand) {
result.brandImg = helpers.image(origin.brand.brandIco, 47, 47);
result.brandName = origin.brand.brandName;
result.brandUrl = helpers.urlFormat('', {}, origin.brand.brandDomain);
result.brandUrl = helpers.urlFormat('', null, origin.brand.brandDomain);
banner = _getBrandDataByProductBaseInfo(origin);
if (banner.isCollect && favoriteData.brand) {
banner.isCollect = favoriteData.brand;
... ... @@ -723,7 +746,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
// 分享相关,产品的链接
result.weixinUrl = helpers.urlFormat(origin.productUrl, {}, 'item');
result.shareTitle = result.name;
result.shareImg = result.img;
result.shareImg = 'http:' + result.img;
result.shareDesc = result.phrase;
// 统计需要的商品信息
... ... @@ -746,18 +769,19 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
if (domainBrand.type && domainBrand.shopId) {
switch (parseInt(domainBrand.type, 10)) {
case 1:
case 1: {
// 多品店不显示
banner = [];
break;
case 2:
}
case 2: {
// 单品店显示新版的店铺banner
let basisData = yield shopService.basisTemplateAsync(domainBrand.shopId);
banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
break;
default:
{
}
default: {
break;
}
}
... ... @@ -1378,12 +1402,17 @@ const showMainAsync = (data) => {
HeaderModel.requestHeaderData(data.channel)
]);
// 分类导航
// 分类导航 ,seo
let navs = requestData[0];
const seo = _getSeoByGoodsInfo(productInfo.goodsInfo, navs);
result.seo = seo;
// 最近浏览功能 ,限量商品不能使用这个功能
if (!_.has(productInfo, 'goodsInfo.fashionTopGoods')) {
data.saveInCookies(data.gid, _.get(productInfo, 'goodsInfo.skn', ''));
}
// 获取商品尺寸相关
let sizeInfo = _getSizeInfo(productInfo.goodsInfo, productInfo.goodsInfo.maxSortId);
... ... @@ -1413,5 +1442,6 @@ module.exports = {
indexConsultAsync: consultService.indexAsync, // 获取咨询列表
createConsultAsync: consultService.createAsync, // 添加咨询
showMainAsync: showMainAsync, // 获取某一个商品详情主页面
indexHotAreaAsync: hotAreaService.indexAsync // 获取某一个商品的热区数据
indexHotAreaAsync: hotAreaService.indexAsync, // 获取某一个商品的热区数据
saveRecentGoodInCookies // 保存最近的商品
};
... ...
... ... @@ -22,7 +22,7 @@ module.exports = {
},
subDomains: {
host: '.yohobuy.com',
default: '//yohobuy.com',
default: '//www.yohobuy.com',
guang: '//guang.yohobuy.com',
list: '//list.yohobuy.com',
search: '//search.yohobuy.com',
... ... @@ -100,7 +100,7 @@ if (isProduction) {
useOneapm: true,
useCache: true,
interfaceShunt: {
useInterfaceShunt: true,
useInterfaceShunt: false,
tencentServers: {
api: ['123.206.1.98', '123.206.2.80'],
service: ['123.206.1.98', '123.206.2.80']
... ...
... ... @@ -13,7 +13,12 @@ module.exports = () => {
};
const channel = req.query.channel || req.cookies._Channel || 'boys';
// 用于头部颜色控制
yoho.pageChannel[channel] = true;
// 当前频道设置
yoho.channel = channel;
yoho.isApp = req.query.app_version || req.query.appVersion;
Object.assign(res.locals, yoho);
... ...
'use strict';
const _ = require('lodash');
const Fp = require('lodash/fp');
const cookie = global.yoho.cookie;
module.exports = () => {
return (req, res, next) => {
// 从 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session._LOGIN_UID)) {
req.user.uid = req.session._LOGIN_UID;
}
// session 没有读取到的时候,从 cookie 读取 UID
if (!req.user.uid && req.cookies._UID) {
if (req.cookies._UID) {
req.user.uid = cookie.getUid(req);
}
// 获得vip 信息
if (req.user.uid && req.cookies._UID) {
let getVip = Fp.pipe(Fp.split('::'), Fp.nth(2));
req.user.vip = getVip(req.cookies._UID);
... ... @@ -27,6 +19,10 @@ module.exports = () => {
if (req.user.uid && req.cookies.isStudent) {
req.user.isStudent = req.cookies.isStudent;
}
// 从 SESSION 中获取到当前登录用户的 UID
// if (req.session && _.isNumber(req.session._LOGIN_UID)) {
// req.user.uid = req.session._LOGIN_UID;
// }
next();
};
... ...