Authored by 王水玲

店铺

... ... @@ -11,6 +11,87 @@ const searchModel = require(`${mRoot}/search`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
* 新店铺首页
* @param {int} shopId 店铺id
* @param {int} uid 用户id
* @param {string} isApp app版本
* @return array
*/
const _getShopData = (shopId, uid, isApp) => {
let data = {};
let channel = req.yoho.channel;
isApp = isApp || '';
//Promise.all([searchModel.getShopDecorator(shopId),searchModel.getShopInfo(shopId, uid)]).then((result) => {
// data = {
// decorator: result[0], // 店铺装修资源数据
// shopInfo: result[1] // 店铺信息
// };
//
// // 店铺使用基础模板,返回品牌页面
// if (data.shopInfo.data.shopTemplateType && data.shopInfo.data.shopTemplateType ===1) {
// return {
// goBrand: data.shopInfo.data
// }
// }
//
// // 店铺分类
// return searchModel.getShopCategory(shopId, channel);
//}).then(shopCategory => {
// _.assign({
// shopCategory: shopCategory
// }, data);
//
// return searchModel.formShopData(data, shopId, isApp); // 组织楼层数据
//});
};
/**
* 店铺首页 || 若店铺使用基础模板跳转品牌页
* @return int
*/
const _shop = (req, res, shopId) => {
let isApp = req.query.app_version || req.query.appVersion || false;
let pageHeader = {};
let uid = 0;
if (!isApp) {
pageHeader = headerModel.setNav({
navTitle: ''
});
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) // 有效期一年
});
}
_getShopData(shopId, uid, isApp).then((result) => {
if (result.goBrand) {
// 跳转基础模板
_baseShop(result.goBrand);
}
res.render('shop', {
shopIndex: result,
shopPage: {
text: '分类',
url: helpers.urlFormat('/product/index/category', {
shop_id: shopId
})
},
gender: req.query.gender,
channel: req.query.channel
}
});
};
// 搜索落地页
const list = (req, res, next) => {
let params = Object.assign({}, req.query);
... ... @@ -106,7 +187,7 @@ const list = (req, res, next) => {
}).catch(next);
};
// 类落地页
// 类落地页
const category = (req, res) => {
let params = Object.assign({}, req.query);
... ... @@ -122,6 +203,81 @@ const category = (req, res) => {
});
};
// 品牌落地页
const brand = (req, res, next) => {
let params = Object.assign({}, req.query);
let domain = 'vans';
let uid = req.user.uid || 20000032;
let brandId = 0;
let brandLogo = {};
let title = '';
let brandHome = false;
if (!domain) {
res.redirect('/?go=1');
}
searchModel.getBrandLogoByDomain(domain).then((result) => {
brandLogo = result;
title = brandLogo.name;
//无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面
if (brandLogo.type === 2 && brandLogo.shopId) {
_shop(req, res, brandLogo.shopId);
return false;
}
if (brandLogo && brandLogo.id) {
brandId = brandLogo.id;
}
params = _.assign({
brand: brandId
}, params);
//获取品牌店铺信息
return searchModel.getBrandShops(brandId);
}).then((brandShop) => {
if (brandId === 0) {
params.query = domain;
}
// 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺
if (req.query.from === 'search' || brandShop.length > 0) {
params = {
brandWay: brandShop ? brandShop : brandLogo,
search: {
default: req.query.query,
url: helpers.urlFormat('', null, 'search')
}
};
} else if (brandId !== 0) { // 品牌一览过来的展示品牌介绍和LOGO
return Promise.all([searchModel.getBrandIntro(brandId, uid), searchModel.getBrandBanner(brandId)]).then((result) => {
title = result[0].title;
delete result[0].title;
return _.assign({
banner: result[1]
}, result[0]);
});
}
}).then((brandHome) => {
params.brandHome = brandHome;
res.render('search/goods-list', {
module: 'product',
page: 'search-list',
pageHeader: headerModel.setNav({
navTitle: title !== '' ? title : domain
}),
goodList: params,
showDownloadApp: true,
pageFooter: true
});
}).catch(next);
};
const search = (req, res, next) => {
let params = Object.assign({}, req.query);
... ... @@ -151,9 +307,58 @@ let filter = (req, res, next) => {
}).catch(next);
};
/**
* 品牌[店铺]收藏/取消收藏
* id 品牌ID
* opt 操作标识("ok":表示收藏,"cancel":表示取消收藏)
*/
const favoriteBrand = (req, res, next) => {
let id = req.body.id;
let uid = req.user.uid || 20000032;
let opt = req.body.opt || 'ok';
if (_.isNumber(id)) {
res.json({
code: 401,
message: '参数不正确',
data: false
});
return false;
} else if (!uid) {
res.json({
code: 400,
message: '未登录',
data: helpers.urlFormat('/signin.html', {
refer: decodeURI(req.cookies.refer)
})
});
return false;
} else if (opt !== 'ok') { // 取消收藏
searchModel.setFavoriteCancel(id, uid).then((data) => {
res.json(data);
return false;
}).catch(next);
}
searchModel.setFavorite(id, uid).then((result) => {
if (!result.code) { // 收藏
result = {
code: 401,
message: '参数不正确',
data: false
};
}
res.json(result);
});
};
module.exports = {
list,
filter,
search,
category
category,
brand,
favoriteBrand
};
... ...
... ... @@ -9,6 +9,7 @@ const logger = global.yoho.logger;
const camelCase = global.yoho.camelCase;
const productProcess = require(`${utils}/product-process`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
/**
... ... @@ -113,6 +114,88 @@ const _processClassNames = (list) => {
return formatData;
};
/* 多品牌店铺列表数据信息处理*/
const _processBrandShops = (list) => {
const formatDat = [];
list = list || [];
list = camelCase(list);
_.forEach(list, (item) => {
if (item.shopId) {
formatDat.push({
url: helpers.urlFormat('/product/index/brand/', {
shop_id: item.brandId
}),
thumb: helpers.image(item.brandIco, 75, 40),
name: item.brandName
});
}
});
return formatDat;
};
/**
* 获取品牌信息数据
* @param {int} brandId 品牌ID
* @return array banner数据
*/
const getBrandIntro = (brandId, uid) => {
let param = {};
if (uid) {
param = {
uid: uid
};
}
return api.get('', _.assign({
method: 'app.brand.getBrandIntro',
brand_id: brandId
}, param), {
cache: true
}).then((result) => {
if (result && result.code === 200) {
let list = camelCase(result.data) || {};
return {
id: list.brandId,
intro: list.brandIntro,
collected: (list.isFavorite && list.isFavorite === 'Y') ? true : false,
title: list.brandName ? list.brandName : ''
};
} else {
logger.error('获取店铺信息接口返回code 不是 200');
return {};
}
});
};
/**
* 获取品牌banner数据
* @param {int} brandId 品牌ID
* @return array banner数据
*/
const getBrandBanner = (brandId) => {
return api.get('', {
method: 'app.brand.banner',
brand_id: brandId
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
if (result.data.banner) {
return helpers.image(result.data.banner, 640, 150);
} else {
return '';
}
} else {
logger.error('获取店铺banner接口返回code 不是 200');
return {};
}
});
};
/**
* 获取商品数据
... ... @@ -180,9 +263,184 @@ const getClassNames = () => {
});
};
/**
* 根据品牌域名获取品牌LOGO
* @param {string} domain 品牌域名
* @return array | false
*/
const getBrandLogoByDomain = (domain) => {
return api.get('', {
method: 'web.brand.byDomain',
domain: domain
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
if (result.data) {
let formatData = camelCase(result.data);
return {
id: formatData.id,
url: helpers.urlFormat('', null, formatData.brandDomain),
thumb: helpers.image(formatData.brandIco, 75, 40),
name: formatData.brandName,
shopId: formatData.shopId ? formatData.shopId : 0,//店铺id
type: formatData.type ? formatData.type : 0
}
} else {
return false;
}
} else {
logger.error('获取品牌logo接口返回code 不是 200');
return {};
}
});
};
/**
* 根据brandId 获取相关店铺列表
* @param brandId
* @return array
*/
const getBrandShops = (brandId) => {
return api.get('', {
method: 'app.shop.queryShopsByBrandId',
brand_id: brandId
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return _processBrandShops(result.data);
} else {
logger.error('根据brandId获取店铺列表接口返回code 不是 200');
return {};
}
});
};
/**
* 收藏
* @param {int} id 品牌ID
* @param {int} uid 用户ID
* @param {bool} isBrand 是品牌还是商品
* @return array
*/
const setFavorite = (id, uid, isBrand) => {
isBrand = isBrand || true;
return api.post('', {
method: 'app.favorite.add',
id: id,
uid: uid,
type: isBrand ? 'brand' : 'product'
});
};
/**
* 取消收藏
*
* @param {int} id 品牌ID
* @param {int} uid 用户ID
* @param {bool} isBrand 是品牌还是商品
* @return array
*/
const setFavoriteCancel = (id, uid, isBrand) => {
isBrand = isBrand || true;
return api.post('', {
method: 'app.favorite.cancel',
fav_id: id,
uid: uid,
type: isBrand ? 'brand' : 'product'
});
};
/**
* 获取店铺装修的所有资源接口
* @param {int} shopId 店铺id
* @return array
*/
const getShopDecorator = (shopId) => {
return api.get('', {
method: 'app.shopsdecorator.getList',
shop_id: shopId
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return camelCase(result);
} else {
logger.error('获取店铺装修的所有资源接口返回code 不是 200');
return {};
}
});
};
/**
* 获取店铺信息
* @param {int} shopId 店铺id
* @param {int} uid 用户id 判断用户是否收藏店铺
* @return array
*/
const getShopInfo = (shopId, uid) => {
return api.get('', {
method: 'app.shops.getIntro',
shop_id: shopId,
uid: uid || 0
}).then((result) => {
if (result && result.code === 200) {
return camelCase(result);
} else {
logger.error('获取店铺信息接口返回code 不是 200');
return {};
}
});
};
/**
* 获取店铺下面的所有分类
* @param {int} shopId 店铺id
* @return array
*/
const getShopCategory = (shopId, channel) => {
return api.get('', {
method: 'app.shop.getSortInfo',
yh_channel: channel,
shop_id: shopId
}).then((result) => {
if (result && result.code === 200) {
return camelCase(result);
} else {
logger.error('获取店铺下面的所有分类接口返回code 不是 200');
return {};
}
});
};
/**
* 组织店铺页面数据
* @param {array} data 接口返回的店铺页所需数据
* @param {int} shopId 店铺id
* @param {int} isAap app版本
* @return array
*/
const formShopData = (data, shopId, isApp) => {
};
module.exports = {
getSearchData,
getFilterData,
getAllBrandNames,
getClassNames
getClassNames,
getBrandLogoByDomain,
getBrandIntro,
getBrandShops,
getBrandBanner,
setFavorite,
setFavoriteCancel,
getShopDecorator,
getShopInfo,
getShopCategory,
formShopData
};
... ...
... ... @@ -59,5 +59,7 @@ router.get('/search/list', search.list);
router.get('/search/filter', search.filter);
router.get('/search/search', search.search);
router.get('/index/index', search.category);
router.get('/index/brand', search.brand);
router.post('/opt/favoriteBrand', search.favoriteBrand);
module.exports = router;
... ...
... ... @@ -15,11 +15,14 @@ module.exports = {
port: 6001,
siteUrl: '//m.yohobuy.com',
domains: {
// api: 'http://devapi.yoho.cn:58078/',
// service: 'http://devservice.yoho.cn:58077/'
//api: 'http://devapi.yoho.cn:58078/',
//service: 'http://devservice.yoho.cn:58077/'
//
//api: 'http://testapi.yoho.cn:28078/',
//service: 'http://testservice.yoho.cn:28077/'
api: 'http://testapi.yoho.cn:28078/',
service: 'http://testservice.yoho.cn:28077/'
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/'
},
subDomains: {
host: '.m.yohobuy.com',
... ...
/**
* 底部JS
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/26
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer');
var floatLayerBtnHammer;
require('../common');
/**
* 获取url参数
*/
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return window.unescape(r[2]);
}
return null;
}
function downLoadApp() {
var appUrl = 'http://union.yoho.cn/union/downapp.html';
var clickedAt = new Date();
setTimeout(function() {
var mkt = getQueryString('mkt_code');
if ((new Date()) - clickedAt < 2000) {
if (mkt) {
appUrl += '?union_type=' + mkt;
}
window.location = appUrl;
}
}, 500);
}
$('#float-layer-close').on('touchend', function(e) {
$('#float-layer-app').hide();
window.setCookie('_float-layer-app', 'id490655927',
{
domain: '.yohobuy.com'
});
window.setCookie('_float-layer-app-close', 1,
{
domain: '.yohobuy.com',
expires: 1
});
return false;
});
if ($('#float-layer-btn') && $('#float-layer-btn')[0]) {
floatLayerBtnHammer = new Hammer($('#float-layer-btn')[0]);
floatLayerBtnHammer.on('tap', function(e) {
downLoadApp('bottom');
e.srcEvent.stopPropagation();
});
if (typeof window.cookie === 'function' && !window.cookie('_float-layer-app')) {
$('#float-layer-app').show();
} else {
$('#float-layer-app').hide();
}
}
... ...
... ... @@ -5,3 +5,4 @@
*/
require('./search/list');
require('../common/footer');
... ...
... ... @@ -43,7 +43,7 @@ var $listNav = $('#list-nav'),
// 导航数据信息
navInfo = {
newest: {
order: 1,
order: 0,
reload: true,
page: 0,
end: false
... ...
... ... @@ -53,3 +53,93 @@
width: 100%;
}
}
.float-layer {
height: 64PX;
background: rgba(68, 68, 68, 0.95);
position: fixed;
width: 100%;
bottom: 0;
left: 0;
z-index: 9999;
padding: 10PX 0;
.float-layer-left {
padding-left: 22PX;
overflow: hidden;
float: left;
img {
height: 44PX;
float: left;
margin-right: 10PX;
}
p {
float: left;
font-size: 16PX;
height: 44PX;
line-height: 44PX;
color: white;
}
.yoho-icon {
float: left;
margin-right: 10PX;
font-size: 22PX;
line-height: 44PX;
width: 44PX;
height: 44PX;
text-align: center;
color: #fff;
border-radius: 10PX;
background-image: linear-gradient(#323232, #0f0f0f);
}
}
}
#float-layer-close {
position: absolute;
left: 0;
top: 0;
width: 50PX;
height: 50PX;
.close-icon {
position: absolute;
left: 0;
top: 0;
color: #C0C0C0;
z-index: 2;
}
}
#float-layer-btn {
position: absolute;
top: 50%;
right: 15PX;
font-size: 16PX;
padding: 0 10PX;
height: 27PX;
line-height: 27PX;
background: white;
border-radius: 5PX;
margin-top: -13PX;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0.5);
&:link,
&:visited,
&:hover,
&:active {
color: #000;
}
}
.circle-rightbottom {
position: absolute;
width: 25PX;
height: 0PX;
border: 0 solid #323232;
border-bottom: 25PX solid #323232;
border-radius: 0 0 25PX 0;
}
... ...
... ... @@ -60,6 +60,7 @@
font-size: 34px;
background: #fff;
color: #000;
overflow: hidden;
}
span {
... ...