...
|
...
|
@@ -20,6 +20,8 @@ const DEFAULT_IMG = '01091c21f2317a64f123f1649fbbccf7ba'; |
|
|
// 经典店铺list url
|
|
|
const shopListUrl = '/product/shoplist';
|
|
|
|
|
|
const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime'];
|
|
|
|
|
|
/**
|
|
|
* channel=>gender
|
|
|
*/
|
...
|
...
|
@@ -266,42 +268,158 @@ const _getShopData = (channel, params, shopInfo) => { |
|
|
})();
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取基础模板店铺数据
|
|
|
*/
|
|
|
const _getBaseShopData = (channel, params, shopInfo) => {
|
|
|
params = params || {};
|
|
|
|
|
|
let searchParams = searchHandler.getSearchParams(params);
|
|
|
let shopId = params.shopId;
|
|
|
|
|
|
return co(function * () {
|
|
|
let result = yield Promise.props({
|
|
|
header: headerModel.requestHeaderData(channel), // 头部数据
|
|
|
sort: searchApi.getSortList({shop_id: shopId}),
|
|
|
decorator: searchApi.getShopDecorator(shopId), // 店铺装修数据
|
|
|
product: searchApi.getProductList(Object.assign(searchParams,
|
|
|
{shop_id: shopId}), 'shop'), // 搜索店铺商品
|
|
|
coupons: api.shopCouponListAsync(shopId), // 店铺优惠券数据
|
|
|
shopInfo: shopInfo ? Promise.resolve(shopInfo) : api.getShopInfo(shopId)
|
|
|
});
|
|
|
|
|
|
if (result.shopInfo && result.shopInfo.code === 200) {
|
|
|
shopInfo = result.shopInfo.data;
|
|
|
}
|
|
|
|
|
|
const shopName = shopInfo.shop_name;
|
|
|
|
|
|
let resData = {
|
|
|
shopId: shopId,
|
|
|
brand: Object.assign({brandShopAd: true},
|
|
|
searchHandler.handlePathNavData({brandName: shopName}, params, 'shop', channel))
|
|
|
};
|
|
|
|
|
|
Object.assign(resData,
|
|
|
result.header, // 头部数据
|
|
|
searchHandler.getBrandShopSeo(channel, {shopName: shopName}, params));
|
|
|
|
|
|
_.set(resData, 'headerData.header', true);
|
|
|
_.set(resData, 'brand.shopBanner', {
|
|
|
shopId: shopId,
|
|
|
shopName: shopName,
|
|
|
shopHome: `/?shopId=${shopId}`,
|
|
|
shopIntro: `/shop${shopId}-about`
|
|
|
});
|
|
|
|
|
|
// 店铺装修
|
|
|
if (result.decorator.code === 200) {
|
|
|
let data = result.decorator.data || {},
|
|
|
decorator = shopHandler.getShopDecorator(data, {}, shopId, true);
|
|
|
|
|
|
Object.assign(resData.brand.shopBanner, decorator.shopTopBannerBase || {});
|
|
|
|
|
|
// 设置店招高度
|
|
|
_.set(resData, 'brand.shopBanner.bannerHeight', 150);
|
|
|
|
|
|
if (decorator.signboard) {
|
|
|
_.set(resData, 'brand.signboard', decorator.signboard);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取左侧类目数据
|
|
|
if (result.sort.code === 200) {
|
|
|
let dps = {shopId: shopId};
|
|
|
|
|
|
_.forEach(needParams, value => {
|
|
|
if (params[value]) {
|
|
|
dps[value] = params[value];
|
|
|
}
|
|
|
});
|
|
|
|
|
|
Object.assign(resData.brand, {
|
|
|
leftContent: searchHandler.handleSortData(result.sort.data, dps, params)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 获取商品数据和顶部筛选条件
|
|
|
if (result.product.code === 200) {
|
|
|
let data = result.product.data;
|
|
|
let filters = Object.assign(searchHandler.handleFilterDataAll(data, params),
|
|
|
resData.brand.leftContent.sort);
|
|
|
|
|
|
filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,
|
|
|
resData.brand.leftContent.checked);
|
|
|
|
|
|
Object.assign(resData.brand, {
|
|
|
filters: filters,
|
|
|
opts: searchHandler.handleOptsData(params, data.total, data.filter),
|
|
|
totalCount: data.total,
|
|
|
footPager: searchHandler.handlePagerData(data.total, params),
|
|
|
goods: productProcess.processProductList(data.product_list,
|
|
|
Object.assign({showDiscount: false, from: {type: 'shop', params: params}}, params)),
|
|
|
hasNextPage: searchHandler.handleNextPage(params, data.total),
|
|
|
|
|
|
// 最近浏览记录
|
|
|
latestWalk: 7
|
|
|
});
|
|
|
|
|
|
// 店铺页不显示品牌筛选项
|
|
|
_.unset(resData, 'brand.filters.brand');
|
|
|
}
|
|
|
|
|
|
// 店铺优惠券
|
|
|
if (result.coupons && !_.isEmpty(result.coupons.data)) {
|
|
|
_.set(resData, 'brand.coupon',
|
|
|
searchHandler.handleBrandShopCoupons(result.coupons.data, {shopId: shopId}));
|
|
|
}
|
|
|
|
|
|
return resData;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
exports.getShopInfoAsync = (domain, channel, params) => {
|
|
|
let resData;
|
|
|
let shopId = _.get(params, 'shopId');
|
|
|
|
|
|
return co(function * () {
|
|
|
let data, shopInfo;
|
|
|
|
|
|
_.unset(params, 'domain');
|
|
|
domain = _.toLower(domain);
|
|
|
|
|
|
if (shopId) {
|
|
|
if (shopId) { // 带id访问
|
|
|
let result = yield api.getShopInfo(shopId);
|
|
|
let data = result.data;
|
|
|
|
|
|
data = result.data;
|
|
|
|
|
|
// 根据店铺ID,未取到店铺信息,跳转至首页
|
|
|
if (result.code !== 200 || _.isEmpty(data)) {
|
|
|
return {redirect: helpers.urlFormat('')};
|
|
|
}
|
|
|
|
|
|
let lowResDomain = _.toLower(data.shop_domain);
|
|
|
|
|
|
// 根据店铺ID取到的店铺domain与链接中domain不一致,跳转至店铺域名下(解决店铺域名与品牌域名混用的问题)
|
|
|
if (data.shop_domain !== domain) {
|
|
|
return {redirect: helpers.urlFormat('', params, data.shop_domain)};
|
|
|
if (lowResDomain !== domain) {
|
|
|
return {redirect: helpers.urlFormat('', params, lowResDomain)};
|
|
|
}
|
|
|
|
|
|
if (+data.shop_template_type === 2) {
|
|
|
let resData = yield _getShopData(channel, params, data);
|
|
|
|
|
|
return Object.assign(resData, {templateType: +data.shop_template_type});
|
|
|
}
|
|
|
} else {
|
|
|
shopInfo = data;
|
|
|
} else { // 以店铺域名方式直接访问
|
|
|
let result = yield searchApi.getBrandData({domain: domain});
|
|
|
let data = result.data;
|
|
|
|
|
|
data = result.data;
|
|
|
|
|
|
// 未取到domain信息,跳转至首页
|
|
|
if (result.code !== 200) {
|
|
|
return {redirect: helpers.urlFormat('')};
|
|
|
}
|
|
|
|
|
|
// domain类型不为店铺,跳转至搜索
|
|
|
if (data.type * 1 !== 2) {
|
|
|
let d = {query: _.toLower(domain)};
|
|
|
let d = {query: domain};
|
|
|
|
|
|
if (data.id) {
|
|
|
d.brand = data.id;
|
...
|
...
|
@@ -311,13 +429,15 @@ exports.getShopInfoAsync = (domain, channel, params) => { |
|
|
}
|
|
|
|
|
|
params.shopId = data.shop_id;
|
|
|
}
|
|
|
|
|
|
if (+data.shop_template_type === 2) {
|
|
|
let resData = yield _getShopData(channel, params);
|
|
|
|
|
|
return Object.assign(resData, {templateType: +data.shop_template_type});
|
|
|
}
|
|
|
if (+data.shop_template_type === 2) { // 经典店铺
|
|
|
resData = yield _getShopData(channel, params, shopInfo);
|
|
|
} else {
|
|
|
resData = yield _getBaseShopData(channel, params, shopInfo);
|
|
|
}
|
|
|
|
|
|
return Object.assign(resData, {templateType: +data.shop_template_type});
|
|
|
})();
|
|
|
};
|
|
|
|
...
|
...
|
|