Authored by 王水玲

店铺

... ... @@ -7,32 +7,159 @@
'use strict';
const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header');
//const resourcesProcess = require(`${utils}/resources-process`);
const searchModel = require(`${mRoot}/search`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
//const _processShopInfo = (list) => {
// let formatData = {
// logoImg: helpers.image(list.shopLogo, 500, 500),
// storeName: (list.isShowShopName === 'Y') ? list.shopName : '',
// collect: (list.isFavorite === 'Y') ? true : false
// };
//
// let allGoodsParam = {
// title: '全部商品'
// }
//
// return {};
//};
/**
* 组织店铺页面数据
* @param {array} data 接口返回的店铺页所需数据
* @param {int} shopId 店铺id
* @param {int} isApp app版本
* @return array
*/
const _formShopData = (data, shopId, isApp) => {
let formatData = {},
single = false,
shopIdObj = {
shop_id: shopId
};
let brandId;
//signboard
//oneRowTwoColImages
//allHotProducts
//shopTopBanner
//brandBrowse
//recommend
//shopTopBannerApp
//hotRecommend
//oneRowTwoColImagesApp
//recommendApp
//navigationBar
//newProducts
//goodsTabBar
//hotProductsApp
//largeSlideImg
//shopTopBannerBase
//hotProducts
//largeSlideImgApp
//allNewProducts
//allHotProductsApp
// 组织店铺装修
if (data.decorator) {
_.forEach(data.decorator.list, (floor) => {
floor[_.camelCase(floor.resourceName)] = true;
// 店铺banner
if (floor.shopTopBannerApp) {
formatData.branerImg = helpers.image(JSON.parse(floor.resourceData)[0].shopSrc, 640, 200, 1);
}
// 资源位小图 接口返回两组,取每组第一张
if (floor.oneRowTwoColImagesApp) {
let jsonData = JSON.parse(floor.resourceData);
_.forEach(jsonData, (key, item) => {
if (key === 0 && item.data) {
formatData.spring = {
url: item.data.url,
springType: helpers.image(item.data.src)
}
}
});
}
// 店铺品牌一览
if (floor.brandBrowse) {
}
});
}
// 店铺基本信息
if (data.shopInfo) {
let allGoodsParam = {
title: '全部商品'
};
formatData = {
logoImg: helpers.image(data.shopInfo.shopLogo, 500, 500),
storeName: (data.shopInfo.isShowShopName === 'Y') ? list.shopName : '',
collect: (data.shopInfo.isFavorite === 'Y') ? true : false,
url: helpers.urlFormat('', shopIdObj, 'search'), // 搜索链接
more_url: helpers.urlFormat('', {
shop_id: shopId,
order: 's_n_d',
title: '人气单品'
}, 'search') // 人气单品的链接
};
if (single) { // 单品点
allGoodsParam.brand = brandId;
} else { // 店铺id
formatData.shopId = shopId;
allGoodsParam.shopId = shopId;
}
if (!isApp) {
_.assign({
allGoods: helpers.urlFormat('', allGoodsParam, 'search'),
shopIntroHref: helpers.urlFormat('/product/index/intro', shopIdObj) // 店铺简介页地址
}, formatData);
} else {
_.assign({
allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":"' . self::$shopId . '","page":"1"}}`,
shopIntroHref: helpers.urlFormat('/product/index/intro', {
shop_id: shopId,
app_version: isApp
}),
more_url: `openby:yohobuy{"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}`
}, formatData);
}
}
return formatData;
};
/**
* 新店铺首页
* @param {object} req
* @param {int} shopId 店铺id
* @param {int} uid 用户id
* @param {string} isApp app版本
* @return array
*/
const _getShopData = (shopId, uid, isApp) => {
const _getShopData = (req, shopId, uid, isApp) => {
let data = {};
let channel = req.yoho.channel;
isApp = isApp || '';
Promise.all([searchModel.getShopDecorator(shopId),searchModel.getShopInfo(shopId, uid)]).then((result) => {
return 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) {
if (data.shopInfo.shopTemplateType && data.shopInfo.shopTemplateType === '1') {
return {
goBrand: data.shopInfo.data
goBrand: data.shopInfo
}
}
... ... @@ -43,7 +170,7 @@ const _getShopData = (shopId, uid, isApp) => {
shopCategory: shopCategory
}, data);
return searchModel.formShopData(data, shopId, isApp); // 组织楼层数据
return _formShopData(data, shopId, isApp); // 组织楼层数据
});
};
... ... @@ -70,13 +197,13 @@ const _shop = (req, res, shopId) => {
});
}
_getShopData(shopId, uid, isApp).then((result) => {
_getShopData(req, shopId, uid, isApp).then((result) => {
if (result.goBrand) {
// 跳转基础模板
_baseShop(result.goBrand);
//_baseShop(result.goBrand);
}
res.render('shop', {
res.render('shop/index', _.assign({
shopIndex: result,
shopPage: {
text: '分类',
... ... @@ -86,10 +213,8 @@ const _shop = (req, res, shopId) => {
},
gender: req.query.gender,
channel: req.query.channel
}
}, pageHeader));
});
};
// 搜索落地页
... ... @@ -206,7 +331,7 @@ const category = (req, res) => {
// 品牌落地页
const brand = (req, res, next) => {
let params = Object.assign({}, req.query);
let domain = 'vans';
let domain = 'colormad';
let uid = req.user.uid || 20000032;
let brandId = 0;
let brandLogo = {};
... ... @@ -223,9 +348,9 @@ const brand = (req, res, next) => {
title = brandLogo.name;
//无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面
if (brandLogo.type === 2 && brandLogo.shopId) {
if (brandLogo.type === '2' && brandLogo.shopId) {
_shop(req, res, brandLogo.shopId);
return false;
return false
}
if (brandLogo && brandLogo.id) {
... ...
... ... @@ -166,7 +166,7 @@ const getBrandIntro = (brandId, uid) => {
title: list.brandName ? list.brandName : ''
};
} else {
logger.error('获取店铺信息接口返回code 不是 200');
logger.error('get brand introduction api return code is not 200');
return {};
}
});
... ... @@ -191,7 +191,7 @@ const getBrandBanner = (brandId) => {
return '';
}
} else {
logger.error('获取店铺banner接口返回code 不是 200');
logger.error('get brand banner api return code is not 200');
return {};
}
});
... ... @@ -205,7 +205,7 @@ const getSearchData = (params) => {
if (result && result.code === 200) {
return productProcess.processProductList(result.data.product_list || []);
} else {
logger.error('商品搜索返回 code 不是 200');
logger.error('get product search api return code is not 200');
return [];
}
});
... ... @@ -221,7 +221,7 @@ const getFilterData = (params) => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || []);
} else {
logger.error('商品搜索返回 code 不是 200');
logger.error('get filter data api return code is not 200');
return [];
}
});
... ... @@ -239,7 +239,7 @@ const getAllBrandNames = () => {
if (result && result.code === 200) {
return _processBrandNames(result.data.brands);
} else {
logger.error('品牌名称接口返回 code 不是 200');
logger.error('get brand all name data api return code is not 200');
return {};
}
});
... ... @@ -257,7 +257,7 @@ const getClassNames = () => {
if (result && result.code === 200) {
return _processClassNames(result.data);
} else {
logger.error('品类名称接口返回 code 不是 200');
logger.error('get category name api return code is not 200');
return {};
}
});
... ... @@ -291,7 +291,7 @@ const getBrandLogoByDomain = (domain) => {
return false;
}
} else {
logger.error('获取品牌logo接口返回code 不是 200');
logger.error('get brand logo by domain api return code is not 200');
return {};
}
});
... ... @@ -312,7 +312,7 @@ const getBrandShops = (brandId) => {
if (result && result.code === 200) {
return _processBrandShops(result.data);
} else {
logger.error('根据brandId获取店铺列表接口返回code 不是 200');
logger.error('get shop list by brandId api return code is not 200');
return {};
}
});
... ... @@ -368,10 +368,10 @@ const getShopDecorator = (shopId) => {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return camelCase(result);
return camelCase(result.data);
} else {
logger.error('获取店铺装修的所有资源接口返回code 不是 200');
return {};
logger.error('get shop all resources api return code is not 200');
return '';
}
});
};
... ... @@ -389,9 +389,9 @@ const getShopInfo = (shopId, uid) => {
uid: uid || 0
}).then((result) => {
if (result && result.code === 200) {
return camelCase(result);
return camelCase(result.data);
} else {
logger.error('获取店铺信息接口返回code 不是 200');
logger.error('get shop info api return code is not 200');
return {};
}
});
... ... @@ -400,6 +400,7 @@ const getShopInfo = (shopId, uid) => {
/**
* 获取店铺下面的所有分类
* @param {int} shopId 店铺id
* @param {string} channel 频道
* @return array
*/
const getShopCategory = (shopId, channel) => {
... ... @@ -409,25 +410,14 @@ const getShopCategory = (shopId, channel) => {
shop_id: shopId
}).then((result) => {
if (result && result.code === 200) {
return camelCase(result);
return camelCase(result.data);
} else {
logger.error('获取店铺下面的所有分类接口返回code 不是 200');
logger.error('get shop all classify api return code is not 200');
return {};
}
});
};
/**
* 组织店铺页面数据
* @param {array} data 接口返回的店铺页所需数据
* @param {int} shopId 店铺id
* @param {int} isApp app版本
* @return array
*/
const formShopData = (data, shopId, isApp) => {
};
module.exports = {
getSearchData,
getFilterData,
... ... @@ -441,6 +431,5 @@ module.exports = {
setFavoriteCancel,
getShopDecorator,
getShopInfo,
getShopCategory,
formShopData
getShopCategory
};
... ...
{{# shopIndex}}
{{log this}}
<div class="shop-index yoho-page" id="wrapper">
<div id="scroller">
<div id="nav-top">
{{!--{{# headerBanner}}
{{> resources/banner-top}}
{{/ headerBanner}}--}}
<!--{{!--{{# headerBanner}}-->
<!--{{> resources/banner-top}}-->
<!--{{/ headerBanner}}--}}-->
<div class="search-area">
<div id="search-input" class="search-input">
<form id="search-form" action={{url}} method="get">
... ...