|
@@ -3,37 +3,40 @@ var _ = require('lodash'); |
|
@@ -3,37 +3,40 @@ var _ = require('lodash'); |
3
|
var fs = require('fs');
|
3
|
var fs = require('fs');
|
4
|
var searchDomain = require('../../config/common.js').yohoSearch;
|
4
|
var searchDomain = require('../../config/common.js').yohoSearch;
|
5
|
|
5
|
|
6
|
-exports.getJSONFile=function(req,res){
|
6
|
+exports.getJSONFile = function (req, res) {
|
7
|
request.get("http://192.168.102.208:8087/yohosearch/brand/list.json").pipe(res);
|
7
|
request.get("http://192.168.102.208:8087/yohosearch/brand/list.json").pipe(res);
|
8
|
}
|
8
|
}
|
9
|
|
9
|
|
10
|
-exports.search=function(req,res){
|
|
|
11
|
- //req.body
|
|
|
12
|
- var url="http://192.168.102.208:8087/yohosearch/search.json";//?viewNum=15&query=51022754,51178582
|
|
|
13
|
- request({url: url}, function (error, response, body) {
|
|
|
14
|
- var data={};
|
|
|
15
|
- data.list=[];
|
|
|
16
|
- body=JSON.parse(body);
|
|
|
17
|
- var dataList=body.data.product_list;
|
|
|
18
|
- var goodslist=[];
|
|
|
19
|
- var goodslist1=[];
|
|
|
20
|
- for(var m=0;m<dataList.length;m++){
|
|
|
21
|
- for(var n=0;n<dataList[m].goods_list.length;n++){
|
|
|
22
|
- goodslist.push({a:dataList[m],b:dataList[m].goods_list[n]})
|
|
|
23
|
- }
|
|
|
24
|
- }
|
|
|
25
|
- for(var i=0;i<goodslist.length;i++){
|
|
|
26
|
- goodslist1[i]= _.assign({},goodslist[i].a,goodslist[i].b);
|
|
|
27
|
- }
|
|
|
28
|
- data.list=goodslist1.concat();
|
|
|
29
|
- //data.list=body.data.product_list;
|
|
|
30
|
- data.total=data.list.length;
|
|
|
31
|
- data.page=body.data.page;
|
|
|
32
|
- data.size=5;
|
|
|
33
|
- var a = (/^[1-9]\d*$/).test(data.total/data.size);
|
|
|
34
|
- data.totalPage=a?parseInt(data.total/data.size):parseInt(data.total/data.size)+1;
|
|
|
35
|
- res.json({data:{data:data}});
|
|
|
36
|
- });
|
10
|
+exports.search = function (req, res) {
|
|
|
11
|
+ var size = 10;//每页数据量
|
|
|
12
|
+ var page = 1;
|
|
|
13
|
+ if (req.body.page) {
|
|
|
14
|
+ page = req.body.page;
|
|
|
15
|
+ }
|
|
|
16
|
+ var url = "http://x.yohobuy.com//yohosearch/search.json?viewNum=" + size + "&query=" + req.body.query + "&page=" + page;
|
|
|
17
|
+ request({url: url}, function (error, response, body) {
|
|
|
18
|
+ var data = {};
|
|
|
19
|
+ data.list = [];
|
|
|
20
|
+ body = JSON.parse(body);
|
|
|
21
|
+ var dataList = body.data.product_list;
|
|
|
22
|
+ var goodslist = [];
|
|
|
23
|
+ var goodslist1 = [];
|
|
|
24
|
+ for (var m = 0; m < dataList.length; m++) {
|
|
|
25
|
+ for (var n = 0; n < dataList[m].goods_list.length; n++) {
|
|
|
26
|
+ goodslist.push({a: dataList[m], b: dataList[m].goods_list[n]})
|
|
|
27
|
+ }
|
|
|
28
|
+ }
|
|
|
29
|
+ for (var i = 0; i < goodslist.length; i++) {
|
|
|
30
|
+ goodslist1[i] = _.assign({}, goodslist[i].a, goodslist[i].b);
|
|
|
31
|
+ }
|
|
|
32
|
+ //data.list=body.data.product_list;
|
|
|
33
|
+ data.list = goodslist1.concat();//显示数据
|
|
|
34
|
+ data.page = body.data.page;//页码
|
|
|
35
|
+ data.totalPage = body.data.page_total;
|
|
|
36
|
+ data.nums = data.list.length;//记录每一页数据量
|
|
|
37
|
+ console.log("最终data", data);
|
|
|
38
|
+ res.json({data: {data: data}});
|
|
|
39
|
+ });
|
37
|
};
|
40
|
};
|
38
|
|
41
|
|
39
|
|
42
|
|