Authored by Rock Zhang

修复搜索图片处理的bug

@@ -121,10 +121,9 @@ class Helpers @@ -121,10 +121,9 @@ class Helpers
121 * @param bool $showTag 控制是否显示标签 121 * @param bool $showTag 控制是否显示标签
122 * @param bool $showNew 控制是否显示NEW图标 122 * @param bool $showNew 控制是否显示NEW图标
123 * @param bool $showSale 控制是否显示SALE图标 123 * @param bool $showSale 控制是否显示SALE图标
124 - * @param bool $fromSearch 是否是搜索页搜出来的商品数据  
125 * @return array | false 124 * @return array | false
126 */ 125 */
127 - public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true, $fromSearch = false) 126 + public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true)
128 { 127 {
129 // 商品信息有问题,则不显示 128 // 商品信息有问题,则不显示
130 if (!isset($productData['product_skn'])) { 129 if (!isset($productData['product_skn'])) {
@@ -147,12 +146,8 @@ class Helpers @@ -147,12 +146,8 @@ class Helpers
147 } 146 }
148 147
149 // 如果是来自搜索页搜索出来的图片要先处理一下 148 // 如果是来自搜索页搜索出来的图片要先处理一下
150 - if($fromSearch && $productData['default_images'])  
151 - {  
152 - $productData['default_images'] = Images::template($productData['default_images'], 'goodsimg');  
153 - }  
154 -  
155 - $result['thumb'] = self::getImageUrl($productData['default_images'], 235, 314); 149 + $result['thumb'] = Images::getImageUrl($productData['default_images'], 235, 314);
  150 +
156 $result['name'] = $productData['product_name']; 151 $result['name'] = $productData['product_name'];
157 $result['price'] = $productData['market_price']; 152 $result['price'] = $productData['market_price'];
158 $result['salePrice'] = $productData['sales_price']; 153 $result['salePrice'] = $productData['sales_price'];
@@ -37,7 +37,6 @@ class Images @@ -37,7 +37,6 @@ class Images
37 */ 37 */
38 static function template($fileName, $bucket = 'yhfair', $mode = 1) 38 static function template($fileName, $bucket = 'yhfair', $mode = 1)
39 { 39 {
40 -  
41 return self::url($fileName, $bucket, $mode); 40 return self::url($fileName, $bucket, $mode);
42 } 41 }
43 42
@@ -65,26 +64,12 @@ class Images @@ -65,26 +64,12 @@ class Images
65 * @param string $bucket 64 * @param string $bucket
66 * @return mixed 65 * @return mixed
67 */ 66 */
68 - public static function getImageUrl($fileName, $width, $height, $mode = 1, $bucket = 'yhfair'){ 67 + public static function getImageUrl($fileName, $width, $height, $mode = 1, $bucket = 'goodsimg')
  68 + {
69 if(!preg_match('|http://|', $fileName)){ 69 if(!preg_match('|http://|', $fileName)){
70 $fileName = self::template($fileName, $bucket, $mode); 70 $fileName = self::template($fileName, $bucket, $mode);
71 } 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'; 72 + return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
88 } 73 }
89 74
90 /** 75 /**
@@ -140,34 +125,17 @@ class Images @@ -140,34 +125,17 @@ class Images
140 return "http://$domain/$keyEsc"; 125 return "http://$domain/$keyEsc";
141 } 126 }
142 127
143 - private static function MakeTemplateRequest($url)  
144 - { 128 + private static function MakeTemplateRequest($url)
  129 + {
145 $ops = array(); 130 $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 - } 131 + $ops[] = '{mode}';
  132 + $ops[] = 'w/{width}';
  133 + $ops[] = 'h/{height}';
154 134
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; 135 + if (empty($ops)) {
  136 + return $url;
169 } 137 }
170 - $url = self::template2($fileName, $bucket, $position, $background);  
171 - return str_replace(array('{width}','{height}'),array($width,$height),$url); 138 +
  139 + return $url . "?imageView/" . implode('/', $ops);
172 } 140 }
173 } 141 }