SearchData.php
2.93 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace LibModels\Web\Product;
use Api\Yohobuy;
class SearchData extends \LibModels\Wap\Product\SearchData
{
/**
* 获取搜索的服务地址
*
* 备注:此处是根据环境来确定使用阿里云内网还是外网的URL
*
* @return string
*/
private static function getUrl($type = 'search')
{
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
switch (APPLICATION_ENV) {
case 'release':
if($type == 'sort'){
return 'http://100.98.132.63/yohosearch/sortgroup.json';
}
if($type == 'discount'){
return 'http://100.98.132.63/yohosearch/discount.json';
}
if($type == 'recent'){
return 'http://100.98.132.63/yohosearch/recent.json';
}
return 'http://100.98.132.63/yohosearch/search.json';
case 'test':
case 'preview':
case 'developer':
default:
if($type == 'sort'){
return 'http://101.200.31.165/yohosearch/sortgroup.json';
}
if($type == 'discount'){
return 'http://101.200.31.165/yohosearch/discount.json';
}
if($type == 'recent'){
return 'http://101.200.31.165/yohosearch/recent.json';
}
return 'http://101.200.31.165/yohosearch/search.json';
}
}
/**
* 根据分类列表获取商品信息
*
* @param array $params
* @param array $sortList
* @return array
*/
public static function getSearchDataBySort(array $params, array $sortList)
{
$data = array();
foreach ($sortList as $v) {
if(empty($v['viewNum'])){
continue;
}
$searchParams = array_merge($params, $v);
$list = self::searchElasticByCondition($searchParams, true);
$productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list'];
if(count($productList) < $v['viewNum']){
continue;
}
$data = array_merge($data, $productList);
}
return $data;
}
/**
* 获取品类数据
*
* @return array 品类数据
*/
public static function getClassesData($condition = array(), $cache = false)
{
$param['brand'] = $condition;
return Yohobuy::get(self::getUrl('sort'),$param, $cache);
}
/**
* 获取折扣区间
*/
public static function getDiscount(){
return Yohobuy::get(self::getUrl('discount'));
}
/**
* 获取最新上架
*/
public static function recentShelve(){
return Yohobuy::get(self::getUrl('recent'));
}
}