Search.php
2.75 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
<?php
namespace Product;
use Configs\CacheConfig;
use Plugin\Images;
use Plugin\Cache;
use Plugin\HelperSearch;
use \LibModels\Web\Product\SearchData;
/**
* sale首页模板数据模型
*
* @name SaleModel
* @package models
* @copyright yoho.inc
* @version 1.0 (2015-12-17 13:54:56)
* @author sefon
*/
class SearchModel
{
/**
* 根据条件获取搜索数据
*
* @param $condition 搜索数据的条件
* @param $options Array([imgSize]
* => Array([0] => 235[1] => 314)[minImgSize] => Array([0] => 60[1] => 80)[gender] => 1[needPd] => Y[rowNum] => 5[viewNum] => 60)
* @author sefon 2015-12-17 16:12:18
* @return array
*/
public static function getSearchData($condition, $options)
{
// 调用接口查询商品数据
$result = SearchData::searchElasticByCondition($condition);
// 调用分类信息
$category = SearchData::getClassesData();
if (isset($category['code']) && $category['code'] === 200) {
$result['data']['filter']['group_sort'] = $category['data']['sort'];
}
// 调用折扣区间
$discount = SearchData::getDiscount();
if (isset($discount['code']) && $discount['code'] === 200) {
$result['data']['filter']['discount'] = $discount['data']['discount'];
}
// 调用最新上架
$recent = SearchData::recentShelve();
if (isset($discount['code']) && $discount['code'] === 200) {
$result['data']['filter']['recent'] = $recent['data']['recent'];
}
// 组织模板数据
if (isset($result['code']) && $result['code'] === 200) {
$res = HelperSearch::getList($result, $options);
$list = HelperSearch::getTemplateData($res, $options);
$data = array(
'productListPage' => true, //初始化js
'list' => $list
);
}
return $data;
}
/**
* 根据product_sn查询产品图片信息
* @param $product_sn
* @param $options
* @author sefon 2015-12-28 18:09:28
* @return array
*/
public static function getProductPic($product_sn, $options)
{
$data = array();
$condition['query'] = $product_sn;
$condition['query'] = $product_sn;
//返回搜索条件
$condition['needFilter'] = 0;
//获取产品数据
$data = SearchData::searchElasticByCondition($condition);
if (isset($data['code']) && $data['code'] === 200 && isset($data['data']['product_list']) && !empty($data['data']['product_list'])) {
//组织数据结构
$data = HelperSearch::getProductPic($data['data']['product_list'], $options);
}
echo json_encode($data);
}
}