Authored by 郭成尧

'search-data-and-filter-data-one-api'

... ... @@ -4,6 +4,7 @@
* @date: 2016/07/21
*/
'use strict';
const utils = '../../../utils';
const logger = global.yoho.logger;
const crypto = global.yoho.crypto;
const camelCase = global.yoho.camelCase;
... ... @@ -11,6 +12,7 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const searchModel = require('./search');
const productProcess = require(`${utils}/product-process`);
/**
* 频道
... ... @@ -527,12 +529,7 @@ const getShopData = (req, shopId, uid, isApp) => {
return Promise.all([
_getShopDecorator(shopId),
searchModel.getFilterData({
shop_id: shopId,
gender: req.query.gender || '1,3',
channel: channel
}),
searchModel.getSearchData({
searchModel.getFilterSearchData({
shop_id: shopId,
gender: req.query.gender || '1,3',
channel: channel
... ... @@ -544,8 +541,19 @@ const getShopData = (req, shopId, uid, isApp) => {
shopInfo: shopInfoResult // 店铺信息
};
/* 获取一次分类和商品数据 */
let shopFilterSearchData = {
filter: [],
goods: []
};
if (result[1]) {
shopFilterSearchData.filter = productProcess.processFilter(result[1].filter || []);
shopFilterSearchData.goods = productProcess.processProductList(result[1].product_list || []);
}
/* 店鋪優惠券 */
let shopCoupons = result[3] || [];
let shopCoupons = result[2] || [];
// 店铺分类
return _getShopCategory(shopId, channel).then((shopCategory) => {
... ... @@ -554,14 +562,16 @@ const getShopData = (req, shopId, uid, isApp) => {
}, shopData);
// noinspection JSCheckFunctionSignatures
return Object.assign(_formShopData(shopData, shopId, isApp), {
filter: result[1],
goods: result[2],
shopId: shopId,
coverChannel: channel,
shopCoupons: shopCoupons,
shopCouponsOne: shopCoupons.length === 1
});
return Object.assign(
_formShopData(shopData, shopId, isApp),
shopFilterSearchData,
{
shopId: shopId,
coverChannel: channel,
shopCoupons: shopCoupons,
shopCouponsOne: shopCoupons.length === 1
}
);
});
});
... ... @@ -573,10 +583,9 @@ const getShopData = (req, shopId, uid, isApp) => {
* @param req
* @param shopId
* @param uid
* @param isApp
* @returns {Promise.<TResult>|*}
*/
const getShopFav = (req, shopId, uid, isApp) => {
const getShopFav = (req, shopId, uid) => {
return _getShopInfo(shopId, uid).then(shopInfoResult => {
return shopInfoResult;
});
... ...
... ... @@ -144,6 +144,22 @@ const getFilterData = (params) => {
};
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
*/
const getFilterSearchData = (params) => {
return _searchGoods(params).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('get filter data api return code is not 200');
return [];
}
});
};
/**
* 获取所有的品类名称
**/
const getClassNames = () => {
... ... @@ -235,6 +251,7 @@ const searchKeyActivity = (params) => {
module.exports = {
getSearchData,
getFilterData,
getFilterSearchData,
getAllBrandNames,
getClassNames,
getSearchIndex,
... ...