Authored by 王水玲

品牌

... ... @@ -18,6 +18,7 @@ const list = (req, res) => {
let query = req.query.query;
let isQueryFirstClass = false; // 标识用户搜的是不是一级品类
let isQuerySecondClass = false; // 标识用户搜的是不是二级品类
let domain = null;
params = _.assign({
isSearch: true,
... ... @@ -26,9 +27,19 @@ const list = (req, res) => {
// 品类 品牌
if (query) {
domain = searchModel.getAllBrandNames(query);
// 跳转到品牌商品列表页
//if (domain !== null && !params.shop_id) {
// $url = Helpers::url('', array(
// 'from' => 'search',
// 'query' => $query
//), $domain);
// $this->go($url);
//}
} else {
params.title = '';
params.query = '';
}
// 搜索是一级品类
... ...
... ... @@ -40,9 +40,6 @@ const channelType = {
* @return {[array]}
*/
const _searchSales = (params) => {
console.log(params);
let method = 'app.search.li';
// 排除基本筛选项默认值为0的对象
... ... @@ -66,8 +63,6 @@ const _searchSales = (params) => {
params.order = typeCont[params.type][params.order];
}
console.log(params);
return api.get('', Object.assign({
method: method
}, params), {
... ... @@ -76,6 +71,29 @@ const _searchSales = (params) => {
};
/**
* 品牌名称处理
* @param {[object]} list
* @return {[object]}
*/
const _processBrandNames = (list) => {
const formatData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, function(item) {
_.forEach(item, function(obj) {
formatData.push({
brandDomain: obj.brandDomain,
brandName: obj.brandName
});
});
});
return formatData;
};
/**
* 获取商品数据
*/
const getSearchData = (params, uid) => {
... ... @@ -105,7 +123,44 @@ const getFilterData = (params) => {
});
};
/**
* 获取所有的品牌名称
**/
const getAllBrandNames = (query) => {
return api.get('', {
method: 'app.brand.brandlist'
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
let domain = null;
let brandNames = _processBrandNames(result.data.brands);
_.forEach(brandNames, function(obj) {
// 精确查品牌域名
if (query === obj.brandDomain) {
domain = query;
}
// 精确查品牌名称
if (query === obj.brandName) {
domain = query;
}
// 模糊查品牌域名
//if ()
});
return domain;
} else {
logger.error('断码区分类接口返回 code 不是 200');
return {};
}
});
};
module.exports = {
getSearchData,
getFilterData
getFilterData,
getAllBrandNames
};
... ...