Brands.php
12.4 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<?php
namespace Product;
use Api\Yohobuy;
use WebPlugin\HelperSearch;
use LibModels\Web\Product\BrandData;
use Index\HomeModel;
use Product\SearchModel;
use WebPlugin\Helpers;
use Plugin\Images;
use LibModels\Web\Product\SearchData;
use LibModels\Web\Home\IndexData;
/**
* 品牌首页模板数据模型
*
* @author Administrator
*/
class BrandsModel
{
//品牌一览资源位CODE码
const BOYS_BRAND_CODE = '8b16b7baf9a66fbe553a6caa97d2ce2a';
const GIRLS_BRAND_CODE = 'c95ae9e40f0add10549b819f821ad626';
const KIDS_BRAND_CODE = '84b7926282fdef92f1039bdcf77c18ba';
const LIFESTYLE_BRAND_CODE = 'c575c6bfdfa4125fae7d24bbec7119c8';
const BRAND_LIST_CODE = 'f0f72b1e8f30e6ad086dfc4401f3a856';//品牌列表资源位CODE码
const URL_PRODUCT_BRAND = '/cmsproduct/service/v1/brands';
/**
* 搜索品牌数据
* @param $condition array 搜索数据的条件
* @param $options array
* @return array
*/
public static function getBrandSearchData($condition, $options)
{
// 并行调用品牌相关接口并封装数据
$data = self::getBrandData($condition, $options);
//获取品牌系列数据
$adNav = self::getAdNav($options['brandId']);
$data['leftContent'][] = array('picLink' => $adNav);
//获取静态内容
if ($options['node']) {
$nodeContent = HelperSearch::getNodeContent($options['node']);
$data['leftContent'][]['picLink']['list'] = $nodeContent;
}
return $data;
}
/**
* 品牌介绍页
* @param array $customCondition
* @param array $customOptions
* @return array
*/
public static function getBrandIntro($customCondition = array(), $customOptions = array())
{
$urlList = array();
//组合搜索品牌url
$urlList['brand'] = SearchData::getBrandUrl($customOptions);
//批量调接口
$result = Yohobuy::getMulti($urlList, array(), true);
if (isset($result['brand'])) {
$banner = HelperSearch::getBannerFormat($result['brand'], $customOptions['brandBanner']);
}
return array(
'brandBanner' => $banner,
'brandAbout' => $customOptions['brandAbout']
);
}
//根据品牌域名处理相关品牌参数
public static function getBrandByDomain($domain, $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_banner,brand_ico,brand_intro';
default:
break;
}
$brandInfo = BrandData::getBrandLogoByDomain($domain, $fields);
$result = array();
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;
}
//获取品牌系列数据
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'];
}
$result['picTitle'] = '经典系列';
}
return $result;
}
/**
* 根据条件获取搜索数据
* @param array $customCondition
* @param array $customOptions
* @return array
*/
public static function getBrandData($customCondition = array(), $customOptions = array())
{
$urlList = array();
//获取$condition和$option 筛选条件和排序条件
$searchCondition = SearchModel::searchCondition($customCondition, $customOptions);
// 组合搜索商品url
$urlList['product'] = SearchData::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
$urlList['sort'] = SearchData::getClassesUrl($searchCondition['sortCondition']);
//组合搜索品牌url
$urlList['brand'] = SearchData::getBrandUrl($customOptions);
//批量调接口
$result = Yohobuy::getMulti($urlList);
//组织模板数据格式
$data = HelperSearch::getList($result, $searchCondition['options']);
return $data;
}
/*
* 获取品牌一览页面,品牌top & 列表
*/
public static function getBrandView($channel)
{
//获取参数
$switchParams = self::switchBrandParams($channel);
//取接口数据
$brandTop = array();
$brandAds = array();
$brandList = array();
$res = BrandData::getTopBanner($switchParams['brandCode'], $switchParams['channelType']);
//头部10个品牌图块 url todo
if (isset($res['brandTop'][1]['data']['list']) && $res['brandTop'][1]['data']['list']) {
foreach ($res['brandTop'][1]['data']['list'] as $tbk => $tbv) {
$topBrandTmp = array(
'name' => $tbv['name'],
'src' => Helpers::getImageUrl($tbv['src'], 80, 50, 3),
'url' => $tbv['url'],
);
$brandAds[$tbk] = $topBrandTmp;
}
}
//头部品牌图块
if (isset($res['brandTop'][0]['data']) && $res['brandTop'][0]['data']) {
foreach ($res['brandTop'][0]['data'] as $tk => $tv) {
$topTmp = array(
'name' => $tv['title'],
'src' => Helpers::getImageUrl($tv['src'], 222, 180, 3),
'url' => $tv['url'],
'items' => $brandAds
);
$brandTop[$tk] = $topTmp;
}
}
//品牌list A-Z 0-9
if (isset($res['brandList']['brands']) && $res['brandList']['brands']) {
foreach ($res['brandList']['brands'] as $lk => $lv) {
$listTmp = array();
if (isset($lv) && $lv) {
foreach ($lv as $ltk => $ltv) {
$listTmp[$ltk] = array(
'name' => $ltv['brand_name'],
'key' => $ltv['id']
);
if ($ltv['is_hot'] == 'Y') {
$listTmp[$ltk] += array('hot' => 'hot');
}
}
}
$brandList[$lk] = $listTmp;
}
//将brandList里的0-9 排序到最后
$numBrand['0~9'] = $brandList['0~9'];
unset($brandList['0~9']);
$brandList+=$numBrand;
}
return array(
'brandTop' => $brandTop,
'brandList' => $brandList
);
}
/*
* 获取单个广告浮窗内容
*/
public static function getBrandInfo($brandId, $uid)
{
$data = array();
$imgs = array();
//获取品牌简介
$res = BrandData::getBrandIntro($brandId, $uid);
if (isset($res['data']) && $res['data']) {
//获取品牌下的产品信息
$proInfo = self::getProductByBrand($brandId);
$proInfoTmp = $proInfo['data']['product_list'];
if (isset($proInfoTmp) && $proInfoTmp) {
foreach ($proInfoTmp as $v) {
$imgs[] = array(
'src' => Images::getImageUrl($v['default_images'], 80, 100, 3, 'goodsimg')
);
}
}
//整合
$data = array(
'key' => $res['data']['brand_id'],
'icon' => Helpers::getImageUrl($res['data']['brand_ico'], 80, 50, 3),
'title' => $res['data']['brand_name'],
'content' => $res['data']['brand_intro'],
'subtitle' => 'FEATURED ITEMS',
'imgs' => $imgs
);
}
return $data;
}
/*
* 根据brandId获取产品信息
*/
public static function getProductByBrand($brandId, $num = 3)
{
$condition['viewNum'] = $num;
$condition['brand'] = $brandId;
return searchData::searchElasticByCondition($condition);
}
/*
* 获取品牌一览资源位&channelType
*/
public static function switchBrandParams($channelStr = 'boys')
{
$res = array('channelType' => 1, 'brandCode' => self::BOYS_BRAND_CODE);
switch ($channelStr) {
case HomeModel::COOKIE_NAME_BOYS:
$res['channelType'] = 1;
$res['brandCode'] = self::BOYS_BRAND_CODE;
break;
case HomeModel::COOKIE_NAME_GIRLS:
$res['channelType'] = 2;
$res['brandCode'] = self::GIRLS_BRAND_CODE;
break;
case HomeModel::COOKIE_NAME_KIDS:
$res['channelType'] = 3;
$res['brandCode'] = self::KIDS_BRAND_CODE;
break;
case HomeModel::COOKIE_NAME_LIFESTYLE:
$res['channelType'] = 4;
$res['brandCode'] = self::LIFESTYLE_BRAND_CODE;
break;
default:
$res['channelType'] = 1;
$res['brandCode'] = self::BOYS_BRAND_CODE;
break;
}
return $res;
}
/**
* 多个品牌ID获取品牌信息
*
* @param array $brands
* @return array
*/
public static function getBrandInfoByIds(array $brandIds)
{
$brandsInfo = array();
foreach($brandIds as $brandId)
{
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URL_PRODUCT_BRAND, 'getOneBrand',
array($brandId, 'id,brand_name,brand_intro,brand_domain'),
function($data)use(&$brandsInfo) {
if(isset($data['data']['id'])) {
$brandsInfo[$data['data']['id']] = $data['data'];
}
});
}
Yohobuy::yarConcurrentLoop();
return $brandsInfo;
}
/**
* 获取品牌列表项目
*
* @return array
*/
public static function getBrandListItem()
{
$items = array(
0 => array('name'=>'所有品牌','src'=>'','url'=>'http://www.yohobuy.com/brands','brandType'=> '','isRecommend'=>''),
1 => array('name'=>'设计师品牌','src'=>'','url'=>'','brandType' => 1,'isRecommend' => 0),
2 => array('name'=>'街头品牌','src'=>'','url'=>'','brandType' => 1,'isRecommend' => 1),
3 => array('name'=>'明星品牌','src'=>'','url'=>'','brandType'=> 2, 'isRecommend'=> 0),
4 => array('name'=>'个人原创','src'=>'','url'=>'','brandType'=> 3, 'isRecommend'=> 0),
);
// $resource = IndexData::getResourceData(self::BRAND_LIST_CODE, 'web');
$pos = 0;
foreach($items as $id => &$val) {
if(empty($val['url'])) {
$val['url'] = '/brands/list?id='.$id;
}
if(isset($resource[0]['data'][$pos])) {
// $val['src'] = Images::getImageUrl($resource[0]['data'][$pos]['src'], 222, 180, 1);
}
$pos++;
}
return $items;
}
}