Authored by yyq

店铺调整

... ... @@ -13,13 +13,10 @@ const searchApi = require(`${mRoot}/search-api`);
// 店铺页
const shop = (shopId, req, res, next) => {
shopId = parseInt(shopId, 10);
list.getShopInfo(shopId, req.user.id).then(shopInfo => {
shopInfo.shopTemplateType = 2;
if (shopInfo.shopTemplateType === 2) {
// 经典模板
if (+shopInfo.shopTemplateType === 2) { // 经典模板
list.getShopData(shopId, req.yoho.channel, req.query, shopInfo).then(result => {
Object.assign(result, {
page: 'shop',
... ... @@ -27,10 +24,7 @@ const shop = (shopId, req, res, next) => {
});
res.render('list/shop-index', result);
}).catch(next);
} else {
// 基础模板
} else { // 基础模板
list.getBaseShopData(shopId, req.user.id, req.query).then(result => {
res.render('list/index', result);
}).catch(next);
... ... @@ -77,17 +71,15 @@ exports.new = (req, res, next) => {
* @return {[type]} [description]
*/
exports.brand = (req, res, next) => {
let brandDomain = req.brandDomain || 'sctest1';
let shopId = req.query.shopId;
let resData = {};
// req.shopId存在,直接走店铺
if (req.shopId) {
return shop(req.shopId, req, res, next);
// shopId存在,直接走店铺
if (shopId) {
return shop(shopId, req, res, next);
}
// let brandDomain = 'colormad';
let brandDomain = req.brandDomain || 'sctest1';
// 获取品牌信息
list.getBrandInfo({domain: brandDomain}).then(brandInfo => {
switch (parseInt(brandInfo.type, 10)) {
... ...
... ... @@ -326,8 +326,7 @@ exports.getShopInfo = (shopId, uid) => {
showShopName: result.data.is_show_shop_name === 'Y'
};
} else {
// log
return {};
}
});
};
... ... @@ -375,6 +374,8 @@ exports.getShopData = (shopId, channel, params, shopInfo) => {
name: '全部商品 ALL',
sort: searchHandler.handleOptsData(params, _.get(result[2], 'data.total', 0)),
list: productProcess.processProductList(_.get(result[2], 'data.product_list', []), {
newCoverSort: true,
showDiscount: false,
gender: gender
})
};
... ... @@ -417,6 +418,8 @@ exports.getShopData = (shopId, channel, params, shopInfo) => {
let coverList = {};
prodList = productProcess.processProductList(_.get(subRes[0], 'data.product_list', []), {
newCoverSort: true,
showDiscount: false,
gender: gender
});
... ... @@ -515,6 +518,8 @@ exports.getShopListData = (channel, params) => {
filters: searchHandler.handleFilterData(_.get(result[2], 'data.filter', {}), params),
opts: searchHandler.handleOptsData(params, tip.total),
goods: productProcess.processProductList(_.get(result[2], 'data.product_list', []), {
newCoverSort: true,
showDiscount: false,
gender: _getGender(channel)
}),
footPager: {tip: tip}
... ...
... ... @@ -12,11 +12,15 @@ const images = require(`${global.utils}/images`);
* 否则优先从cover1 --》 cover2 -- 》 images_url
*
*/
const procProductImg = (product, gender) => {
const procProductImg = (product, gender, newSort) => {
if (gender === '2,3') {
return product.cover2 || product.cover1 || product.imagesUrl || '';
}
if (newSort && gender === '1,2,3') {
return product.imagesUrl || '';
}
return product.cover1 || product.cover2 || product.imagesUrl || '';
};
... ... @@ -39,7 +43,35 @@ const handleGoodsListData = (origin) => {
};
/**
* 根据性别来决定 默认图片获取字段 如果是 2、3
* 处理搜索返回同一skc分男女封分别返回问题
* @param array $images
* @return string 商品图片
*/
const procGoodsList = (goodsList) => {
let list = {};
if (!_.isEmpty(goodsList)) {
let goods = _.cloneDeep(goodsList);
_.forEach(goods, value => {
if (!list[value.productSkc]) {
list[value.productSkc] = value;
} else {
if (value.cover1) {
list[value.productSkc].cover1 = value.cover1;
}
if (value.cover2) {
list[value.productSkc].cover2 = value.cover2;
}
}
});
}
return _.toArray(list);
};
/**
* 处理
*
* 2、3: cover2 --> images_url -> cover1
* 1,3 :cover1 --> images_url -> cover2
... ... @@ -72,9 +104,8 @@ exports.processProductList = (list, options) => {
showTags: true,
showNew: true,
showSale: true,
// 显示折扣
showDiscount: true,
showDiscount: true, // 显示折扣
newCoverSort: false, // 新封面排序
width: 290,
height: 388,
isApp: false,
... ... @@ -105,17 +136,17 @@ exports.processProductList = (list, options) => {
}
// 如果设置了默认图片,就取默认的图片
_.forEach(product.goodsList, (goods) => {
_.forEach(procGoodsList(product.goodsList), (goods) => {
// (颜色优先)
if (options.color) {
if (goods.colorId === options.color) {
product.defaultImages = procProductImg(goods, options.gender);
product.defaultImages = procProductImg(goods, options.gender, options.newCoverSort);
return;
}
} else {
if (goods.isDefault === 'Y') {
product.defaultImages = procProductImg(goods, options.gender);
product.defaultImages = procProductImg(goods, options.gender, options.newCoverSort);
return;
}
}
... ... @@ -123,7 +154,7 @@ exports.processProductList = (list, options) => {
// 如果还未赋值,则取第一个skc产品的默认图片
if (!product.defaultImages) {
product.defaultImages = procProductImg(product.goodsList[0]);
product.defaultImages = procProductImg(product.goodsList[0], options.gender, options.newCoverSort);
}
product = Object.assign(product, {
... ...