Authored by 郭成尧

'mg-shop-page-cache'

... ... @@ -14,7 +14,7 @@ const helpers = global.yoho.helpers;
/**
* 店铺 - 基础模板
*/
const _baseShop = (req, res, shopInfo) => {
const _baseShop = (req, res, shopInfo, shopId) => {
listModel.getBaseShopData(req.query, shopInfo).then(result => {
... ... @@ -29,13 +29,31 @@ const _baseShop = (req, res, shopInfo) => {
pageFooter: true,
title: shopInfo.shopName + '|' + shopInfo.shopName + '潮流服装服饰-Yoho!Buy有货',
keywords: shopInfo.shopName + ',' + shopInfo.shopName + '服装服饰,' + shopInfo.shopName + '潮流服装服饰',
description: shopInfo.shopName + '|Yoho!Buy有货' + shopInfo.shopName + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。'
description: shopInfo.shopName + '|Yoho!Buy有货' + shopInfo.shopName + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
});
});
};
/**
* 基础模板收藏
*/
const baseShopFav = (req, res) => {
let isApp = req.query.app_version || req.query.appVersion || false;
let uid = isApp ? req.query.uid : req.user.uid;
let shopId = req.query.shopId;
listModel.getShopData(req, shopId, uid, isApp).then(result => {
res.json({
code: 200,
collect: result.goBrand && result.goBrand.isFavorite === 'Y' ? true : false,
});
});
};
/**
* 店铺首页
* @return int
*/
... ... @@ -44,6 +62,7 @@ const _shop = (req, res, shopId) => {
let pageHeader = {};
let uid = 0;
// pagecache前端判断
if (!isApp) {
pageHeader = {
pageHeader: _.assign({
... ... @@ -57,21 +76,23 @@ const _shop = (req, res, shopId) => {
navTitle: false
}))
};
uid = req.user.uid;
} else {
uid = req.query.uid;
req.session.appUid = uid;
res.cookie('appUid', uid, {
domain: 'yohobuy.com',
expires: new Date(Date.now() + 2592000000) // 有效期一年
});
}
// uid = req.user.uid;
// } 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 => {
if (result.goBrand) {
/* 若店铺使用基础模板跳转基础模板 */
_baseShop(req, res, result.goBrand);
_baseShop(req, res, result.goBrand, shopId);
} else {
result = _.assign(result, pageHeader);
... ... @@ -87,12 +108,46 @@ const _shop = (req, res, shopId) => {
}),
title: result.storeName + '|' + result.storeName + '潮流服装服饰-Yoho!Buy有货',
keywords: result.storeName + ',' + result.storeName + '服装服饰,' + result.storeName + '潮流服装服饰',
description: result.storeName + '|Yoho!Buy有货' + result.storeName + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。'
description: result.storeName + '|Yoho!Buy有货' + result.storeName + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
});
}
});
};
/**
* app设置cookie
*/
const shopAppCookie = (req, res) => {
let uid = req.query.uid;
req.session.appUid = uid;
res.cookie('appUid', uid, {
domain: 'yohobuy.com',
expires: new Date(Date.now() + 2592000000) // 有效期一年
});
res.json({
code: 200,
msg: 'app cookie set',
});
};
/**
* 前端请求判断shop是否收藏
*/
const shopFav = (req, res) => {
let isApp = req.query.app_version || req.query.appVersion || false;
let uid = isApp ? req.query.uid : req.user.uid;
let shopId = req.query.shopId;
listModel.getShopData(req, shopId, uid, isApp).then(result => {
res.json({
code: 200,
collect: result.collect,
});
});
};
// 品类落地页
const category = (req, res) => {
let params = Object.assign({}, req.query);
... ... @@ -188,13 +243,27 @@ const brand = (req, res, next) => {
pageFooter: true,
title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货',
keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰',
description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。'
description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
domain: req.query.domain,
});
});
}
}).catch(next);
};
const brandFav = (req, res) => {
let domain = req.query.domain;
let uid = req.user.uid;
let brandId = 0;
listModel.getBrandLogoByDomain(domain).then((result) => {
brandId = result.id;
listModel.getBrandIntro(brandId, uid).then(result2 => {
res.json(result2);
});
});
};
/**
* 店铺简介
* @param req
... ... @@ -281,5 +350,11 @@ module.exports = {
category,
brand,
favoriteBrand,
shopIntro
shopIntro,
// pagecache新增
brandFav,
shopAppCookie,
shopFav,
baseShopFav,
};
... ...
... ... @@ -33,19 +33,19 @@ const list = (req, res, next) => {
Promise.all([searchModel.getAllBrandNames(), searchModel.getClassNames()]).then((result) => {
if (query) {
_.forEach(result[0], function(obj) {
if (query === obj.brandDomain) { // 精确查品牌域名
if (query === obj.brandDomain && /^[a-z0-9]+$/i.test(obj.brandName)) { // 精确查品牌域名
domain = query;
return false;
}
if (query === obj.brandName) { // 精确查品牌名称
if (query === obj.brandName && /^[a-z0-9]+$/i.test(obj.brandName)) { // 精确查品牌名称
domain = obj.brandName;
return false;
}
if (obj.brandDomain.indexOf(query) > 0) { // 模糊查品牌域名
domain = obj.brandDomain;
return false;
}
// if (obj.brandDomain.indexOf(query) > 0) { // 模糊查品牌域名
// domain = obj.brandDomain;
// return false;
// }
});
// 跳转到品牌商品列表页
... ... @@ -56,7 +56,7 @@ const list = (req, res, next) => {
}, domain);
res.redirect(url);
return res.redirect(url);
}
// 品类名称为空时跳出
... ...
... ... @@ -381,7 +381,6 @@ const _formShopData = (data, shopId, isApp) => {
formatData.favId = shopId;
formatData.shopId = '';
}
return formatData;
};
... ... @@ -494,11 +493,9 @@ const getShopData = (req, shopId, uid, isApp) => {
const getBrandIntro = (brandId, uid) => {
let param = {};
if (uid) {
param = {
uid: uid
};
}
param = {
uid: uid,
};
return api.get('', _.assign({
method: 'app.brand.getBrandIntro',
... ...
... ... @@ -96,6 +96,10 @@ router.get('/index/index', list.category);
// 品牌 | 店铺
router.get('/index/brand', list.brand);
router.get('/index/brandFav', list.brandFav);
router.get('/index/shopAppCookie', list.shopAppCookie);
router.get('/index/shopFav', list.shopFav);
router.get('/index/baseShopFav', list.baseShopFav);
// 店铺介绍
router.get('/index/intro', list.shopIntro);
... ...
... ... @@ -32,11 +32,7 @@
<img class="logo" src="{{image logoImg 500 500}}">
<p class="store-name">{{storeName}}</p>
<div class="collect">
{{#if collect}}
<div class="already-collect" id="collect"></div>
{{else}}
<div class="not-collect buriedpoint" id="collect" data-bp-id="shop_branner_collect_1"></div>
{{/if}}
<div class="not-collect buriedpoint" id="collect" data-bp-id="shop_branner_collect_1"></div>
</div>
</div>
</div>
... ... @@ -220,3 +216,5 @@
{{> common/filter}}
{{/ shopIndex}}
{{> common/query-param}}
<input type="text" class="shopid" style="display:none" value={{shopId}} />
... ...
... ... @@ -37,7 +37,7 @@
<a class="btn-intro" href="javascript:void(0);">
品牌介绍
</a>
<a class="btn-col{{#if collected}} coled{{/if}}" href="javascript:void(0);">
<a class="btn-col" href="javascript:void(0);">
<span class="iconfont">&#xe622;</span>
<span class="txt"></span>
</a>
... ... @@ -65,7 +65,7 @@
<a class="btn-intro" href="javascript:void(0);">
店铺介绍
</a>
<a class="btn-col{{#if collected}} coled{{/if}}" href="javascript:void(0);">
<a class="btn-col" href="javascript:void(0);">
<span class="iconfont">&#xe622;</span>
<span class="txt"></span>
</a>
... ... @@ -140,3 +140,6 @@
{{> common/suspend-cart}}
{{/ goodList}}
<input type="text" class="domain" style="display:none" value={{domain}}>
<input type="text" class="shopId" style="display:none" value={{shopId}}>
... ...
... ... @@ -18,8 +18,13 @@ module.exports = {
domains: {
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test1.yohops.com:9999/'
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://single.yoho.cn/'
// api: 'http://api-test1.yohops.com:9999/',
// service: 'http://service-test1.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test1.yohops.com:9999/'
},
subDomains: {
host: '.m.yohobuy.com',
... ... @@ -83,7 +88,7 @@ if (isProduction) {
api: 'http://api.yoho.yohoops.org/',
service: 'http://service.yoho.yohoops.org/',
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://singleapi.yoho.cn/'
singleApi: 'http://single.yoho.cn/'
},
memcache: {
master: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'],
... ...
... ... @@ -5,6 +5,7 @@
*/
'use strict';
const querystring = require('querystring');
const _ = require('lodash');
const helpers = global.yoho.helpers;
module.exports = () => {
... ... @@ -22,7 +23,17 @@ module.exports = () => {
break;
case 'search': // search
if (req.path === '/') {
req.url = `/product/search/list?${querystring.stringify(req.query)}`;
// 有查询关键字
if (_.keys(req.query).length) {
req.url = `/product/search/list?${querystring.stringify(req.query)}`;
} else {
req.url = `/product/search/index?${querystring.stringify(req.query)}`;
}
}
if (req.path === '/search') {
req.url = `/product/search/index?${querystring.stringify(req.query)}`;
}
break;
... ... @@ -48,10 +59,10 @@ module.exports = () => {
default: // 其它(识别为品牌)
if (req.path === '/') {
req.url = `/product/index/brand?domain=${req.subdomains[0]}`;
req.query = {
req.query = Object.assign(req.query, {
domain: req.subdomains[0]
};
});
req.url = `/product/index/brand?${querystring.stringify(req.query)}`;
}
break;
}
... ...
... ... @@ -7,6 +7,7 @@
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
* 传配置对象设置头部
... ... @@ -26,10 +27,10 @@ exports.setNav = (opt) => {
if (defaultOpt.navBtn || _.isNull(defaultOpt.navBtn)) {
Object.assign(defaultOpt, {
navBtn: { // 顶部下拉菜单选项
indexUrl: '/?go=1',
categoryUrl: '/cate',
shoppingCartUrl: '/cart/index/index',
mineUrl: '/home'
indexUrl: helpers.urlFormat('/', {go: 1}),
categoryUrl: helpers.urlFormat('/cate'),
shoppingCartUrl: helpers.urlFormat('/cart/index/index'),
mineUrl: helpers.urlFormat('/home')
}
});
}
... ...
... ... @@ -71,6 +71,43 @@ require('../../common');
ellipsis.init();
// pageCache 获取是否收藏
(function() {
if ($('.domain').val()) {
$.ajax({
url: '/product/index/brandFav',
data: {
domain: $('.domain').val()
},
dataType: 'json',
success: function(data) {
if (data.collected) {
$('.brand-header .btn-col').addClass('coled');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
} else {
$.ajax({
url: '/product/index/baseShopFav',
data: {
shopId: $('.shopId').val()
},
dataType: 'json',
success: function(data) {
if (data.collect) {
$('.brand-header .btn-col').addClass('coled');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
}());
// 搜索输入联动
function inputAction() {
var $searchAssociate = $('.search-associate');
... ...
... ... @@ -42,6 +42,38 @@ var winH = $(window).height(),
require('../../common');
// pagecache判断app设置cookie,判断是否收藏
(function() {
var param = location.search;
var isApp = param.indexOf('app_version') > -1 || param.indexOf('appVersion') > -1;
if (isApp) {
$.ajax({
type: 'GET',
url: '/product/index/shopAppCookie',
error: function() {
tip.show('网络断开连接了~');
}
});
}
$.ajax({
type: 'GET',
url: '/product/index/shopFav',
data: {
shopId: $('.shopid').val(),
},
success: function(data) {
if (data.collect) {
$collect.attr('class', 'already-collect');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
}());
// 默认筛选条件
var defaultOpt = require('../../common/query-param');
... ...