Index.php 2.53 KB
<?php

namespace Product;

use WebPlugin\HelperSearch;
use Product\SearchModel;
use Api\Yohobuy;

/**
 * list Index页模板数据模型
 *
 */
class IndexModel 
{
    const URI_INDEX_TBANNER = '/shops/service/v1/searchbanner';
    
    public static function getIndexData($customCondition, $customOptions) 
    {
        $urlList = array();
        $searchCondition = SearchModel::searchCondition($customCondition, $customOptions);
        // 组合搜索商品url
        $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);
        
        // 组合搜索分类url
        $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['sortCondition']);
        
        //用户浏览记录
        //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
        
        //批量调接口获取数据
        $result = Yohobuy::getMulti($urlList, array(), true);
        
        // 组织模板数据
        $data = HelperSearch::getList($result, $searchCondition['options']);
        
        //调用接口获取list-index banner数据
        $msort = isset($searchCondition['condition']['msort']) ? $searchCondition['condition']['msort'] : false;
        $misort = isset($searchCondition['condition']['misort']) ? $searchCondition['condition']['misort'] : false;
        $positionId = isset($searchCondition['options']['positionId']) ? $searchCondition['options']['positionId'] : '';
        $gender = $searchCondition['condition']['gender'] == '2,3' ? 2 : 1;
        if ($msort && $misort) {
            $bannerData = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_INDEX_TBANNER, 'get', array($positionId,$msort,$misort,$gender,0,0,0,0,0));
            if (isset($bannerData['code']) && $bannerData['code'] == '200') {
                $banner = self::formatBanner($bannerData['data']);
            }
        }
        //插入banner数据
        if (!empty($banner)) {
            $data['sortIntro'] = $banner;
        }
        
        return $data;
    }
    
    //组织list-index banner数据
    public static function formatBanner($bannerData)
    {
        $banner = array();
        $banner['name'] = $bannerData['title'];
        $banner['enName'] = $bannerData['subtitle'];
        $banner['desc'] = $bannerData['intro'];
        $banner['img'] = $bannerData['logo'];
        foreach($bannerData['keyword'] as $key => $vo){
            $banner['keyEntry'][$key]['name'] = $vo['word'];
            $banner['keyEntry'][$key]['url'] = $vo['url'];
        }
        
        return $banner;
    } 
    
}