SearchData.js
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const querystring = require('querystring');
const getUrl = ($type)=>{
var map = {
sort: '/sortgroup.json',
discount: '/discount.json',
recent: '/recent.json',
suggest: '/suggest.json',
'new-shelve': '/new-shelve.json',
shop: '/shops.json',
brand: '/brand/list.json'
};
return map[$type] || '/search.json';
};
const getBrandListUrl = ()=>{
return getUrl('brand');
};
const getProductUrl = ($condition, $type)=>{
let $orderMaps = {
s_t_desc: 'shelve_time:desc',
s_t_asc: 'shelve_time:asc',
s_p_asc: 'sales_price:asc',
s_p_desc: 'sales_price:desc',
p_d_desc: 'discount:desc',
p_d_asc: 'discount:asc',
skn_desc: 'product_skn:desc',
skn_asc: 'product_skn:asc',
activities_desc: 'activities.order_by:desc',
activities_asc: 'activities.order_by:asc',
s_n_asc: 'sales_num:asc',
s_n_desc: 'sales_num:desc',
activities_id_desc: 'activities.activity_id:desc',
activities_id_asc: 'activities.activity_id:asc',
brand_desc: 'brand_weight:desc'
};
let $param = {
status: 1,
sales: 'Y',
outlets: 2,
stocknumber: 1,
attribute_not: 2
};
if (!$condition.order) {
$param.order = $orderMaps.s_t_desc;
} else {
$param.order = $orderMaps[$condition.order] ? $orderMaps[$condition.order] : '';
}
if (!$condition.page) {
$param.page = 1;
}
if ($condition.viewNum) {
$param.viewNum = $condition.viewNum;
} else if (!$condition.limit) {
$param.viewNum = 60;
} else {
$param.viewNum = $condition.limit;
delete $condition.limit;
}
if (!$condition) {
$param += $condition;
}
console.log(JSON.stringify($param));
return getUrl($type) + '?' + querystring.stringify($param);// searchApi.get(getUrl($type), $param,{cache:true});
};
module.exports = {
getProductUrl,
getBrandListUrl
};