HelperHome.php 1.84 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)
    {
        $result = array();
        foreach ($product as $key => $val) {
            $result[] = array(
                    'href' => Helpers::getUrlBySkc($val['product_id'], $val['goods_list'][0]['product_skc'], $val['cn_alphabet']),
                    'thumb' => (isset($val['default_images']) && $val['default_images'])?Images::getImageUrl($val['default_images'], 400, 500) : '',
                    'name' => $val['product_name'],
                    'price' => $val['sales_price'],
                    'productId' => $val['product_id'],
                );
        }
        return $result;
    }

}