Brands.php
9.92 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
namespace Product;
use Api\Yohobuy;
use WebPlugin\HelperSearch;
use LibModels\Web\Product\BrandData;
use WebPlugin\Helpers;
use LibModels\Web\Product\SearchData;
use Configs\WebCacheConfig;
use WebPlugin\Cache;
use Index\HomeModel;
/**
* 品牌首页模板数据模型
*
* @author Administrator
*/
class BrandsModel
{
/**
* 搜索品牌数据
* @param $condition array(
* 'brand' => int (品牌id,必传)
* 'folder_id' => string (搜索品牌系列参数)
* )
* @param $options array(
* 'brandName' => string (品牌域名)
'uid' => int (用户uid)
'brandId' => int (品牌id)
'node' => string (左侧广告node)
'brandBanner' => string (品牌banner)
'brandNameEn' => string (品牌英文名)
'brandNameCn' => string (品牌中文名)
'reviewNum' => int (底部浏览记录显示个数)
'controller' => string (说明当前控制器名)
'action' => string (说明当前方法名)
* ) 排序条件
* @return array() (处理后的品牌首页数据)
*/
public static function getBrandSearchData($condition, $options)
{
//获取$condition和$option 筛选条件和排序条件
$searchCondition = SearchModel::searchCondition($condition, $options);
// 并行调用品牌相关接口并封装数据
$result = self::getBrandData($searchCondition, $options);
//获取品牌系列数据
$adNav = self::getAdNav($options['brandId']);
$result['leftContent'][] = array('picLink' => $adNav);
//获取静态内容
if ($options['node']) {
$nodeContent = HelperSearch::getNodeContent($options['node']);
$result['leftContent'][]['picLink']['list'] = $nodeContent;
}
return $result;
}
/**
* 品牌介绍页
* @param $customOptions array(
* 'brandName' => string (品牌域名)
'uid' => int (用户uid)
'brandId' => int (品牌id)
'brandAbout' => string (品牌简介)
'brandBanner' => string (品牌banner)
'brandNameEn' => string (品牌英文名)
'brandNameCn' => string (品牌中文名)
* )
* @return array
*/
public static function getBrandIntro($customOptions = array())
{
$urlList = array();
if (USE_CACHE) {
$key = WebCacheConfig::KEY_WEB_PRODUCT_INDEX_BRANDINTRO;
if (!empty($customOptions['userInput'])) {
$key .= http_build_query($customOptions['userInput'], null, '&');
}
$channel = HomeModel::getSwitchChannel();
//key加上性别参数
$key .= $channel;
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
//组合搜索品牌url
$urlList['brand'] = SearchData::getBrandUrl($customOptions);
//批量调接口
$data = Yohobuy::getMulti($urlList, array(), true);
$result = array();
if (isset($data['brand']) && isset($customOptions['channel'])) {
$banner = HelperSearch::getBannerFormat($data['brand'], $customOptions['brandBanner']);
$channel = $customOptions['channel'];
$brandNav = $customOptions['brandNameEn'] . ' ' . $customOptions['brandNameCn'];
//根据频道判断home页地址
switch ($channel) {
case 'boys':
$home = Helpers::url('', '', 'default');
break;
case 'girls':
$home = Helpers::url('/woman', '', 'new');
break;
case 'lifestyle':
$home = Helpers::url('/lifestyle', '', 'new');
break;
case 'kids':
$home = Helpers::url('/kids', '', 'new');
break;
default:
$home = Helpers::url('', '', 'new');
break;
}
$result = array(
'brandBanner' => $banner,
'brandAbout' => $customOptions['brandAbout'],
'pathNav' => array(
array(
'href' => $home,
'name' => strtoupper($channel) . '首页',
'title' => 'YOHO!有货'
),
array(
'href' => Helpers::url('/brands'),
'name' => '品牌一览',
'title' => '品牌一览'
),
array(
'name' => $brandNav
)
)
);
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result, 1800); // 缓存30分钟
}
}
return $result;
}
/**
* 根据品牌域名处理相关品牌参数
* @param $domain (品牌域名)
* @param $type (根据type调取同一接口不同的数据)
* @return array|bool
*/
public static function getBrandByDomain($domain, $type)
{
//根据传来的type值,选择请求需要的数据
switch ($type) {
case 1:
$fields = 'id,brand_name,brand_name_cn,brand_name_en,brand_domain,brand_alif,brand_banner,brand_ico,static_content_code';
break;
case 2:
$fields = 'id,brand_name,brand_name_cn,brand_name_en,brand_banner,brand_ico,brand_intro';
default:
break;
}
//调用接口获得数据
$brandInfo = BrandData::getBrandLogoByDomain($domain, $fields);
$result = array();
//组装品牌页顶部banner条需要的数据
if (!empty($brandInfo['data']) && $brandInfo['code'] == 200) {
$result['brandId'] = isset($brandInfo['data']['id']) ? $brandInfo['data']['id'] : '';
$result['node'] = isset($brandInfo['data']['static_content_code']) ? $brandInfo['data']['static_content_code'] : false;
$result['brandBanner'] = isset($brandInfo['data']['brand_banner']) ? $brandInfo['data']['brand_banner'] : '';
$result['brandNameEn'] = isset($brandInfo['data']['brand_name_en']) ? $brandInfo['data']['brand_name_en'] : '';
$result['brandNameCn'] = isset($brandInfo['data']['brand_name_cn']) ? $brandInfo['data']['brand_name_cn'] : '';
$result['brandAbout'] = isset($brandInfo['data']['brand_intro']) ? $brandInfo['data']['brand_intro'] : '';
}
else {
return false;
}
return $result;
}
/**
* 获取品牌系列数据
* @param $brandId (品牌id)
* @param int $status (状态码)
* @return array
*/
public static function getAdNav($brandId, $status = 1)
{
//调用接口获得品牌系列数据
$advNav = BrandData::getFolderByBrand($brandId, $status);
$result = array();
if (isset($advNav['data']) && $advNav['code'] === 200) {
foreach ($advNav['data'] as $key => $value) {
$result['list'][$key]['href'] = '?folder_id=' . $value['id'];
$result['list'][$key]['src'] = $value['brand_sort_ico'];
}
//title设置为经典系列
$result['picTitle'] = '经典系列';
}
return $result;
}
/**
* 根据条件获取搜索品牌数据
* @param $searchCondition array() (经过过滤的、用户输入的一些数据)
* @param $customOptions array(
* 'brandName' => string (品牌域名)
* 'uid' => int (用户uid)
* 'brandId' => int (品牌id)
* 'node' => string (左侧广告node)
* 'brandBanner' => string (品牌banner)
* 'brandNameEn' => string (品牌英文名)
* 'brandNameCn' => string (品牌中文名)
* 'reviewNum' => int (底部浏览记录显示个数)
* 'controller' => string (说明当前控制器名)
* 'action' => string (说明当前方法名)
* )
* @return array() (品牌首页数据,不包括系列数据、广告数据、banner数据)
*/
public static function getBrandData($searchCondition = array(), $customOptions = array())
{
// 组合搜索商品url
$urlList['product'] = SearchData::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
$sortCondition = array();
if (isset($searchCondition['condition']['misort']) && !empty($searchCondition['condition']['misort'])) {
$sortCondition['needSmallSort'] = 1;
}
$sortCondition= array(
'attribute_not' => $searchCondition['sortCondition']['attribute_not'],
'brand' => $searchCondition['sortCondition']['brand']
);
$urlList['sort'] = SearchData::getClassesUrl($sortCondition);
//组合搜索品牌url
$urlList['brand'] = SearchData::getBrandUrl($customOptions);
//批量调接口
$data = Yohobuy::getMulti($urlList);
//组织模板数据格式
$result = HelperSearch::getList($data, $searchCondition['options'], $searchCondition['userInput']);
return $result;
}
}