List.php
17.9 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
<?php
namespace Product;
use Configs\CacheConfig;
use LibModels\Wap\Category\ClassData;
use LibModels\Wap\Category\BrandData;
use LibModels\Wap\Product\ListData;
use LibModels\Wap\Product\ShopData;
use Plugin\DataProcess\ListProcess;
use Plugin\DataProcess\ShopProcess;
use Plugin\Helpers;
use Plugin\Cache;
use Plugin\Images;
use Plugin\Encryption;
/**
* 商品列表相关的模板数据模型
*
* @name ListModel
* @package models/Product
* @copyright yoho.inc
* @version 1.0 (2015-10-27 16:27:54)
* @author fei.hong <fei.hong@yoho.cn>
*/
class ListModel
{
/**
* 获取品类商品列表数据
*
* @param array $condition 条件
* @return array | false
*
* tar mark
*/
public static function getClassData($condition)
{
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_PRODUCT_INDEX;
if (!empty($condition)) {
$key .= http_build_query($condition, null, '&');
}
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
// 调用接口查询数据
$listData = ClassData::filterClassData($condition);
// 处理返回的数据
if (isset($listData['code']) && $listData['code'] === 200) {
$result = ListProcess::getListData($listData['data'], false);
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
} // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result, 300); // 缓存5分钟
}
}
return $result;
}
/**
* 获取品牌信息
*
* @param int $id 唯一的ID
* @param int $uid 用户ID
* @param string $title 网站标题
* @return array
*/
public static function getBrandIntro($id, $uid, &$title)
{
$result = array();
// 获取品牌介绍信息, 有缓存1小时
$introData = BrandData::getBrandIntro($id, $uid);
if (isset($introData['data']['brand_intro'])) {
$result['id'] = $id;
$result['intro'] = $introData['data']['brand_intro'];
$result['collected'] = (isset($introData['data']['is_favorite']) && $introData['data']['is_favorite'] == 'Y') ? true : false;
// 顶部导航的标题
$title = isset($introData['data']['brand_name']) ? $introData['data']['brand_name'] : '';
}
// 获取品牌banner的数据, 有缓存1小时
$bannerData = BrandData::getBrandBanner($id);
if (isset($bannerData['data']['banner'])) {
$result['banner'] = Helpers::getImageUrl($bannerData['data']['banner'], 640, 150);
}
return $result;
}
/**
* 获取品牌商品列表数据
*
* @param array $condition 条件参数
* @param string $title 网站标题
* @return array
*/
public static function getBrandData($condition, &$title)
{
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_PRODUCT_BRAND;
if (!empty($condition)) {
$key .= http_build_query($condition, null, '&');
}
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
// 调用接口查询数据
$listData = BrandData::filterBrandData($condition);
// 处理返回的数据
if (isset($listData['code']) && $listData['code'] === 200) {
$result = ListProcess::getListData($listData['data'], false);
if (!empty($listData['data']['brand'])) {
$result['brandWay'] = array(
'url' => 'http://' . $listData['data']['brand']['brand_domain'] . SUB_DOMAIN,
'thumb' => Helpers::getImageUrl($listData['data']['brand']['brand_ico'], 75, 40),
'name' => $listData['data']['brand']['brand_name']
);
$title = $listData['data']['brand']['brand_name'];
}
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
} // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result, 300); // 缓存5分钟
}
}
return $result;
}
/**
* 根据品牌ID获取品牌LOGO
*
* @param int $id 品牌ID
* @param string $title 品牌标题
* @return array | false
*/
public static function getBrandLogoByIds($id, &$title)
{
$result = false;
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_LOGO . strval($id);
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
// 调用接口查询数据
$brandLogo = BrandData::getBrandLogo($id);
// 处理返回的数据
if (isset($brandLogo['data'][0])) {
$result = array(
'url' => Helpers::url('', null, $brandLogo['data'][0]['brand_domain']),
'thumb' => Helpers::getImageUrl($brandLogo['data'][0]['brand_ico'], 75, 40),
'name' => $brandLogo['data'][0]['brand_name'],
);
$title = $result['name'];
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
} // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result); // 缓存1小时
}
}
return $result;
}
/**
* 根据品牌ID获取品牌LOGO
*
* @param int $id 品牌ID
* @param string $title 品牌标题
* @modify sefon 2016-4-29 01:57:14 添加shopId / type
* @return array | false
*/
public static function getBrandLogoByDomain($domain, &$title)
{
$result = false;
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_LOGO_DOMAIN . strval($domain);
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
// 调用接口查询数据
// $brandLogo = BrandData::getBrandLogoByDomain($domain);
$brandLogo = BrandData::getShopInfoByBrandDomain($domain);
// 处理返回的数据
if (isset($brandLogo['data'])) {
$result = array(
'id' => $brandLogo['data']['id'],
'url' => Helpers::url('', null, $brandLogo['data']['brand_domain']),
'thumb' => Helpers::getImageUrl($brandLogo['data']['brand_ico'], 75, 40),
'name' => $brandLogo['data']['brand_name'],
'shopId' => isset($brandLogo['data']['shop_id']) ? $brandLogo['data']['shop_id'] : 0,//店铺id
'type' => isset($brandLogo['data']['type']) ? $brandLogo['data']['type'] : 0,
);
$title = $result['name'];
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
} // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result); // 缓存1小时
}
}
return $result;
}
/**
* 获取所有的品牌名称列表
*
* @return array(
* 品牌ID => 品牌域名(domain)
* )
*/
public static function getAllBrandDomains()
{
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_DOMAINS;
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
$brand = BrandData::getBrandsData(null);
/* 按字母'A-Z'分组的品牌列表 */
if (!empty($brand['data']['brands'])) {
foreach ($brand['data']['brands'] as $value) {
foreach ($value as $row) {
$result[$row['id']] = $row['brand_domain'];
}
}
}
// 更多关联的品牌
if (!empty($brand['data']['morebrands'])) {
foreach ($brand['data']['morebrands'] as $row) {
$result[$row['id']] = $row['brand_domain'];
}
}
$brand = array();
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
} // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result);
}
}
return $result;
}
/**
* 获取所有的品牌名称列表
*
* @return array(
* 品牌域名(domain) => 品牌名称(name)
* )
*/
public static function getAllBrandNames()
{
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_NAMES;
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
$brand = BrandData::getBrandsData(null);
/* 按字母'A-Z'分组的品牌列表 */
if (!empty($brand['data']['brands'])) {
foreach ($brand['data']['brands'] as $value) {
foreach ($value as $row) {
$result[$row['brand_domain']] = strtolower($row['brand_name']);
}
}
}
// 更多关联的品牌
if (!empty($brand['data']['morebrands'])) {
foreach ($brand['data']['morebrands'] as $row) {
$result[$row['brand_domain']] = strtolower($row['brand_name']);
}
}
$brand = array();
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
} // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result);
}
}
return $result;
}
/**
* @param $data
* @param $shop_id
* @return array 返回的处理好的数据
* @author chengyao.guo
*/
public static function categoryData($data, $shop_id)
{
$result = array(
'allproduct' => Helpers::url('/search/list', array(
'shop_id' => $shop_id,
)),
'class' => array(),
'category' => array()
);
if (empty($data)) {
return $result;
}
foreach ($data as $categorys) {
if (empty($categorys['sub'])) {
continue;
}
array_push($result['class'], array('name' => $categorys['category_name']));
//判断是否有全部
$subcategory = array();
$item = array(
'category_name' => '全部' . $categorys['category_name'],
'url' => Helpers::url('/search/list', array(
'shop_id' => $shop_id,
'sort' => $categorys['relation_parameter']['sort'],
'title' => '全部' . $categorys['category_name']
)),
);
array_push($subcategory, $item);
foreach ($categorys['sub'] as &$sub) {
$sub['url'] = Helpers::url('/search/list', array(
'shop_id' => $shop_id,
'sort' => $sub['relation_parameter']['sort'],
'title' => $sub['category_name']
));
array_push($subcategory, $sub);
}
$result['category'][]['subcategory'] = $subcategory;
}
return $result;
}
public static function introData(&$data)
{
$imgArray = explode("?", $data['shop_logo']);
$data['shop_logo'] = str_replace('http:', '', $imgArray[0]) . '?imageMogr2/thumbnail/400x172/extent/400x172/background/d2hpdGU=/position/center';
return $data;
}
/**
* 店铺所有品牌信息处理
* @author chengyao.guo
* @param $data
* @param $shop_id
* @return mixed
*/
public static function brandData($data, $shop_id)
{
// 处理图片链接
foreach ($data as &$item) {
$item['brand_ico'] = Images::getImageUrl($item['brand_ico'], 0, 0);
$item['url'] = Helpers::url('/search/list', array(
'shop' => $shop_id,
'brand' => $item['brand_id'],
'title' => $item['brand_name'],
));
}
return $data;
}
/**
* 新店铺首页
* @param int $shopId 店铺id
* @param int $uid 用户id
* @param string $appVersion app版本
* @author sefon 2016-4-26 21:09:35
* @return array
*/
public static function shopData($shopId, $uid, $appVersion = '')
{
$data = array();
/* tar modified 160901 店铺信息和店铺资源位接口合并 */
$data = ListData::getShopDecoratorAndInfo($shopId, $uid);
//店铺使用基础模板,返回品牌页面
if (isset($data['shopInfo']['shop_template_type']) && $data['shopInfo']['shop_template_type'] == 1) {
return array('goBrand' => $data['shopInfo']);
}
//店铺分类
$channel = empty($_GET['yh_channel']) ? Helpers::getChannelByCookie() : $_GET['yh_channel'];
$data['shopCategory'] = ListData::getShopCategory($shopId, $channel);
//组织楼层数据
$result = ShopProcess::formShopData($data, $shopId, $appVersion, $channel); // tar add 160826 add $channel
return $result;
}
/**
* 根据brandId 获取相关店铺列表
* @param int $brandId
* @author sefon 2016-4-28 13:38:23
* @return array
*/
public static function getBrandShops($brandId)
{
$result = array();
$brandShop = ShopData::getShopByBrandId($brandId);
if (isset($brandShop['code']) && $brandShop['code'] && !empty($brandShop['data'])) {
foreach ($brandShop['data'] as $key => $val) {
if (!isset($val['shop_id'])) {
continue;
}
$result[$key]['url'] = Helpers::url('/product/index/brand/', array('shop_id'=>$val['shop_id']));
$result[$key]['thumb'] = $val['brand_ico'];
$result[$key]['name'] = $val['brand_name'];
}
}
return $result;
}
/**
* 根据brand domain查询店铺信息
* @param string $domain
* @author sefon 2016-4-28 23:39:04
* @return array
*/
public static function getShopInfo($domain)
{
return ShopData::getShopInfoByBrandDomain($domain);
}
/**
* 通过店铺 ID 获取店铺信息
* @param $shopId
* @param $uid
* @return array
*/
public static function getShopInfoById($shopId, $uid)
{
return ListData::getShopInfo($shopId, $uid);
}
/**
* 获取店铺基础模板banner
* @return string
*/
public static function getShopBaseBanner($shopId)
{
$decorator = ListData::getShopDecorator($shopId);
if (isset($decorator['code']) && $decorator['code'] === 200 && isset($decorator['data']['list']) && !empty($decorator['data']['list'])) {
foreach ($decorator['data']['list'] as $val) {
if ($val['resource_name'] == 'shopTopBanner_base') {
$banner = json_decode($val['resource_data'], true);
return $banner[0]['shopSrc'] . '?imageMogr2/auto-orient/strip/thumbnail/x150/crop/640x150';
}
}
}
}
public static function getShopCouponsList($shopId, $uid)
{
$shopCoupons = array();
$result = ListData::shopCouponsList($shopId, $uid);
if ($result['code'] !== 200) {
return $shopCoupons;
}
foreach ($result['data'] as $key => $value) {
$value['status'] = $value['status'] * 1;
if ($value['status'] === 1 || $value['status'] === 3) {
$shopCoupons[] = array(
'validity' => $value['couponValidity'],
'id' => Encryption::encrypt($value['coupon_id']),
'name' => $value['coupon_name'],
'pic' => $value['coupon_pic'],
'money' => intval($value['money']),
'status' => $value['status'] === 1
);
}
}
return $shopCoupons;
}
}