Authored by 张孝茹

list

... ... @@ -40,7 +40,7 @@ const _getUidFromUserAgent = (req) => {
*/
const _baseShop = (req, res, shopInfo, shopId) => {
listModel.getBaseShopData(Object.assign(req.query, {
req.ctx(listModel).getBaseShopData(Object.assign(req.query, {
channel: req.yoho.channel
}), shopInfo).then(result => {
if (result && result.baseShopHome && result.baseShopHome.banner) {
... ... @@ -79,7 +79,7 @@ const baseShopFav = (req, res) => {
let uid = req.user.uid || req.query.uid || _getUidFromUserAgent(req);
let shopId = req.query.shopId;
listModel.getBrandFavStatus({
req.ctx(listModel).getBrandFavStatus({
uid: uid,
id: shopId,
type: 'shop'
... ... @@ -117,7 +117,7 @@ const _shop = (req, res, shopId) => {
};
}
listModel.getShopData(req, shopId, uid, isApp).then(result => {
req.ctx(listModel).getShopData(req, shopId, uid, isApp).then(result => {
if (result.goBrand) {
/* 若店铺使用基础模板跳转基础模板 */
... ... @@ -190,7 +190,7 @@ const shopFav = (req, res) => {
});
}
listModel.getBrandFavStatus({
req.ctx(listModel).getBrandFavStatus({
uid: uid,
id: shopId,
type: 'shop',
... ... @@ -303,7 +303,7 @@ const brand = (req, res, next) => {
if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) {
_shop(req, res, brandLogo.shopId);
} else { // 获取品牌店铺信息
listModel.getBrandShops(brandId, req).then(brandShop => {
req.ctx(listModel).getBrandShops(brandId, req).then(brandShop => {
if (brandId === 0) {
params.query = domain;
}
... ... @@ -366,7 +366,7 @@ const brandFav = (req, res) => {
req.ctx(shopModel).getBrandLogoByDomain(domain).then((result) => {
brandId = result.id;
listModel.getBrandFavStatus({
req.ctx(listModel).getBrandFavStatus({
uid: uid,
id: brandId,
type: 'brand',
... ... @@ -388,7 +388,7 @@ const shopIntro = (req, res, next) => {
let params = {};
if (parseInt(shopId, 10)) {
listModel.getShopIntro(shopId).then(result => {
req.ctx(listModel).getShopIntro(shopId).then(result => {
if (appVersion) {
params = {
title: '店铺简介'
... ... @@ -459,11 +459,11 @@ const favoriteBrand = (req, res, next) => {
}
if (opt !== 'ok') { // 取消收藏
listModel.setFavoriteCancel(id, uid, type).then(result => {
req.ctx(listModel).setFavoriteCancel(id, uid, type).then(result => {
res.json(result);
}).catch(next);
} else {
listModel.setFavorite(id, uid, type).then(result => {
req.ctx(listModel).setFavorite(id, uid, type).then(result => {
res.json(result);
}).catch(next);
}
... ... @@ -477,7 +477,7 @@ const favoriteBrand = (req, res, next) => {
*/
const shopCategory = (req, res, next) => {
listModel.getShopCategory({
req.ctx(listModel).getShopCategory({
shopId: req.query.shop_id,
channel: req.yoho.channel,
gender: req.query.gender || '1,3'
... ... @@ -518,7 +518,7 @@ const getBrandCouponsList = (req, res, next) => {
param.brand_id = brandId;
listModel.brandCouponsList(param).then(result => {
req.ctx(listModel).brandCouponsList(param).then(result => {
res.json(result);
}).catch(next);
} else {
... ...
... ... @@ -200,11 +200,11 @@ const newDetail = {
}
if (req.body.opt === 'ok') {
listModel.setFavorite(req.body.id, uid, 'product').then(result => {
req.ctx(listModel).setFavorite(req.body.id, uid, 'product').then(result => {
return res.json(result);
}).catch(next);
} else {
listModel.setFavoriteCancel(req.body.id, uid, 'product').then(result => {
req.ctx(listModel).setFavoriteCancel(req.body.id, uid, 'product').then(result => {
return res.json(result);
}).catch(next);
}
... ...
... ... @@ -152,11 +152,11 @@ const newDetail = {
}
if (req.body.opt === 'ok') {
listModel.setFavorite(req.body.id, uid, 'product').then(result => {
req.ctx(listModel).setFavorite(req.body.id, uid, 'product').then(result => {
return res.json(result);
}).catch(next);
} else {
listModel.setFavoriteCancel(req.body.id, uid, 'product').then(result => {
req.ctx(listModel).setFavoriteCancel(req.body.id, uid, 'product').then(result => {
return res.json(result);
}).catch(next);
}
... ...
... ... @@ -8,7 +8,6 @@ const utils = '../../../utils';
const crypto = global.yoho.crypto;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const searchModel = require('./search');
const productProcess = require(`${utils}/product-process`);
const stringProcess = require(`${global.utils}/string-process`);
... ... @@ -24,819 +23,830 @@ const yhChannel = {
lifestyle: 4
};
/* 多品牌店铺列表数据信息处理*/
const _processBrandShops = (list) => {
let formatDat = [];
_.forEach(list, item => {
if (item.shop_type === 'yoho_shop') {
formatDat.push({
url: helpers.urlFormat('/product/shop', {
shop_id: item.shop_id
}),
thumb: helpers.image(item.shop_logo, 126, 80),
name: item.shop_name,
shopId: item.shop_id
});
} else if (item.shop_type === 'tbl_brand') {
formatDat.push({
url: helpers.urlFormat('/product/global/list/', {
brand: item.global_brand_id
}),
thumb: helpers.image(item.brand_ico, 126, 80),
name: item.brand_name,
brandId: item.global_brand_id
});
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.ctx = _.get(ctx, 'req.ctx');
}
/* 多品牌店铺列表数据信息处理*/
_processBrandShops(list) {
let formatDat = [];
_.forEach(list, item => {
if (item.shop_type === 'yoho_shop') {
formatDat.push({
url: helpers.urlFormat('/product/shop', {
shop_id: item.shop_id
}),
thumb: helpers.image(item.shop_logo, 126, 80),
name: item.shop_name,
shopId: item.shop_id
});
} else if (item.shop_type === 'tbl_brand') {
formatDat.push({
url: helpers.urlFormat('/product/global/list/', {
brand: item.global_brand_id
}),
thumb: helpers.image(item.brand_ico, 126, 80),
name: item.brand_name,
brandId: item.global_brand_id
});
}
});
if (formatDat.length > 2) {
formatDat.moreShop = true;
}
});
if (formatDat.length > 2) {
formatDat.moreShop = true;
return formatDat;
}
return formatDat;
};
/**
* 销售类目链接拼接 APP
* @param origin
* @param shopId
* @private
*/
const _modifyWapUrl = (origin, shopId) => {
if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) {
return helpers.urlFormat('', {
filter_poolId: origin.categoryId,
shop_id: shopId,
title: origin.categoryName
}, 'search'); //eslint-disable-line
} else {
if (_.has(origin, 'url')) {
return origin.url;
/**
* 销售类目链接拼接 APP
* @param origin
* @param shopId
* @private
*/
_modifyWapUrl(origin, shopId) {
if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) {
return helpers.urlFormat('', {
filter_poolId: origin.categoryId,
shop_id: shopId,
title: origin.categoryName
}, 'search'); //eslint-disable-line
} else {
return '';
if (_.has(origin, 'url')) {
return origin.url;
} else {
return '';
}
}
}
};
/**
* 销售类目链接拼接 APP
* @param origin
* @param shopId
* @private
*/
const _modifyAppUrl = (origin, shopId) => {
if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) {
return helpers.urlFormat('/search/list', {filter_poolId: origin.categoryId}) +
`?openby:yohobuy={"action":"go.poollist","params":{"shop_id":"${shopId}","title":"${origin.categoryName}","productPool":"${origin.categoryId}"}}`; //eslint-disable-line
} else {
if (_.has(origin, 'url')) {
return origin.url;
/**
* 销售类目链接拼接 APP
* @param origin
* @param shopId
* @private
*/
_modifyAppUrl(origin, shopId) {
if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) {
return helpers.urlFormat('/search/list', {filter_poolId: origin.categoryId}) +
`?openby:yohobuy={"action":"go.poollist","params":{"shop_id":"${shopId}","title":"${origin.categoryName}","productPool":"${origin.categoryId}"}}`; //eslint-disable-line
} else {
return '';
if (_.has(origin, 'url')) {
return origin.url;
} else {
return '';
}
}
}
};
/**
* 获取店铺装修的所有资源接口
* @param {int} shopId 店铺id
* @return array
*/
_getShopDecorator(shopId) {
return this.get({
data: {
method: 'app.shopsdecorator.getList',
shop_id: shopId
},
param: {
cache: true,
code: 200
}
}).then((result) => {
return (result && result.data) || {};
});
}
/**
* 获取店铺装修的所有资源接口
* @param {int} shopId 店铺id
* @return array
*/
const _getShopDecorator = (shopId) => {
return api.get('', {
method: 'app.shopsdecorator.getList',
shop_id: shopId
}, {
cache: true,
code: 200
}).then((result) => {
return (result && result.data) || {};
});
};
/**
* 获取店铺信息
* @param {int} shopId 店铺id
* @param {int} uid 用户id 判断用户是否收藏店铺
* @return array
*/
_getShopInfo(shopId, uid) {
let finalParams = {
method: 'app.shops.getIntro',
shop_id: shopId,
};
/**
* 获取店铺信息
* @param {int} shopId 店铺id
* @param {int} uid 用户id 判断用户是否收藏店铺
* @return array
*/
const _getShopInfo = (shopId, uid) => {
let finalParams = {
method: 'app.shops.getIntro',
shop_id: shopId,
};
if (!shopId || !stringProcess.isNumeric(shopId)) {
return Promise.resolve({});
}
if (!shopId || !stringProcess.isNumeric(shopId)) {
return Promise.resolve({});
}
if (uid && uid !== 'undefined') {
Object.assign(finalParams, {
uid: uid
if (uid && uid !== 'undefined') {
Object.assign(finalParams, {
uid: uid
});
}
return this.get({
data: finalParams,
param: {code: 200}
}).then((result) => {
return result && result.data;
});
}
return api.get('', finalParams, {code: 200}).then((result) => {
return result && result.data;
});
};
/**
* 调取店铺简介数据
* @param {int} shopId
*/
getShopIntro(shopId, uid) {
let params = {
method: 'app.shops.getIntro',
shop_id: shopId
};
/**
* 调取店铺简介数据
* @param {int} shopId
*/
const getShopIntro = (shopId, uid) => {
let params = {
method: 'app.shops.getIntro',
shop_id: shopId
};
if (!shopId || !stringProcess.isNumeric(shopId)) {
return Promise.resolve({});
if (!shopId || !stringProcess.isNumeric(shopId)) {
return Promise.resolve({});
}
if (uid && uid !== 'undefined') {
params.uid = uid;
}
return this.get({
data: params,
param: {code: 200}
}).then(result => {
if (result && result.data) {
const imgReg = /<img [^>]*src=['"]([^'"]+)[^>]*>/gi;
result.data.shop_intro = (result.data.shop_intro || '').replace(imgReg, function(match, url) {
return match.replace(url, url.replace('http:', ''));
});
}
return result && result.data;
});
}
if (uid && uid !== 'undefined') {
params.uid = uid;
/**
* 获取店铺下面的所有分类
* @param {int} shopId 店铺id
* @param {string} channel 频道
* @return array
*/
_getShopCategory(shopId, channel) {
return this.get({
data: {
method: 'app.shop.getSortInfo',
yh_channel: yhChannel[channel],
shop_id: shopId
},
param: {code: 200, cache: true}
}).then(result => {
return result && result.data;
});
}
return api.get('', params, {code: 200}).then(result => {
if (result && result.data) {
const imgReg = /<img [^>]*src=['"]([^'"]+)[^>]*>/gi;
/**
* 处理店铺或者品牌 seo 数据
* @param channel
* @param info
* @param qs
* @returns {{}}
* @private
*/
_getBrandShopSeo(channel, info, qs) {
let resData = {},
ctype = {
boys: {fashionType: '男装', brandType: '男生品牌'},
girls: {fashionType: '女装', brandType: '女生品牌'},
kids: {fashionType: '童装', brandType: '潮童品牌'},
lifestyle: {fashionType: '创意生活', brandType: '创意生活品牌'}
};
let params = {
nameEn: '',
name: ''
};
result.data.shop_intro = (result.data.shop_intro || '').replace(imgReg, function(match, url) {
return match.replace(url, url.replace('http:', ''));
if (info) {
Object.assign(params, {
nameEn: _.get(info, 'brand_name_en', ''),
nameCn: _.get(info, 'brand_name_cn', ''),
name: _.get(info, 'brand_name', '')
});
params.name = `${params.nameEn} ${params.nameCn} ${params.name}`;
if (info.shop_name) {
Object.assign(params, {
nameEn: info.shop_name,
name: info.shop_name
});
}
}
return result && result.data;
});
};
/**
* 获取店铺下面的所有分类
* @param {int} shopId 店铺id
* @param {string} channel 频道
* @return array
*/
const _getShopCategory = (shopId, channel) => {
return api.get('', {
method: 'app.shop.getSortInfo',
yh_channel: yhChannel[channel],
shop_id: shopId
}, {code: 200, cache: true}).then(result => {
return result && result.data;
});
};
/**
* 处理店铺或者品牌 seo 数据
* @param channel
* @param info
* @param qs
* @returns {{}}
* @private
*/
const _getBrandShopSeo = (channel, info, qs) => {
let resData = {},
ctype = {
boys: {fashionType: '男装', brandType: '男生品牌'},
girls: {fashionType: '女装', brandType: '女生品牌'},
kids: {fashionType: '童装', brandType: '潮童品牌'},
lifestyle: {fashionType: '创意生活', brandType: '创意生活品牌'}
};
let params = {
nameEn: '',
name: ''
};
if (qs && qs.gender) {
if (qs.gender === '1,3') {
channel = 'boys';
} else if (qs.gender === '2,3') {
channel = 'girls';
}
if (info) {
Object.assign(params, {
nameEn: _.get(info, 'brand_name_en', ''),
nameCn: _.get(info, 'brand_name_cn', ''),
name: _.get(info, 'brand_name', '')
});
params.name = `${params.nameEn} ${params.nameCn} ${params.name}`;
if (info.shop_name) {
Object.assign(params, {
nameEn: info.shop_name,
name: info.shop_name
Object.assign(params, ctype[channel] || ctype.boys);
Object.assign(resData, {
title: `${params.nameEn} | ${params.name} ${params.brandType}`,
keywords: `${params.nameEn}, ${params.name} ${params.fashionType},${params.nameEn} ${params.brandType}`,
description: `${params.nameEn}正品网购。${params.name}官方授权!`
});
} else {
Object.assign(resData, {
title: `${params.nameEn} | ${params.name}官网`,
keywords: `${params.nameEn}, ${params.name}官网`,
description: `${params.nameEn}正品网购。${params.name}官方授权!`
});
}
resData.title += resData.title ? ' | YOHO!有货 100%正品保证' : '';
resData.description += resData.description ? ' YOHO! 有货中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。' : ''; // eslint-disable-line
return resData;
}
if (qs && qs.gender) {
if (qs.gender === '1,3') {
channel = 'boys';
} else if (qs.gender === '2,3') {
channel = 'girls';
/**
*
* 调用接口获取品牌或者店铺的收藏状态
* @private
*/
getBrandFavStatus(params) {
if (params.uid === 'undefined') {
params.uid = 0;
}
Object.assign(params, ctype[channel] || ctype.boys);
Object.assign(resData, {
title: `${params.nameEn} | ${params.name} ${params.brandType}`,
keywords: `${params.nameEn}, ${params.name} ${params.fashionType},${params.nameEn} ${params.brandType}`,
description: `${params.nameEn}正品网购。${params.name}官方授权!`
});
} else {
Object.assign(resData, {
title: `${params.nameEn} | ${params.name}官网`,
keywords: `${params.nameEn}, ${params.name}官网`,
description: `${params.nameEn}正品网购。${params.name}官方授权!`
return this.get({
data: {
method: 'app.favorite.isFavorite',
uid: params.uid || 0,
id: params.id,
type: params.type
}
}).then(result => {
return result;
});
}
resData.title += resData.title ? ' | YOHO!有货 100%正品保证' : '';
resData.description += resData.description ? ' YOHO! 有货中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。' : ''; // eslint-disable-line
return resData;
};
/**
*
* 调用接口获取品牌或者店铺的收藏状态
* @private
*/
const getBrandFavStatus = (params) => {
if (params.uid === 'undefined') {
params.uid = 0;
/**
* 获取店铺下面的所有品牌
* @param {int} shopId 店铺id
*/
getShopBrands(shopId) {
return this.get({
data: {
method: 'app.shops.getShopsBrands',
shop_id: shopId
},
param: {code: 200, cache: true}
}).then((result) => {
if (result[0]) {
return result[0].brand_id;
}
});
}
return api.get('', {
method: 'app.favorite.isFavorite',
uid: params.uid || 0,
id: params.id,
type: params.type
}).then(result => {
return result;
});
};
/**
* 获取店铺下面的所有品牌
* @param {int} shopId 店铺id
*/
const getShopBrands = (shopId) => {
return api.get('', {
method: 'app.shops.getShopsBrands',
shop_id: shopId
}, {code: 200, cache: true}).then((result) => {
if (result[0]) {
return result[0].brand_id;
}
});
};
/**
* 组织店铺页面数据
* @param {array} data 接口返回的店铺页所需数据
* @param {int} shopId 店铺id
* @param {int} isApp app版本
* @return {shopId: int, appVersion: int}
*/
_formShopData(data, shopId, isApp) {
let formatData = {
shopId: shopId,
appVersion: isApp
},
single = false;
let brandId;
// 组织店铺装修
if (data.decorator) {
_.forEach(data.decorator.list, floor => {
let resData = JSON.parse(floor.resource_data);
if (floor.resource_name) {
floor[_.camelCase(floor.resource_name)] = true;
}
// 店铺banner
if (floor.shopTopBannerApp) {
formatData.branerImg = resData[0].shopSrc;
}
/**
* 组织店铺页面数据
* @param {array} data 接口返回的店铺页所需数据
* @param {int} shopId 店铺id
* @param {int} isApp app版本
* @return {shopId: int, appVersion: int}
*/
const _formShopData = (data, shopId, isApp) => {
let formatData = {
shopId: shopId,
appVersion: isApp
},
single = false;
let brandId;
// 组织店铺装修
if (data.decorator) {
_.forEach(data.decorator.list, floor => {
let resData = JSON.parse(floor.resource_data);
if (floor.resource_name) {
floor[_.camelCase(floor.resource_name)] = true;
}
// 资源位小图 接口返回两组,取每组第一张
if (floor.oneRowTwoColImagesApp) {
// 店铺banner
if (floor.shopTopBannerApp) {
formatData.branerImg = resData[0].shopSrc;
}
let spring = [];
// 资源位小图 接口返回两组,取每组第一张
if (floor.oneRowTwoColImagesApp) {
_.forEach(resData, (item) => {
if (item.data) {
spring.push({
url: isApp ? this._modifyAppUrl(item.data[0], shopId) :
this._modifyWapUrl(item.data[0], shopId),
springType: helpers.image(item.data[0].src)
});
}
});
let spring = [];
formatData.spring = spring;
}
_.forEach(resData, (item) => {
if (item.data) {
spring.push({
url: isApp ? _modifyAppUrl(item.data[0], shopId) :
_modifyWapUrl(item.data[0], shopId),
springType: helpers.image(item.data[0].src)
// 店铺品牌一览
if (floor.brandBrowse) {
let brandNumber = resData.length;
let brand = {
list: []
};
brandId = '';
// 少于2个不展示 单品店:单品店根据品牌id查询
if (brandNumber < 2) {
brandId = formatData.brand = resData[0].id;
single = true;
} else {
_.forEach(resData, (item) => {
if (item.brandDomain) {
brand.list.push({
url: helpers.urlFormat('/', {brand: item.id, shop_id: shopId, title: item.brandName}, 'list') + (isApp ? `?openby:yohobuy={"action":"go.brand","params":{"shop_id":${shopId},"brand_id":${item.id}}}` : ''), //eslint-disable-line
img: helpers.image(item.brandIco, 640, 400),
brandName: item.brandName
});
brandId += item.id + ',';
}
});
}
});
formatData.spring = spring;
}
formatData.brandList = brand;
// 店铺品牌一览
if (floor.brandBrowse) {
let brandNumber = resData.length;
let brand = {
list: []
};
// 大于5个返回更多品牌链接
if (brandNumber > 5) {
formatData.brandList.url = helpers.urlFormat('/product/index/allBrand', {
shop_id: shopId
});
}
}
}
brandId = '';
// 资源位大图幻灯
if (floor.largeSlideImgApp) {
let bannerTop = {
data: []
};
// 少于2个不展示 单品店:单品店根据品牌id查询
if (brandNumber < 2) {
brandId = formatData.brand = resData[0].id;
single = true;
} else {
_.forEach(resData, (item) => {
if (item.brandDomain) {
brand.list.push({
url: helpers.urlFormat('/', {brand: item.id, shop_id: shopId, title: item.brandName}, 'list') + (isApp ? `?openby:yohobuy={"action":"go.brand","params":{"shop_id":${shopId},"brand_id":${item.id}}}` : ''), //eslint-disable-line
img: helpers.image(item.brandIco, 640, 400),
brandName: item.brandName
if (item.data[0]) {
bannerTop.data.push({
url: isApp ? this._modifyAppUrl(item.data[0], shopId) :
this._modifyWapUrl(item.data[0], shopId),
src: item.data[0].src
});
brandId += item.id + ',';
}
});
formatData.brandList = brand;
// 大于5个返回更多品牌链接
if (brandNumber > 5) {
formatData.brandList.url = helpers.urlFormat('/product/index/allBrand', {
shop_id: shopId
});
}
formatData.bannerTop = bannerTop;
}
}
// 资源位大图幻灯
if (floor.largeSlideImgApp) {
let bannerTop = {
data: []
};
_.forEach(resData, (item) => {
if (item.data[0]) {
bannerTop.data.push({
url: isApp ? _modifyAppUrl(item.data[0], shopId) :
_modifyWapUrl(item.data[0], shopId),
src: item.data[0].src
// 热门品类
if (floor.recommendApp) {
let hotCategory = {
data: {
title: {
title: '热门品类'
},
list: []
}
};
_.forEach(resData, cate => {
hotCategory.data.list.push({
url: isApp ? this._modifyAppUrl(cate, shopId) :
this._modifyWapUrl(cate, shopId),
src: helpers.image(cate.src),
name: cate.name
});
}
});
});
formatData.bannerTop = bannerTop;
}
formatData.hotCategory = hotCategory;
}
// 热门品类
if (floor.recommendApp) {
let hotCategory = {
data: {
title: {
title: '热门品类'
},
list: []
}
};
// 人气单品
if (floor.hotProductsApp) {
let productSkn = '';
_.forEach(resData, cate => {
hotCategory.data.list.push({
url: isApp ? _modifyAppUrl(cate, shopId) :
_modifyWapUrl(cate, shopId),
src: helpers.image(cate.src),
name: cate.name
_.forEach(resData, value => {
productSkn += value.productSkn + ',';
});
});
formatData.hotCategory = hotCategory;
}
formatData.hotListproductSkn = productSkn;
}
});
}
// 人气单品
if (floor.hotProductsApp) {
let productSkn = '';
// 店铺基本信息
if (data.shopInfo) {
let allGoodsParam = {
title: '全部商品'
};
_.forEach(resData, value => {
productSkn += value.productSkn + ',';
});
let moreUrl = helpers.urlFormat('', {
shop_id: shopId,
order: 's_n_d',
title: '人气单品'
}, 'search'); // 人气单品的链接
formatData.hotListproductSkn = productSkn;
if (isApp) {
moreUrl = 'openby:yohobuy={"action":"go.list","params":{"shop_id":"' + shopId + '","title":"人气单品"}}';
}
});
}
// 店铺基本信息
if (data.shopInfo) {
let allGoodsParam = {
title: '全部商品'
};
let moreUrl = helpers.urlFormat('', {
shop_id: shopId,
order: 's_n_d',
title: '人气单品'
}, 'search'); // 人气单品的链接
if (isApp) {
moreUrl = 'openby:yohobuy={"action":"go.list","params":{"shop_id":"' + shopId + '","title":"人气单品"}}';
}
formatData = _.assign({
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', '') : '',
seoTitle: _.get(data, 'shopInfo.shop_name', ''),
collect: _.get(data, 'shopInfo.is_favorite', '') === 'Y',
url: helpers.urlFormat('', {
shop_id: shopId
}, 'search'), // 搜索链接
more_url: moreUrl
}, formatData);
if (single) { // 单品点
allGoodsParam.brand = brandId;
} else { // 店铺id
formatData.shopId = shopId;
allGoodsParam.shop_id = shopId;
}
if (!isApp) {
formatData = _.assign({
allGoods: helpers.urlFormat('', allGoodsParam, 'search'),
shopIntroHref: helpers.urlFormat('/product/index/intro', {
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', '') : '',
seoTitle: _.get(data, 'shopInfo.shop_name', ''),
collect: _.get(data, 'shopInfo.is_favorite', '') === 'Y',
url: helpers.urlFormat('', {
shop_id: shopId
}) // 店铺简介页地址
}, 'search'), // 搜索链接
more_url: moreUrl
}, formatData);
} else {
formatData = _.assign({
allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":${shopId}}}`,//eslint-disable-line
shopIntroHref: helpers.urlFormat('/product/index/intro', {
shop_id: shopId,
app_version: isApp
}),
more_url: formatData.more_url + `?openby:yohobuy{"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}`//eslint-disable-line
}, formatData);
}
}
// 店铺下面的所有分类
if (data.shopCategory) {
let total = data.shopCategory.length;
let shopCategory = {
list: []
};
if (single) { // 单品点
allGoodsParam.brand = brandId;
} else { // 店铺id
formatData.shopId = shopId;
allGoodsParam.shop_id = shopId;
}
if (total > 6) {
shopCategory.url = helpers.urlFormat('/product/index/category', {
shop_id: shopId
});
} else {
_.forEach(data.shopCategory, item => {
shopCategory.list.push({
url: helpers.urlFormat('', {
if (!isApp) {
formatData = _.assign({
allGoods: helpers.urlFormat('', allGoodsParam, 'search'),
shopIntroHref: helpers.urlFormat('/product/index/intro', {
shop_id: shopId
}) // 店铺简介页地址
}, formatData);
} else {
formatData = _.assign({
allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":${shopId}}}`,//eslint-disable-line
shopIntroHref: helpers.urlFormat('/product/index/intro', {
shop_id: shopId,
sort: (item.relation_parameter && item.relation_parameter.sort) || ''
}, 'search'),
categoryId: item.category_id,
name: item.category_name
});
});
app_version: isApp
}),
more_url: formatData.more_url + `?openby:yohobuy{"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}`//eslint-disable-line
}, formatData);
}
}
formatData.shopCategory = shopCategory;
}
if (single) {
formatData.favId = shopId;
formatData.shopId = '';
}
return formatData;
};
// 店铺下面的所有分类
if (data.shopCategory) {
let total = data.shopCategory.length;
let shopCategory = {
list: []
};
/**
* 使用基础模板的店铺首页
* @param params
* @param shopInfo
* @returns {*|Promise.<TResult>}
*/
const getBaseShopData = (params, shopInfo) => {
/* tar add 161109 seo-info */
let seoResult = _getBrandShopSeo(params.channel, shopInfo, params);
let finalResult = {
cartUrl: helpers.urlFormat('/cart/index/index'),
seoResult: seoResult
};
let shopId = params.shop_id || shopInfo.shops_id;
return api.all([
_getShopDecorator(shopId),
getShopBrands(shopId)
]).then(result => {
if (result[0] && _.has(result[0], 'list')) {
_.forEach(result[0].list, item => {
if (item.resource_name === 'shopTopBanner_base') {
let banner = JSON.parse(item.resource_data);
finalResult = _.assign(finalResult, {
baseShopHome: {
appVersion: _.get(params, 'app_version', ''),
isBaseShop: true,
id: shopId,
intro: shopInfo.shop_intro,
collected: shopInfo.is_favorite === 'Y',
banner: _.get(banner[0], 'shopSrc', '')
}
if (total > 6) {
shopCategory.url = helpers.urlFormat('/product/index/category', {
shop_id: shopId
});
} else {
_.forEach(data.shopCategory, item => {
shopCategory.list.push({
url: helpers.urlFormat('', {
shop_id: shopId,
sort: (item.relation_parameter && item.relation_parameter.sort) || ''
}, 'search'),
categoryId: item.category_id,
name: item.category_name
});
}
});
}
});
}
if (params.multBrandShopType === '2') {
// 转义店铺
finalResult.shop_id = shopId;
} else {
finalResult.brand = result[1];
formatData.shopCategory = shopCategory;
}
return finalResult;
});
};
/**
* 使用经典模板的店铺首页
* @param {object} req
* @param {int} shopId 店铺id
* @param {int} uid 用户id
* @param {string} isApp app版本
*/
const getShopData = (req, shopId, uid, isApp) => {
let shopData = {};
let channel = req.yoho.channel;
let brandData = [];
return _getShopInfo(shopId, uid).then(shopInfoResult => {
if (single) {
formatData.favId = shopId;
formatData.shopId = '';
}
return formatData;
}
let seoResult = _getBrandShopSeo(channel, shopInfoResult, req.query);
/**
* 使用基础模板的店铺首页
* @param params
* @param shopInfo
* @returns {*|Promise.<TResult>}
*/
getBaseShopData(params, shopInfo) {
/* tar add 161109 seo-info */
let seoResult = _getBrandShopSeo(params.channel, shopInfo, params);
let finalResult = {
cartUrl: helpers.urlFormat('/cart/index/index'),
seoResult: seoResult
};
/* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
if (shopInfoResult && shopInfoResult.shop_template_type &&
parseInt(shopInfoResult.shop_template_type, 10) === 1) {
return {
goBrand: shopInfoResult
};
}
let shopId = params.shop_id || shopInfo.shops_id;
return this.all([
this._getShopDecorator(shopId),
this.getShopBrands(shopId)
]).then(result => {
if (result[0] && _.has(result[0], 'list')) {
_.forEach(result[0].list, item => {
if (item.resource_name === 'shopTopBanner_base') {
let banner = JSON.parse(item.resource_data);
finalResult = _.assign(finalResult, {
baseShopHome: {
appVersion: _.get(params, 'app_version', ''),
isBaseShop: true,
id: shopId,
intro: shopInfo.shop_intro,
collected: shopInfo.is_favorite === 'Y',
banner: _.get(banner[0], 'shopSrc', '')
}
});
}
});
}
return _getShopDecorator(shopId).then(shopDeco => {
return shopDeco;
}).then(shopDeco => {
let brandBrowseData;
// 取店铺下的brand, id
_.forEach(shopDeco.list, floor => {
if (floor.resource_name === 'brandBrowse') {
brandBrowseData = JSON.parse(floor.resource_data);
_.forEach(brandBrowseData, brandBrowse => {
brandData.push(brandBrowse.id);
});
}
});
if (params.multBrandShopType === '2') {
// 转义店铺
finalResult.shop_id = shopId;
} else {
finalResult.brand = result[1];
}
return finalResult;
});
}
return Promise.all([
searchModel.getFilterSearchData({
shop_id: shopId,
type: 'default', // 默认
brand: brandData.join(','),
order: '0',
channel: channel
})
]).then((result) => {
shopData = {
decorator: shopDeco, // 店铺装修资源数据
shopInfo: shopInfoResult // 店铺信息
/**
* 使用经典模板的店铺首页
* @param {object} req
* @param {int} shopId 店铺id
* @param {int} uid 用户id
* @param {string} isApp app版本
*/
getShopData(req, shopId, uid, isApp) {
let shopData = {};
let channel = req.yoho.channel;
let brandData = [];
return this._getShopInfo(shopId, uid).then(shopInfoResult => {
let seoResult = this._getBrandShopSeo(channel, shopInfoResult, req.query);
/* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
if (shopInfoResult && shopInfoResult.shop_template_type &&
parseInt(shopInfoResult.shop_template_type, 10) === 1) {
return {
goBrand: shopInfoResult
};
}
/* 获取一次分类和商品数据 */
let shopFilterSearchData = {
filter: [],
goods: []
};
return this._getShopDecorator(shopId).then(shopDeco => {
return shopDeco;
}).then(shopDeco => {
let brandBrowseData;
// 取店铺下的brand, id
_.forEach(shopDeco.list, floor => {
if (floor.resource_name === 'brandBrowse') {
brandBrowseData = JSON.parse(floor.resource_data);
_.forEach(brandBrowseData, brandBrowse => {
brandData.push(brandBrowse.id);
});
}
});
if (result[0]) {
shopFilterSearchData.filter = productProcess.processFilter(result[0].filter || []);
shopFilterSearchData.goods =
productProcess.processProductList(result[0].product_list || [], {isApp: isApp});
}
return Promise.all([
this.ctx(searchModel).getFilterSearchData({
shop_id: shopId,
type: 'default', // 默认
brand: brandData.join(','),
order: '0',
channel: channel
})
]).then((result) => {
shopData = {
decorator: shopDeco, // 店铺装修资源数据
shopInfo: shopInfoResult // 店铺信息
};
/* 获取一次分类和商品数据 */
let shopFilterSearchData = {
filter: [],
goods: []
};
if (result[0]) {
shopFilterSearchData.filter = productProcess.processFilter(result[0].filter || []);
shopFilterSearchData.goods =
productProcess.processProductList(result[0].product_list || [], {isApp: isApp});
}
// 店铺分类
return _getShopCategory(shopId, channel).then(shopCategory => {
shopData = _.assign({
shopCategory: shopCategory
}, shopData);
// noinspection JSCheckFunctionSignatures
return Object.assign(
_formShopData(shopData, shopId, isApp),
shopFilterSearchData,
{
shopId: shopId,
uid: uid,
coverChannel: channel,
seoResult: seoResult
}
);
// 店铺分类
return this._getShopCategory(shopId, channel).then(shopCategory => {
shopData = _.assign({
shopCategory: shopCategory
}, shopData);
// noinspection JSCheckFunctionSignatures
return Object.assign(
this._formShopData(shopData, shopId, isApp),
shopFilterSearchData,
{
shopId: shopId,
uid: uid,
coverChannel: channel,
seoResult: seoResult
}
);
});
});
});
});
});
}
};
/**
* 异步判断店铺是否收藏
* @param req
* @param shopId
* @param uid
* @returns {Promise.<TResult>|*}
*/
getShopFav(req, shopId, uid) {
return this._getShopInfo(shopId, uid).then(shopInfoResult => {
return shopInfoResult;
});
}
/**
* 异步判断店铺是否收藏
* @param req
* @param shopId
* @param uid
* @returns {Promise.<TResult>|*}
*/
const getShopFav = (req, shopId, uid) => {
return _getShopInfo(shopId, uid).then(shopInfoResult => {
return shopInfoResult;
});
};
/**
* 根据brandId 获取相关店铺列表
* @param brandId
* @param req
* @return array
*/
getBrandShops(domain, req) {
return this.get({
data: {
method: 'app.search.li',
query: domain
},
param: {
code: 200,
cache: true
}
}).then(result => {
if (result.data.shopList && _.isArray(result.data.shopList)) {
let seoResult = this._getBrandShopSeo(req.channel, result.data[0], req.query);
/**
* 根据brandId 获取相关店铺列表
* @param brandId
* @param req
* @return array
*/
const getBrandShops = (domain, req) => {
return api.get('', {
method: 'app.search.li',
query: domain
}, {
code: 200,
cache: true
}).then(result => {
if (result.data.shopList && _.isArray(result.data.shopList)) {
let seoResult = _getBrandShopSeo(req.channel, result.data[0], req.query);
return Object.assign(_processBrandShops(result.data.shopList), {seoResult: seoResult});
} else {
return [];
}
});
};
return Object.assign(this._processBrandShops(result.data.shopList), {seoResult: seoResult});
} else {
return [];
}
});
}
/**
* 收藏
* @param {int} id ID
* @param {int} uid 用户ID
* @param type
* @return array
*/
const setFavorite = (id, uid, type) => {
return api.post('', {
method: 'app.favorite.add',
fav_id: id,
id: id,
uid: uid,
type: type
});
};
/**
* 收藏
* @param {int} id ID
* @param {int} uid 用户ID
* @param type
* @return array
*/
setFavorite(id, uid, type) {
return this.post({
data: {
method: 'app.favorite.add',
fav_id: id,
id: id,
uid: uid,
type: type
}
});
}
/**
* 取消收藏
*
* @param {int} id 品牌ID
* @param {int} uid 用户ID
* @param type
* @return array
*/
const setFavoriteCancel = (id, uid, type) => {
return api.post('', {
method: 'app.favorite.cancel',
fav_id: id,
id: id,
uid: uid,
type: type
});
};
/**
* 取消收藏
*
* @param {int} id 品牌ID
* @param {int} uid 用户ID
* @param type
* @return array
*/
setFavoriteCancel(id, uid, type) {
return this.post({
data: {
method: 'app.favorite.cancel',
fav_id: id,
id: id,
uid: uid,
type: type
}
});
}
/**
* 处理店铺品类
* @param params
*/
const getShopCategory = (params) => {
let finalResult = {
class: [],
category: []
};
return _getShopCategory(params.shopId, params.channel).then(result => {
let resultCopy = _.cloneDeep(result);
_.forEach(resultCopy, value => {
finalResult.class.push({
name: value.category_name
});
/**
* 处理店铺品类
* @param params
*/
getShopCategory(params) {
let finalResult = {
class: [],
category: []
};
_.forEach(value.sub, (subValue, subKey) => {
value.sub[subKey].url = helpers.urlFormat('/product/search/list', {
shop_id: params.shopId,
sort: _.get(subValue, 'relation_parameter.sort', ''),
title: subValue.category_name,
query: subValue.category_name
return this._getShopCategory(params.shopId, params.channel).then(result => {
let resultCopy = _.cloneDeep(result);
_.forEach(resultCopy, value => {
finalResult.class.push({
name: value.category_name
});
});
let subCategory = [
{
category_name: '全部' + value.category_name,
url: helpers.urlFormat('/product/search/list', {
_.forEach(value.sub, (subValue, subKey) => {
value.sub[subKey].url = helpers.urlFormat('/product/search/list', {
shop_id: params.shopId,
sort: _.get(value, 'relation_parameter.sort', ''),
title: '全部' + value.category_name,
query: value.category_name
})
}
];
sort: _.get(subValue, 'relation_parameter.sort', ''),
title: subValue.category_name,
query: subValue.category_name
});
});
subCategory = subCategory.concat(value.sub);
let subCategory = [
{
category_name: '全部' + value.category_name,
url: helpers.urlFormat('/product/search/list', {
shop_id: params.shopId,
sort: _.get(value, 'relation_parameter.sort', ''),
title: '全部' + value.category_name,
query: value.category_name
})
}
];
finalResult.category.push({
subcategory: subCategory
});
});
subCategory = subCategory.concat(value.sub);
finalResult.allProduct = helpers.urlFormat('/product/search/list', {
shop_id: params.shopId
});
finalResult.category.push({
subcategory: subCategory
});
});
return finalResult;
});
};
finalResult.allProduct = helpers.urlFormat('/product/search/list', {
shop_id: params.shopId
});
/**
* 获取品牌优惠券列表
* @param {[int]} brand_id 品牌id
* @param {[int]} uid 当前用户id,空则不传
* @return {[array]}
*/
const brandCouponsList = (params) => {
if (!params.brand_id || params.brand_id === '' || params.brand_id === 'undefined') {
return Promise.resolve([]);
return finalResult;
});
}
return api.get('', Object.assign({
method: 'app.brand.getBrandIntro'
}, params)).then(result => {
let shopCoupons = [];
let couPonstatus;
if (result && result.data && result.data.coupons) {
_.forEach(result.data.coupons, value => {
couPonstatus = parseInt(value.status, 10);
if (couPonstatus === 1 || couPonstatus === 3) {
shopCoupons.push({
validity: value.couponValidity,
id: crypto.encryption('', value.coupon_id + ''),
name: value.coupon_name,
pic: value.coupon_pic,
money: parseInt(value.money, 10),
status: couPonstatus === 1
});
}
});
/**
* 获取品牌优惠券列表
* @param {[int]} brand_id 品牌id
* @param {[int]} uid 当前用户id,空则不传
* @return {[array]}
*/
brandCouponsList(params) {
if (!params.brand_id || params.brand_id === '' || params.brand_id === 'undefined') {
return Promise.resolve([]);
}
return {
couponsOne: shopCoupons.length <= 1,
coupons: shopCoupons
};
});
};
return this.get({
data: Object.assign({
method: 'app.brand.getBrandIntro'
}, params)
}).then(result => {
let shopCoupons = [];
let couPonstatus;
if (result && result.data && result.data.coupons) {
_.forEach(result.data.coupons, value => {
couPonstatus = parseInt(value.status, 10);
if (couPonstatus === 1 || couPonstatus === 3) {
shopCoupons.push({
validity: value.couponValidity,
id: crypto.encryption('', value.coupon_id + ''),
name: value.coupon_name,
pic: value.coupon_pic,
money: parseInt(value.money, 10),
status: couPonstatus === 1
});
}
});
}
module.exports = {
getBaseShopData,
getShopData,
getBrandShops,
setFavorite,
setFavoriteCancel,
getShopIntro,
getShopBrands,
getShopCategory,
brandCouponsList,
getShopFav,
getBrandFavStatus,
getShopDecorator: _getShopDecorator,
getShopCategoryApi: _getShopCategory,
formShopData: _formShopData,
getBrandShopSeo: _getBrandShopSeo
return {
couponsOne: shopCoupons.length <= 1,
coupons: shopCoupons
};
});
}
};
... ...