Common.php
3.72 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
use Action\WebAction;
use Index\HomeModel;
use LibModels\Web\Home\IndexData;
use Plugin\Cache;
use Configs\CacheConfig;
use Api\Yohobuy;
use Plugin\Images;
class CommonController extends WebAction
{
/**
* 获取首页资源品牌
*/
public function getIndexResourceBrandAction()
{
// 首页资源品牌,采用内存存储
$type = $this->get('type');
$data = array();
if (! empty($type)) {
$key = CacheConfig::KEY_INDEX_BRANDS_LIST_DATA . '_' . $type;
// array('logoBrand'=>'','moreBrand'=>'')
$data = Cache::get($key);
}
echo $this->echoJson($data);
}
/**
* 新品上架 接口数据
*
* @param string channel 当前频道
* @param int pageIndex 当前页数
* @param int pageCount 一页显示个数
*/
public function getNewArrivalAction()
{
$result = $data = array();
do {
/* 判断是不是AJAX请求 */
if (! $this->isAjax()) {
break;
}
$channels = array(
HomeModel::COOKIE_NAME_BOYS,
HomeModel::COOKIE_NAME_GIRLS,
HomeModel::COOKIE_NAME_KIDS,
HomeModel::COOKIE_NAME_LIFESTYLE
);
$channel = $this->post('type', '');
$pageIndex = intval($this->post('pageIndex', 0));
$pageCount = intval($this->post('pageCount', 8));
if (! in_array($channel, $channels)) {
break;
} else {
$data = HomeModel::getNewArrival($channel);
}
if($pageIndex < 0) {
$pageIndex = 0;
}
if($pageCount < 0 || $pageCount > 50) {
$pageCount = 20;
}
$result = array_slice($data, $pageIndex, $pageCount);
if (empty($result)) {
break;
}
$result = array(
'code' => 200,
'goods' => $result
);
} while (false);
$this->echoJson($result);
}
/**
* 获取资源位banner
*
* @return jsonp
*/
public function getbannerAction()
{
$url = 'http://service.api.yohobuy.com/operations/api/v4/resource/get?';
$content_code = $this->get('content_code', '');
$client_type = $this->get('client_type', 'web');
$callback = $this->get('callback', '');
$width = $this->get('width', '');
$height = $this->get('height', '');
$params = array(
'content_code' => $content_code,
'client_type' => $client_type
);
$data = IndexData::getResourceData($content_code);//Yohobuy::get($url.http_build_query($params));
if(empty($data['data']))
{
return $this->helpJsonCallbackResult($callback, 200, '没有数据', '');
}
else
{
$banner = '';
if(isset($data['data'][0]['data']))
{
$banner = current($data['data'][0]['data']);
if(!empty($banner)) {
if(empty($width) || empty($height) ) {
$width = 2600;//通栏广告
$height = 60;
}
$banner['src'] = Images::getImageUrl($banner['src'], $width, $height ,2);
//str_replace('?imageView/{mode}/w/{width}/h/{height}', '', $banner['src']);
}
}
}
return $this->helpJsonCallbackResult($callback, $data['code'], $data['message'], $banner);
}
}