yohosearch.js 1.16 KB
var request = require('request');
var _ = require('lodash');
var fs = require('fs');
var searchDomain = require('../../config/common.js').yohoSearch;

exports.getJSONFile=function(req,res){
    request.get("http://192.168.10.64:8080/yohosearch/brand/list.json").pipe(res);
};

exports.search=function(req,res){
	var url="http://192.168.10.64:8080/yohosearch/search.json?viewNum=15&query=51022754,51178582";
	request({url: url}, function (error, response, body) {
		var data={};
		data.list=[];
		body=JSON.parse(body);
		var dataList=body.data.product_list;
		var goodslist=[];
		var goodslist1=[];
		for(var m=0;m<dataList.length;m++){
			for(var n=0;n<dataList[m].goods_list.length;n++){
				goodslist.push({a:dataList[m],b:dataList[m].goods_list[n]})
			}
		}
		for(var i=0;i<goodslist.length;i++){
			goodslist1[i]= _.assign({},goodslist[i].a,goodslist[i].b);
		}
		data.list=goodslist1.concat();
		//data.list=body.data.product_list;
		data.total=data.list.length;
		data.page=body.data.page;
		data.size=5;
		var a = (/^[1-9]\d*$/).test(data.total/data.size);
		data.totalPage=a?parseInt(data.total/data.size):parseInt(data.total/data.size)+1;
		res.json({data:{data:data}});
	});
};