...
|
...
|
@@ -7,7 +7,6 @@ |
|
|
const utils = '../../../utils';
|
|
|
const logger = global.yoho.logger;
|
|
|
const crypto = global.yoho.crypto;
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const api = global.yoho.API;
|
...
|
...
|
@@ -27,16 +26,13 @@ const yhChannel = { |
|
|
|
|
|
/* 多品牌店铺列表数据信息处理*/
|
|
|
const _processBrandShops = (list) => {
|
|
|
const formatDat = [];
|
|
|
let formatDat = [];
|
|
|
|
|
|
list = list || [];
|
|
|
list = camelCase(list);
|
|
|
|
|
|
_.forEach(list, (item) => {
|
|
|
if (item.shopId) {
|
|
|
_.forEach(list, item => {
|
|
|
if (item.shop_id) {
|
|
|
formatDat.push({
|
|
|
url: helpers.urlFormat('/product/index/brand/', {
|
|
|
shop_id: item.brandId
|
|
|
shop_id: item.shop_id
|
|
|
}),
|
|
|
thumb: helpers.image(item.brandIco, 75, 40),
|
|
|
name: item.brandName
|
...
|
...
|
@@ -98,11 +94,7 @@ const _getShopDecorator = (shopId) => { |
|
|
cache: true,
|
|
|
code: 200
|
|
|
}).then((result) => {
|
|
|
if (result.data) {
|
|
|
return camelCase(result.data);
|
|
|
} else {
|
|
|
return '';
|
|
|
}
|
|
|
return result.data;
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -118,11 +110,7 @@ const _getShopInfo = (shopId, uid) => { |
|
|
shop_id: shopId,
|
|
|
uid: uid || 0
|
|
|
}, {code: 200}).then((result) => {
|
|
|
if (result.data) {
|
|
|
return camelCase(result.data);
|
|
|
} else {
|
|
|
return {};
|
|
|
}
|
|
|
return result.data;
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -139,11 +127,7 @@ const _getShopCategory = (shopId, channel, gender) => { |
|
|
gender: gender || '1,3',
|
|
|
shop_id: shopId
|
|
|
}, {code: 200}).then(result => {
|
|
|
if (result && result.code === 200) {
|
|
|
return camelCase(result.data);
|
|
|
} else {
|
|
|
return {};
|
|
|
}
|
|
|
return result.data;
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -212,11 +196,8 @@ const getShopBrands = (shopId) => { |
|
|
method: 'app.shops.getShopsBrands',
|
|
|
shop_id: shopId
|
|
|
}, {code: 200}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
result = camelCase(result.data);
|
|
|
return result[0].brandId;
|
|
|
} else {
|
|
|
return {};
|
|
|
if (result[0]) {
|
|
|
return result[0].brand_id;
|
|
|
}
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -256,10 +237,10 @@ const _formShopData = (data, shopId, isApp) => { |
|
|
if (data.decorator) {
|
|
|
|
|
|
_.forEach(data.decorator.list, floor => {
|
|
|
let resData = JSON.parse(floor.resourceData);
|
|
|
let resData = JSON.parse(floor.resource_data);
|
|
|
|
|
|
if (floor.resourceName) {
|
|
|
floor[_.camelCase(floor.resourceName)] = true;
|
|
|
if (floor.resource_name) {
|
|
|
floor[_.camelCase(floor.resource_name)] = true;
|
|
|
}
|
|
|
|
|
|
// 店铺banner
|
...
|
...
|
@@ -382,10 +363,11 @@ const _formShopData = (data, shopId, isApp) => { |
|
|
};
|
|
|
|
|
|
formatData = _.assign({
|
|
|
shopIntro: data.shopInfo.shopIntro,
|
|
|
logoImg: data.shopInfo.shopLogo,
|
|
|
storeName: (data.shopInfo.isShowShopName === 'Y') ? data.shopInfo.shopName : '',
|
|
|
collect: data.shopInfo.isFavorite === 'Y',
|
|
|
shopIntro: _.get(data, 'shopInfo.shop_intro', ''),
|
|
|
logoImg: _.get(data, 'shopInfo.shop_logo', ''),
|
|
|
storeName: (_.get(data, 'shopInfo.is_show_shop_name', '') === 'Y') ?
|
|
|
_.get(data, 'shopInfo.shop_name', '') : '',
|
|
|
collect: _.get(data, 'shopInfo.is_favorite', '') === 'Y',
|
|
|
url: helpers.urlFormat('', {
|
|
|
shop_id: shopId
|
|
|
}, 'search'), // 搜索链接
|
...
|
...
|
@@ -434,14 +416,14 @@ const _formShopData = (data, shopId, isApp) => { |
|
|
shop_id: shopId
|
|
|
});
|
|
|
} else {
|
|
|
_.forEach(data.shopCategory, (item) => {
|
|
|
_.forEach(data.shopCategory, item => {
|
|
|
shopCategory.list.push({
|
|
|
url: helpers.urlFormat('', {
|
|
|
shop_id: shopId,
|
|
|
sort: item.relationParameter.sort
|
|
|
sort: item.relation_parameter.sort
|
|
|
}, 'search'),
|
|
|
categoryId: item.categoryId,
|
|
|
name: item.categoryName
|
|
|
categoryId: item.category_id,
|
|
|
name: item.category_name
|
|
|
});
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -477,8 +459,8 @@ const getBaseShopData = (params, shopInfo) => { |
|
|
|
|
|
if (result[0] && _.has(result[0], 'list')) {
|
|
|
_.forEach(result[0].list, item => {
|
|
|
if (item.resourceName === 'shopTopBanner_base') {
|
|
|
let banner = JSON.parse(item.resourceData);
|
|
|
if (item.resource_name === 'shopTopBanner_base') {
|
|
|
let banner = JSON.parse(item.resource_data);
|
|
|
|
|
|
finalResult = _.assign(finalResult, {
|
|
|
baseShopHome: {
|
...
|
...
|
@@ -515,13 +497,10 @@ const getShopData = (req, shopId, uid, isApp) => { |
|
|
let shopData = {};
|
|
|
let channel = req.yoho.channel;
|
|
|
|
|
|
/* 变量污染临时处理 */
|
|
|
// shopId = shopId.replace(/\//, '');
|
|
|
|
|
|
return _getShopInfo(shopId, uid).then(shopInfoResult => {
|
|
|
|
|
|
/* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
|
|
|
if (shopInfoResult.shopTemplateType && parseInt(shopInfoResult.shopTemplateType, 10) === 1) {
|
|
|
if (shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) {
|
|
|
return {
|
|
|
goBrand: shopInfoResult
|
|
|
};
|
...
|
...
|
@@ -556,7 +535,8 @@ const getShopData = (req, shopId, uid, isApp) => { |
|
|
let shopCoupons = result[2] || [];
|
|
|
|
|
|
// 店铺分类
|
|
|
return _getShopCategory(shopId, channel).then((shopCategory) => {
|
|
|
return _getShopCategory(shopId, channel).then(shopCategory => {
|
|
|
|
|
|
shopData = _.assign({
|
|
|
shopCategory: shopCategory
|
|
|
}, shopData);
|
...
|
...
|
@@ -597,31 +577,27 @@ const getShopFav = (req, shopId, uid) => { |
|
|
* @return array banner数据
|
|
|
*/
|
|
|
const getBrandIntro = (brandId, uid) => {
|
|
|
let param = {};
|
|
|
|
|
|
param = {
|
|
|
uid: uid,
|
|
|
let param = {
|
|
|
uid: uid
|
|
|
};
|
|
|
|
|
|
return api.get('', _.assign({
|
|
|
method: 'app.brand.getBrandIntro',
|
|
|
brand_id: brandId
|
|
|
}, param), {
|
|
|
code: 200,
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
let list = camelCase(result.data) || {};
|
|
|
}).then(result => {
|
|
|
|
|
|
let list = result.data;
|
|
|
|
|
|
return {
|
|
|
id: list.brandId,
|
|
|
intro: list.brandIntro,
|
|
|
collected: (list.isFavorite && list.isFavorite === 'Y') ? true : false,
|
|
|
title: list.brandName ? list.brandName : ''
|
|
|
id: list.brand_id,
|
|
|
intro: list.brand_intro,
|
|
|
collected: list.is_favorite && list.is_favorite === 'Y',
|
|
|
title: list.brand_name ? list.brand_name : ''
|
|
|
};
|
|
|
} else {
|
|
|
logger.error('get brand introduction api return code is not 200');
|
|
|
return {};
|
|
|
}
|
|
|
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -660,27 +636,23 @@ const getBrandLogoByDomain = (domain) => { |
|
|
method: 'web.brand.byDomain',
|
|
|
domain: domain
|
|
|
}, {
|
|
|
code: 200,
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
}).then(result => {
|
|
|
if (result.data) {
|
|
|
let formatData = camelCase(result.data);
|
|
|
let formatData = 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
|
|
|
url: helpers.urlFormat('', null, formatData.brand_domain),
|
|
|
thumb: helpers.image(formatData.brand_ico, 75, 40),
|
|
|
name: formatData.brand_name,
|
|
|
shopId: formatData.shop_id ? formatData.shop_id : 0, // 店铺id
|
|
|
type: formatData.type ? formatData.type : 0
|
|
|
};
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
} else {
|
|
|
logger.error('get brand logo by domain api return code is not 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -694,13 +666,13 @@ const getBrandShops = (brandId) => { |
|
|
method: 'app.shop.queryShopsByBrandId',
|
|
|
brand_id: brandId
|
|
|
}, {
|
|
|
code: 200,
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
}).then(result => {
|
|
|
if (_.isArray(result.data)) {
|
|
|
return _processBrandShops(result.data);
|
|
|
} else {
|
|
|
logger.error('get shop list by brandId api return code is not 200');
|
|
|
return {};
|
|
|
return [];
|
|
|
}
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -748,13 +720,8 @@ const getShopIntro = (shopId) => { |
|
|
return api.get('', {
|
|
|
method: 'app.shops.getIntro',
|
|
|
shop_id: shopId
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return camelCase(result.data);
|
|
|
} else {
|
|
|
logger.error('get shop intro api return code is not 200');
|
|
|
return {};
|
|
|
}
|
|
|
}, {code: 200, cache: true}).then(result => {
|
|
|
return result.data;
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -779,7 +746,7 @@ const getShopCategory = (params) => { |
|
|
_.forEach(value.sub, (subValue, subKey) => {
|
|
|
value.sub[subKey].url = helpers.urlFormat('/product/search/list', {
|
|
|
shop_id: params.shopId,
|
|
|
sort: _.get(value, 'relationParameter.sort', ''),
|
|
|
sort: _.get(value, 'relation_parameter.sort', ''),
|
|
|
title: subValue.categoryName,
|
|
|
query: subValue.categoryName
|
|
|
});
|
...
|
...
|
|