Goods.php
2.51 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
<?php
/**
* 搜索商品
* @author tongdesheng
*
*/
class YHMSearch_Goods extends YHMSearch_Core {
/**
* 搜索条件,sales_price是以逗号分隔
* @var string
*/
private $_searchConditions = array('gender', 'quality', 'msort', 'storeid','stocknumber',
'identity', 'price', 'keyword', 'page', 'viewNum', 'brand', 'searchuid', 'storetype');
/**
* keyword需要搜索的字段
* @var string
*/
private $_keywordFields = 'goods_name';
/**
* 支持的排序方式
* @var string
*/
private $_orderType = array('hot_number:asc', 'hot_number:desc', "stock_number:desc", 'create_time:asc', 'create_time:desc');
/**
* 搜索的路径
* @var string
*/
private $_urlPath = 'search';
public function getList($params) {
$condParams = array(
// 'field' => $this->_keywordFields //暂时不需要指定搜索的field
);
//筛选条件
if (!empty($params)) {
foreach ($this->_searchConditions as $cond) {
if (isset($params[$cond])) {
$condParams[$cond] = $params[$cond];
}
}
}
if (isset($params['order_type']))
{
$typearr = explode(",", $params['order_type']);
$newtype = array_intersect($typearr, $this->_orderType);
//排序方式
if (!empty($params['order_type']) && (count($typearr) == count($newtype))) {
$condParams['order'] = $params['order_type'];
}
}else {
$condParams['order'] = 'create_time:desc';
}
// print_r($condParams);
// $condParams['order'] = $params['order_type'];
//{"search":{"result":{"size":10,"skcs":{"153805":"NIKE LUNARFLY 306 男子运动鞋","126232":"NIKE AF1 TRUCK TEE 男子印花短袖T恤","126240":"NIKE TEE-LIFE IS SHORT 女子短袖T恤","156814":"NIKE ROSHE RUN LIBERTY 印花运动鞋","152328":"NIKE ROSHERUN NM BREEZE男子运动鞋","156818":"NIKE INTERNATIONALIST LIBERTY 印花运动鞋","153188":"NIKE ROSHERUN NM BREEZE男子运动鞋","153804":"NIKE LUNARFLY 306 男子运动鞋","126273":"NIKE SB FREMONT STRETCH 5-PKT PANT男子休闲裤","126247":"NIKE 男子圆领logo短袖T恤"}}}}
$retData = $this->req($this->_urlPath, $condParams);
if (empty($retData['search']['result']['skcs'])) {
return array();
}
return $retData['search']['result']['skcs']; //返回skc列表
}
}