Plusstar.php
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?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
{
const URL_GUANG_ARTICLE = '/guang/service/v1/article';
/**
* 获取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, 3600);
}
}
return $articles;
}
}
?>