Authored by 郭成尧

处理筛选链接

/*
* @Author: Targaryen
* @Date: 2016-05-25 18:03:34
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-25 18:13:49
*/
* @Author: Targaryen
* @Date: 2016-05-25 18:03:34
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-26 11:10:37
*/
'use strict';
const library = '../../../library';
... ... @@ -19,8 +19,7 @@ const _ = require('lodash');
* @return {[type]} [description]
*/
exports.getSaleGoodsList = (params) => {
return api.get('', sign.apiSign({
let tempParams = {
method: 'app.search.sales',
p_d: _.isEmpty(params.p_d) ? null : params.p_d,
limit: _.isEmpty(params.limit) ? null : params.limit,
... ... @@ -38,7 +37,17 @@ exports.getSaleGoodsList = (params) => {
price: _.isEmpty(params.price) ? null : params.price,
productSize: '384x511',
yh_channel: 1
}));
};
let finalParams = {};
_.forEach(tempParams, function(value, key) {
if (!_.isEmpty(value)) {
finalParams[key] = value;
}
});
return api.get('', sign.apiSign(finalParams));
};
/**
... ...
/*
* @Author: Targaryen
* @Date: 2016-05-25 18:16:59
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-25 18:21:15
*/
* @Author: Targaryen
* @Date: 2016-05-25 18:16:59
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-26 11:11:07
*/
'use strict';
const _ = require('lodash');
/**
* 处理用于筛选的 URL
* @param {[type]} originParam [description]
* @param {[type]} newParam [description]
* @return {[type]} [description]
*/
const handleFilterUrl = (originParam, newParam) => {
let dest = '';
let tempOriginParam = {};
// 创建 originParam、newParam 键的数组
let originParamArray = _.keys(originParam);
let newParamArray = _.keys(newParam);
// 判断参数是否已经存在
let isExist = !_.isEmpty(_.find(originParamArray, function(o) {
return o === newParamArray[0];
}));
if (isExist) {
tempOriginParam = Object.assign(tempOriginParam, originParam);
_.forEach(newParam, function(value, key) {
tempOriginParam[key] = value;
});
} else {
tempOriginParam = Object.assign(tempOriginParam, originParam, newParam);
}
_.forEach(tempOriginParam, function(value, key) {
dest = dest + key + '=' + value + '&';
});
return _.trim(dest, '&');
};
/**
* 处理商品列表数据
* @param {[type]} origin [description]
* @return {[type]} [description]
... ... @@ -16,7 +52,6 @@ const _ = require('lodash');
exports.handleSaleGoodsListData = (origin) => {
var dest = [];
if (!_.isEmpty(origin)) {
_.forEach(origin, function(value) {
... ... @@ -29,7 +64,7 @@ exports.handleSaleGoodsListData = (origin) => {
oneGoods.goodsList = value.goods_list;
oneGoods.name = value.product_name;
oneGoods.brand = {};
oneGoods.brand.url = value.brand_domain + '.SUB_DOMAIN'; // 待处理
oneGoods.brand.url = value.brand_domain + '.yohobuy.com'; // 待处理
oneGoods.brand.name = value.brand_name;
oneGoods.marketPrice = value.market_price;
... ... @@ -45,7 +80,7 @@ exports.handleSaleGoodsListData = (origin) => {
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.handleSaleFilterData = (origin) => {
exports.handleSaleFilterData = (origin, params) => {
var dest = {};
dest.brand = {};
... ... @@ -61,7 +96,7 @@ exports.handleSaleFilterData = (origin) => {
let brand = {};
brand.checked = false;
brand.href = 'CURRENT_URL/brand=' + value.brand_domain; // 待处理
brand.href = handleFilterUrl(params, { brand: value.id });
brand.name = value.brand_name;
dest.brand.default.push(brand);
... ... @@ -73,7 +108,7 @@ exports.handleSaleFilterData = (origin) => {
_.forEach(origin.priceRange, function(value, key) {
let price = {
checked: false,
href: 'CURRENT_URL/price=' + key, // 待处理
href: handleFilterUrl(params, { price: key }),
name: value
};
... ... @@ -89,9 +124,9 @@ exports.handleSaleFilterData = (origin) => {
}
dest.channel[0].name = '男生';
dest.channel[0].href = 'CURRENT_URL/?gender=1,3';
dest.channel[0].href = handleFilterUrl(params, { gender: '1,3' });
dest.channel[1].name = '女生';
dest.channel[1].href = 'CURRENT_URL/?gender=2,3';
dest.channel[1].href = handleFilterUrl(params, { gender: '2,3' });
return dest;
};
... ... @@ -101,7 +136,7 @@ exports.handleSaleFilterData = (origin) => {
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.handleSaleOptsData = () => {
exports.handleSaleOptsData = (params) => {
var dest = {};
dest.countPerPage = 60;
... ... @@ -112,7 +147,7 @@ exports.handleSaleOptsData = () => {
for (let i = 0; i < 2; i++) {
let opt = {};
opt.href = 'CURRENT_URL/?order=s_p_asc';
opt.href = handleFilterUrl(params, { order: 's_p_asc' });
opt.name = '价格';
opt.hasSortOrient = {};
opt.hasSortOrient.active = {};
... ... @@ -128,7 +163,7 @@ exports.handleSaleOptsData = () => {
* 处理页面左侧分类筛选数据
* @return {[type]} [description]
*/
exports.handleSaleSortData = (origin) => {
exports.handleSaleSortData = (origin, params) => {
var leftContent = {};
leftContent.allSort = {};
... ... @@ -145,7 +180,7 @@ exports.handleSaleSortData = (origin) => {
category.childList.push({
name: subValue.category_name,
num: subValue.node_count,
href: ''
href: handleFilterUrl(params, { sort: subValue.relation_parameter.sort })
});
});
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2016-05-19 10:20:08
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-25 18:20:33
* @Last Modified time: 2016-05-26 11:11:37
*/
'use strict';
... ... @@ -67,11 +67,11 @@ exports.getSaleOthersData = (params) => {
}
if (!_.isEmpty(result[0].data.filter)) {
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter);
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
}
if (!_.isEmpty(result[0].data.filter.group_sort)) {
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
}
... ... @@ -91,7 +91,7 @@ exports.getSaleDiscountData = (params) => {
if (result[0].code === 200) {
finalResult.saleList = {};
finalResult.saleList.goods = saleHandler.handleSaleGoodsListData(result[0].data.product_list);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
return finalResult;
... ... @@ -118,10 +118,10 @@ exports.getSalebreakingYardsData = (params) => {
if (!_.isEmpty(result[1].data.filter)) {
finalResult.filters = saleHandler.handleSaleFilterData(result[1].data.filter);
finalResult.leftContent = saleHandler.handleSaleSortData(result[1].data.filter.group_sort);
finalResult.leftContent = saleHandler.handleSaleSortData(result[1].data.filter.group_sort, params);
}
}
finalResult.opts = saleHandler.handleSaleOptsData();
finalResult.opts = saleHandler.handleSaleOptsData(params);
return finalResult;
});
};
... ...
... ... @@ -12,7 +12,7 @@ const isTest = process.env.NODE_ENV === 'test';
module.exports = {
port: 6002,
domains: {
api: 'http://testapi.yoho.cn:28078/', // 192.168.102.205:8080 testapi.yoho.cn:28078
api: 'http://api.yoho.cn/', // 192.168.102.205:8080 testapi.yoho.cn:28078
service: 'http://testservice.yoho.cn:28077',
search: 'http://192.168.10.64:8080/yohosearch/'
},
... ...