SearchData.php 2.93 KB
<?php
namespace LibModels\Web\Product;

use Api\Yohobuy;
class SearchData extends \LibModels\Wap\Product\SearchData
{
    /**
     * 获取搜索的服务地址
     *
     * 备注:此处是根据环境来确定使用阿里云内网还是外网的URL
     *
     * @return string
     */
    private static function getUrl($type = 'search')
    {
        defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
        switch (APPLICATION_ENV) {
            case 'release':
                if($type == 'sort'){
                    return 'http://100.98.132.63/yohosearch/sortgroup.json';
                }
                if($type == 'discount'){
                    return 'http://100.98.132.63/yohosearch/discount.json';
                }
                if($type == 'recent'){
                    return 'http://100.98.132.63/yohosearch/recent.json';
                }
                return 'http://100.98.132.63/yohosearch/search.json';
            case 'test':
            case 'preview':
            case 'developer':
            default:
                if($type == 'sort'){
                    return 'http://101.200.31.165/yohosearch/sortgroup.json';
                }
                if($type == 'discount'){
                    return 'http://101.200.31.165/yohosearch/discount.json';
                }
                if($type == 'recent'){
                    return 'http://101.200.31.165/yohosearch/recent.json';
                }
                return 'http://101.200.31.165/yohosearch/search.json';
        }
    }
    /**
     * 根据分类列表获取商品信息
     *
     * @param array $params
     * @param array $sortList
     * @return array
     */
    public static function getSearchDataBySort(array $params, array $sortList)
    {
        $data = array();
        foreach ($sortList as $v) {
            if(empty($v['viewNum'])){
                continue;
            }
            $searchParams = array_merge($params, $v);
            $list = self::searchElasticByCondition($searchParams, true);
            $productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list'];
            if(count($productList) < $v['viewNum']){
                continue;
            }
            $data = array_merge($data, $productList);
        }
        return $data;
    }

    /**
     * 获取品类数据
     *
     * @return array 品类数据
     */
    public static function getClassesData($condition = array(), $cache = false)
    {
        $param['brand'] = $condition;
        return Yohobuy::get(self::getUrl('sort'),$param, $cache);
    }

    /**
     * 获取折扣区间
     */
    public static function getDiscount(){
        return Yohobuy::get(self::getUrl('discount'));
    }

    /**
     * 获取最新上架
     */
    public static function recentShelve(){
        return Yohobuy::get(self::getUrl('recent'));
    }
}