Authored by Rock Zhang

修复搜索图片处理的bug

... ... @@ -121,10 +121,9 @@ class Helpers
* @param bool $showTag 控制是否显示标签
* @param bool $showNew 控制是否显示NEW图标
* @param bool $showSale 控制是否显示SALE图标
* @param bool $fromSearch 是否是搜索页搜出来的商品数据
* @return array | false
*/
public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true, $fromSearch = false)
public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true)
{
// 商品信息有问题,则不显示
if (!isset($productData['product_skn'])) {
... ... @@ -147,12 +146,8 @@ class Helpers
}
// 如果是来自搜索页搜索出来的图片要先处理一下
if($fromSearch && $productData['default_images'])
{
$productData['default_images'] = Images::template($productData['default_images'], 'goodsimg');
}
$result['thumb'] = self::getImageUrl($productData['default_images'], 235, 314);
$result['thumb'] = Images::getImageUrl($productData['default_images'], 235, 314);
$result['name'] = $productData['product_name'];
$result['price'] = $productData['market_price'];
$result['salePrice'] = $productData['sales_price'];
... ...
... ... @@ -37,7 +37,6 @@ class Images
*/
static function template($fileName, $bucket = 'yhfair', $mode = 1)
{
return self::url($fileName, $bucket, $mode);
}
... ... @@ -65,26 +64,12 @@ class Images
* @param string $bucket
* @return mixed
*/
public static function getImageUrl($fileName, $width, $height, $mode = 1, $bucket = 'yhfair'){
public static function getImageUrl($fileName, $width, $height, $mode = 1, $bucket = 'goodsimg')
{
if(!preg_match('|http://|', $fileName)){
$fileName = self::template($fileName, $bucket, $mode);
}
return str_replace('{width}', $width, str_replace('{height}', $height, str_replace('{mode}', $mode, $fileName)));
}
/**
* 缩略图模板
* @param $fileName
* @param $bucket
* @param string $position ()
* @param string $background
* @return string
*/
static function template2($fileName, $bucket, $position = 'center', $background = 'd2hpdGU=')
{
$domain = self::getDomain($bucket, $fileName);
$key = $bucket . $fileName;
return self::MakeBaseUrl($domain, $key) . '?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/' . $background . '/position/' . $position.'/quality/90';
return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
}
/**
... ... @@ -140,34 +125,17 @@ class Images
return "http://$domain/$keyEsc";
}
private static function MakeTemplateRequest($url)
{
private static function MakeTemplateRequest($url)
{
$ops = array();
$ops[] = '{mode}';
$ops[] = 'w/{width}';
$ops[] = 'h/{height}';
if (empty($ops)) {
return $url;
}
return $url . "?imageView/" . implode('/', $ops);
}
$ops[] = '{mode}';
$ops[] = 'w/{width}';
$ops[] = 'h/{height}';
/**
* 获取老的图片地址
* @param $fileName
* @param $bucket
* @param $width
* @param $height
* @param string $position
* @param string $background
* @return mixed
*/
public static function getUrl($fileName,$width,$height,$bucket, $position = 'center', $background = 'd2hpdGU=')
{
if(empty($fileName)){
$fileName = self::$default_image;
if (empty($ops)) {
return $url;
}
$url = self::template2($fileName, $bucket, $position, $background);
return str_replace(array('{width}','{height}'),array($width,$height),$url);
return $url . "?imageView/" . implode('/', $ops);
}
}
\ No newline at end of file
... ...