HelperHome.php 2.43 KB
<?php

namespace WebPlugin;

use WebPlugin\Paging;
use WebPlugin\Helpers;
use LibModels\Web\Product\BrandData;
use Configs\ChannelConfig;

/**
 * 搜索辅助类
 */
class HelperHome
{

    /**
     * 格式化喜欢的品牌
     * @param $brandInfo
     * @param int $i
     * @return array
     */
    public static function formatFavBrand($brandInfo, $i = 10)
    {
        //取前20个热销品牌
        $hotBrands = array();
        if ($brandInfo) {
            foreach ($brandInfo as $value) {
                if (isset($value['is_hot']) && $value['is_hot'] == 'Y') {
                    $hotBrands[] = array(
                        'href' => Helpers::url('', '', $value['brand_domain']),
                        'logo' => Images::getSourceUrl($value['brand_ico'], 'brandLogo'),
                        'name' => $value['brand_name'],
                    );
                    $i--;
                }
                if ($i <= 0) {
                    break;
                }
            }
        }
        return $hotBrands;
    }

    /**
     * 格式化新品上架数据(个人中心, 支付成功)
     * @param $product
     * @return array
     */
    public static function formatNew($product, $size = array())
    {
        $result = array();
        foreach ($product as $key => $val) {
            if (!empty($size)) {
                $img = (isset($val['default_images']) && $val['default_images'])?Images::getImageUrl($val['default_images'], $size['width'], $size['height']) : '';
            } else {
                $img = (isset($val['default_images']) && $val['default_images'])?Images::getImageUrl($val['default_images'], 100, 100) : '';

                // 强制对图片进行切图规则处理 redmine:12390
                if (strpos($img, 'imageView')) {
                    $img = strstr($img, 'imageView', true) . 'imageMogr2/thumbnail/100x100/extent/100x100/background/d2hpdGU=/position/center/quality/90';
                }
            }

            $result[] = array(
                    'href' => Helpers::getUrlBySkc($val['product_id'], $val['goods_list'][0]['product_skc'], $val['cn_alphabet']),
                    'thumb' => $img,
                    'name' => $val['product_name'],
                    'price' => $val['sales_price'],
                    'productId' => $val['product_id'],
                );
        }
        return $result;
    }

}