Hotrank.php 5.26 KB
<?php
namespace product;

use Plugin\Images;
use Api\Yohobuy;
use \LibModels\Web\Product\HotrankData;
use \LibModels\Web\Product\SearchData;

class HotrankModel {
    
    /**
     * 获取热销排行频道资源
     *
     * @param string $channel                       
     * @return array
     */
    static public function getChannelResource()
    {
         $channel = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
        switch ($channel)
        {
            case 'boys' :
                $resource = array('channel' => 'boys', 'gender' => '1,3','road' => 1,'code' => '80d772d8dff25300a2a2e4c97165330c');
                return $resource;
            case 'girls' :
                $resource = array('channel' => 'girls','gender' => '2,3','road' => 2,'code' => '8df64e505e94edb9881fd1e7efb702e9');
                return $resource;
            case 'lifestyle' :
                $resource = array('channel' => 'lifestyle','gender' => '','road' => 4,'code' => 'd131aba83a84a6977eee3a7403a713de');
                return $resource;
            case 'kids' :
                $resource = array('channel' => 'kids','gender' => '','road' => 3,'code' => 'bd6a06a08f8ca9b0db762f78e0bc5b68');
                return $resource;
        }
    }
    
    /**
     * 人气单品  一周热卖
     */
    static public function getSearchData($param,$page,$ajax)
    {
        // 调用接口查询商品数据
        $result = SearchData::searchElasticByCondition($param);
        
        if(!empty($result))
        {
            $res = self::getProductList($result,$page,$ajax);
            if(!empty($res['popular']))
            {
                $data['popular'] = $res['popular'];
            }
            if(!empty($res['hotWeek']))
            {
                $data['hotWeek'] = $res['hotWeek'];
            }    
        }
        return $data;
    }
    
   

    /**
     * 获取分类标签
     */
    static public function getHotranktag($client_type,$channel,$is_concurrent)
    {
        $list = \LibModels\Web\Product\HotrankData::getHotranktag($client_type,$channel,$is_concurrent);
        $nav = array();
        if(!empty($list['data']['list']))
        {
                foreach($list['data']['list'] as $li=>$lt)
                {
                        $nav[$li]['sid'] = $lt['id'];
                        $nav[$li]['textCn'] = $lt['tag_name'];
                }
        }
        return $nav;
    }

    
     /**
     * 人气单品  一周热卖 数据处理
     */
    static public function getProductList($result,$page,$ajax=0)
    {
        // 调用发起请求
        Yohobuy::yarConcurrentLoop();
 
        if(empty($result) || empty($result['data']) || empty($result['data']['product_list']))
        {
            return;
        }
        $data = $result['data']['product_list'];
        $popular = array();
        $hotWeek = array();
        foreach($data as $key=>$val)
        {
            if(empty($val['goods_list']))
            {
                continue;
            }
            $defaultGoodsId = 0;
            foreach ($val['goods_list'] as $v)
            {
                if($v['is_default'] == 'Y')
                {
                    $defaultGoodsId = $v['goods_id'];
                }
            }
            if(empty($defaultGoodsId))
            {
                $defaultGoodsId = $val['goods_list'][0]['goods_id'];
            }

            $product_id = empty($val['product_id']) ? '' : $val['product_id'];
            $re['name'] = $val['product_name'];
            if($key <= 9 && $page == 1 && $ajax == 0)
            {	
                //人气单品
                $re['rank'] = $key + 1;
                $re['href'] = 'http://item.yohobuy.com/product/pro_'.$product_id.'_'.$defaultGoodsId.'.html';
                $re['price'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : $val['market_price'];
                $re['sPrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];
                if($key <= 5)
                {
                    $re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 378, 504, 2);
                    $popular['list'][] = $re;
                }else{
                    $re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
                    $popular['list'][] = $re;
                }
            }else{
                //一周热卖
                $re['url'] = 'http://item.yohobuy.com/product/pro_'.$product_id.'_'.$defaultGoodsId.'.html';
                $re['marketPrice'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : $val['market_price'];
                $re['salePrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];
                $re['rank'] = '';
                $re['thumb'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
                $hot[] = $re;
            }
        }
        $popular['name'] = '人气单品';
        $hotWeek = array(
                'name'=>'一周热卖',
                'list'=>$hot,	
        );

        return array('popular'=>$popular,'hotWeek'=>$hotWeek);
    }
}