修改搜索为新的Search接口,并变换商品数据处理方式
Showing
4 changed files
with
208 additions
and
10 deletions
@@ -15,6 +15,7 @@ use Api\Sign; | @@ -15,6 +15,7 @@ use Api\Sign; | ||
15 | */ | 15 | */ |
16 | class SearchData | 16 | class SearchData |
17 | { | 17 | { |
18 | + protected static $_searchurl = 'http://101.200.31.165/yohosearch/search.json'; | ||
18 | 19 | ||
19 | /** | 20 | /** |
20 | * 模糊搜索提供的关键词 | 21 | * 模糊搜索提供的关键词 |
@@ -58,8 +59,25 @@ class SearchData | @@ -58,8 +59,25 @@ class SearchData | ||
58 | */ | 59 | */ |
59 | public static function searchLiDatas($query = null, $brand = null, $gender = null, $color = null, $size = null, $price = null, $p_d = null, $sort = null, $order = 's_t_desc', $page = 1, $limit = 60, $channel = null) | 60 | public static function searchLiDatas($query = null, $brand = null, $gender = null, $color = null, $size = null, $price = null, $p_d = null, $sort = null, $order = 's_t_desc', $page = 1, $limit = 60, $channel = null) |
60 | { | 61 | { |
61 | - // 构建必传参数 | ||
62 | - $param = Yohobuy::param(); | 62 | + // 排序数据映射表 |
63 | + $order_map = array( | ||
64 | + 's_t_desc' => 'shelve_time:desc', | ||
65 | + 's_t_asc' => 'shelve_time:asc', | ||
66 | + 's_p_asc' => 'sales_price:asc', | ||
67 | + 's_p_desc' => 'sales_price:desc', | ||
68 | + 's_d_desc' => 'discount:desc', | ||
69 | + 's_d_asc' => 'discount:asc', | ||
70 | + 'skn_desc' => 'product_skn:desc', | ||
71 | + 'skn_asc' => 'product_skn:asc', | ||
72 | + 'activities_desc' => 'activities.order_by:desc', | ||
73 | + 'activities_asc' => 'activities.order_by:asc', | ||
74 | + 's_n_asc'=>'sales_num:asc', | ||
75 | + 's_n_desc'=>'sales_num:desc', | ||
76 | + 'activities_id_desc' => 'activities.activity_id:desc', | ||
77 | + 'activities_id_asc' => 'activities.activity_id:asc', | ||
78 | + ); | ||
79 | + | ||
80 | + $param = array(); | ||
63 | 81 | ||
64 | is_null($query) || $param['query'] = $query; | 82 | is_null($query) || $param['query'] = $query; |
65 | is_null($brand) || $param['brand'] = $brand; | 83 | is_null($brand) || $param['brand'] = $brand; |
@@ -69,14 +87,13 @@ class SearchData | @@ -69,14 +87,13 @@ class SearchData | ||
69 | is_null($price) || $param['price'] = $price; | 87 | is_null($price) || $param['price'] = $price; |
70 | is_null($p_d) || $param['p_d'] = $p_d; | 88 | is_null($p_d) || $param['p_d'] = $p_d; |
71 | is_null($sort) || $param['sort'] = $sort; | 89 | is_null($sort) || $param['sort'] = $sort; |
72 | - is_null($channel) || $param['channel'] = $channel; | ||
73 | - $param['method'] = 'app.search.li'; | ||
74 | - $param['order'] = $order; | 90 | + // is_null($channel) || $param['channel'] = $channel; |
91 | + $param['order'] = $order_map[$order]; | ||
75 | $param['page'] = $page; | 92 | $param['page'] = $page; |
76 | - $param['limit'] = $limit; | ||
77 | - $param['client_secret'] = Sign::getSign($param); | 93 | + $param['viewNum'] = $limit; // 每页记录数 |
94 | + $param['status'] = 1; // 是否上架,1表示在架,2表示不在 | ||
78 | 95 | ||
79 | - return Yohobuy::get(Yohobuy::API_URL, $param); | 96 | + return Yohobuy::get(self::$_searchurl, $param); |
80 | } | 97 | } |
81 | 98 | ||
82 | } | 99 | } |
@@ -45,7 +45,7 @@ class ListProcess | @@ -45,7 +45,7 @@ class ListProcess | ||
45 | 45 | ||
46 | foreach ($data as $value) | 46 | foreach ($data as $value) |
47 | { | 47 | { |
48 | - $products[] = Helpers::formatProduct($value); | 48 | + $products[] = Helpers::formatProduct($value, true, true, true, true); |
49 | } | 49 | } |
50 | 50 | ||
51 | return $products; | 51 | return $products; |
@@ -44,9 +44,10 @@ class Helpers | @@ -44,9 +44,10 @@ class Helpers | ||
44 | * @param bool $showTag 控制是否显示标签 | 44 | * @param bool $showTag 控制是否显示标签 |
45 | * @param bool $showNew 控制是否显示NEW图标 | 45 | * @param bool $showNew 控制是否显示NEW图标 |
46 | * @param bool $showSale 控制是否显示SALE图标 | 46 | * @param bool $showSale 控制是否显示SALE图标 |
47 | + * @param bool $fromSearch 是否是搜索页搜出来的商品数据 | ||
47 | * @return array | false | 48 | * @return array | false |
48 | */ | 49 | */ |
49 | - public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true) | 50 | + public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true, $fromSearch = false) |
50 | { | 51 | { |
51 | // 商品信息有问题,则不显示 | 52 | // 商品信息有问题,则不显示 |
52 | if (!isset($productData['product_skn'])) { | 53 | if (!isset($productData['product_skn'])) { |
@@ -61,6 +62,13 @@ class Helpers | @@ -61,6 +62,13 @@ class Helpers | ||
61 | $result = array(); | 62 | $result = array(); |
62 | $result['id'] = $productData['product_skn']; | 63 | $result['id'] = $productData['product_skn']; |
63 | $result['product_id'] = $productData['product_id']; | 64 | $result['product_id'] = $productData['product_id']; |
65 | + | ||
66 | + // 如果是来自搜索页搜索出来的图片要先处理一下 | ||
67 | + if($fromSearch && $productData['default_images']) | ||
68 | + { | ||
69 | + $productData['default_images'] = Images::template($productData['default_images'], 'goodsimg'); | ||
70 | + } | ||
71 | + | ||
64 | $result['thumb'] = self::getImageUrl($productData['default_images'], 235, 314); | 72 | $result['thumb'] = self::getImageUrl($productData['default_images'], 235, 314); |
65 | $result['name'] = $productData['product_name']; | 73 | $result['name'] = $productData['product_name']; |
66 | $result['price'] = $productData['market_price']; | 74 | $result['price'] = $productData['market_price']; |
library/Plugin/Images.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * User: Zip | ||
4 | + * Date: 15/10/28 | ||
5 | + * Time: 下午13:08 | ||
6 | + */ | ||
7 | +namespace Plugin; | ||
8 | +class Images | ||
9 | +{ | ||
10 | + private static $domain = '.static.yhbimg.com'; | ||
11 | + private static $default_image = '/2015/08/25/02/01dd632a6e07bfef457ce4beda21dd6413.png'; | ||
12 | + private static $domainList = array( | ||
13 | + '01' => array( | ||
14 | + 'img10.static.yhbimg.com', | ||
15 | + 'img11.static.yhbimg.com', | ||
16 | + ), | ||
17 | + '02' => array( | ||
18 | + 'img12.static.yhbimg.com', | ||
19 | + 'img13.static.yhbimg.com' | ||
20 | + ), | ||
21 | + 'yhb-head' => 'head.static.yhbimg.com' | ||
22 | + ); | ||
23 | + | ||
24 | + private static $staticDomain = array( | ||
25 | + 'bucket' => '' | ||
26 | + ); | ||
27 | + | ||
28 | + private static $qiniuDomain = 'yhfair.qiniudn.com'; | ||
29 | + | ||
30 | + /** | ||
31 | + * 缩略图模板 | ||
32 | + * @param $fileName | ||
33 | + * @param $bucket | ||
34 | + * @param string $position () | ||
35 | + * @param string $background | ||
36 | + * @return string | ||
37 | + */ | ||
38 | + static function template($fileName, $bucket = 'yhfair', $mode = 1) | ||
39 | + { | ||
40 | + | ||
41 | + return self::url($fileName, $bucket, $mode); | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * | ||
46 | + * @param unknown $fileName | ||
47 | + * @param string $bucket | ||
48 | + * @return string | ||
49 | + */ | ||
50 | + public static function getSourceUrl($fileName, $bucket = 'yhfair') | ||
51 | + { | ||
52 | + if(preg_match('|http://|', $fileName)){ | ||
53 | + return $fileName; | ||
54 | + } | ||
55 | + $domain = self::getDomain($bucket, $fileName); | ||
56 | + return 'http://' . $domain . '/' . $bucket . $fileName; | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * 根据尺寸获得图片url | ||
61 | + * @param unknown $fileName | ||
62 | + * @param unknown $width | ||
63 | + * @param unknown $height | ||
64 | + * @param number $mode | ||
65 | + * @param string $bucket | ||
66 | + * @return mixed | ||
67 | + */ | ||
68 | + public static function getImageUrl($fileName, $width, $height, $mode = 1, $bucket = 'yhfair'){ | ||
69 | + if(!preg_match('|http://|', $fileName)){ | ||
70 | + $fileName = self::template($fileName, $bucket, $mode); | ||
71 | + } | ||
72 | + return str_replace('{width}', $width, str_replace('{height}', $height, str_replace('{mode}', $mode, $fileName))); | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * 缩略图模板 | ||
77 | + * @param $fileName | ||
78 | + * @param $bucket | ||
79 | + * @param string $position () | ||
80 | + * @param string $background | ||
81 | + * @return string | ||
82 | + */ | ||
83 | + static function template2($fileName, $bucket, $position = 'center', $background = 'd2hpdGU=') | ||
84 | + { | ||
85 | + $domain = self::getDomain($bucket, $fileName); | ||
86 | + $key = $bucket . $fileName; | ||
87 | + return self::MakeBaseUrl($domain, $key) . '?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/' . $background . '/position/' . $position.'/quality/90'; | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * 获取图片URL模板 | ||
92 | + * @param $fileName | ||
93 | + * @param int $mode | ||
94 | + * @param string $bucket | ||
95 | + * @return string | ||
96 | + */ | ||
97 | + public static function url($fileName, $bucket = 'yhfair', $mode = 1) | ||
98 | + { | ||
99 | + $domain = self::getDomain($bucket, $fileName); | ||
100 | + return self::getImgTemplateUrl($bucket . $fileName, $mode, $domain); | ||
101 | + } | ||
102 | + | ||
103 | + public static function getDomain($bucket, $fileName) | ||
104 | + { | ||
105 | + $domain = ''; | ||
106 | + if(!empty(self::$domainList[$bucket])){ | ||
107 | + $domain = self::$domainList[$bucket]; | ||
108 | + }else{ | ||
109 | + $node = mb_substr($fileName, 15, 2); | ||
110 | + if (!empty(self::$domainList[$node])) { | ||
111 | + $domainList = self::$domainList[$node]; | ||
112 | + $nodeNum = sprintf('%u', crc32($fileName)) % count($domainList); | ||
113 | + $domain = $domainList[$nodeNum]; | ||
114 | + } | ||
115 | + } | ||
116 | + return $domain; | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * 获取模板的图片地址 | ||
121 | + * @param $fileName | ||
122 | + * @param int $width | ||
123 | + * @param int $height | ||
124 | + * @param int $mode | ||
125 | + * @param null $domain | ||
126 | + * @return string | ||
127 | + */ | ||
128 | + private static function getImgTemplateUrl($fileName, $mode = 1, $domain = null) | ||
129 | + { | ||
130 | + if ($domain == null) { | ||
131 | + $domain = self::$qiniuDomain; | ||
132 | + } | ||
133 | + $baseUrl = self::MakeBaseUrl($domain, $fileName); | ||
134 | + return self::MakeTemplateRequest($baseUrl); | ||
135 | + } | ||
136 | + | ||
137 | + private static function MakeBaseUrl($domain, $key) // => $baseUrl | ||
138 | + { | ||
139 | + $keyEsc = str_replace("%2F", "/", rawurlencode($key)); | ||
140 | + return "http://$domain/$keyEsc"; | ||
141 | + } | ||
142 | + | ||
143 | + private static function MakeTemplateRequest($url) | ||
144 | + { | ||
145 | + $ops = array(); | ||
146 | + $ops[] = '{mode}'; | ||
147 | + $ops[] = 'w/{width}'; | ||
148 | + $ops[] = 'h/{height}'; | ||
149 | + if (empty($ops)) { | ||
150 | + return $url; | ||
151 | + } | ||
152 | + return $url . "?imageView/" . implode('/', $ops); | ||
153 | + } | ||
154 | + | ||
155 | + /** | ||
156 | + * 获取老的图片地址 | ||
157 | + * @param $fileName | ||
158 | + * @param $bucket | ||
159 | + * @param $width | ||
160 | + * @param $height | ||
161 | + * @param string $position | ||
162 | + * @param string $background | ||
163 | + * @return mixed | ||
164 | + */ | ||
165 | + public static function getUrl($fileName,$width,$height,$bucket, $position = 'center', $background = 'd2hpdGU=') | ||
166 | + { | ||
167 | + if(empty($fileName)){ | ||
168 | + $fileName = self::$default_image; | ||
169 | + } | ||
170 | + $url = self::template2($fileName, $bucket, $position, $background); | ||
171 | + return str_replace(array('{width}','{height}'),array($width,$height),$url); | ||
172 | + } | ||
173 | +} |
-
Please register or login to post a comment