Plusstar.php 2.89 KB
<?php
namespace Guang;
use LibModels\Web\Guang\PlusstarData;
use WebPlugin\Images;
use WebPlugin\Cache;
use Configs\WebCacheConfig;
use WebPlugin\Helpers;
use LibModels\Web\Guang\ListData;
class PlusstarModel
{
    /**
     * 获取Plustar列表
     * 
     * @param string $brandType
     * @param string $gender
     * @return array
     */
    public static function getPlustarList($brandType, $gender)
    {
        $key = WebCacheConfig::KEY_WEB_GUANG_PLUSSTAR_DATA.'_'.$brandType.'_'.$gender;
        $data = Cache::get($key);
        if(empty($data)) {
            $list = PlusstarData::getList($brandType, $gender);
            $brandList = $brandIds = array();
            if(isset($list['data']['data']['list'])) {
                $brandList = current($list['data']['data']['list']);
            }
            if(isset($brandList['data'])) {
                foreach ($brandList['data'] as $brand) {
                    $pos = 0;
                    if(isset($brand['data'][0])) {
                        $src = Images::getImageUrl($brand['data'][0]['src'], 320, 160, 1);
                    }
                    $brandIds[] = $brand['brand_id'];
                    $data[$brand['brand_id']] = array(
                        'brand_id' => $brand['brand_id'],
                        'name'=> $brand['brand_name'],
                        'sort_id' => $brand['sort_id'],
                        'src' => $src,
                        'desc' => '',
                        'url'=> '',
                    );
                }
            }
            Cache::set($key, $data, 600);
        }
        return $data;
    }
    
    /**
     * 根据sortId获取新闻
     *
     * @param int $sortId
     * @param string $gender
     * @param int $page
     * @param int $limit
     */
    public static function getArticleBySortId($sortId, $gender, $page = 1, $limit = 10)
    {
        $key = sprintf("%s_%s_%s_%s",  $sortId, $gender, $page, $limit);
        $articles = Cache::get($key);
        if(empty($articles)) {
            if(empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
                $udid = md5($_SERVER['REMOTE_ADDR']);
            }else{
                $udid = md5($_SERVER['HTTP_X_FORWARDED_FOR']);
            }
            $news = ListData::article($gender,$sortId, 0,  $udid, $page, '', '', $limit);
            $news = $news['data'];
            if(isset($news['list'])) {
                foreach($news['list']['artList'] as $key1 => $article) {
                    $articles[$key1] = array(
                        'name'=> $article['title'],
                        'desc'=> $article['intro'],'href'=> Helpers::getFilterUrl($article['url']),
                    );
                }
            }
            if(!empty($articles)) {
                Cache::set($key, $articles, 1800);
            }
        }
        return $articles;
    }
}
?>