Index.php
18.5 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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
<?php
use Action\WebAction;
use LibModels\Web\Product\FavoriteData;
use Product\BrandsModel;
use Product\HotrankModel;
use Index\HomeModel;
use WebPlugin\Helpers;
use LibModels\Web\Product\BrandData;
use Product\ShopModel;
class IndexController extends WebAction
{
private $_information = array('code' => 400, 'message' => '操作失败,请稍后再试!');
/**
* 品牌首页
*/
public function brandAction()
{
//品牌域名,没有获取到品牌域名的跳转首页
$domain = $this->param('named');
if (empty($domain)) {
$this->go(SITE_MAIN);
}
//根据品牌域名获取品牌id(同时判断品牌域名是否有效),无效跳转首页
$result = BrandsModel::getBrandByDomain($domain);
if (!$result) {
$this->go(SITE_MAIN);
}
//获取uid
$uid = $this->getUid();
// 1 该品牌在多个店铺存在,2 该品牌只有一个店铺
$type = intval(isset($result['type']) ? $result['type'] : '');
switch ($type) {
case 1:
$shopId = intval($this->get('shopId', 0));
if (empty($shopId)) {
//无单品店有多品店:1--->搜索页
$this->go('//search.yohobuy.com/?query=' . $domain);
} else {
$shopIntro = ShopModel::getIntro($shopId, $uid);
//$shopTemplateType 1基础模板,2经典模板,
if (!empty($shopIntro['shopTemplateType']) && $shopIntro['shopTemplateType'] === 1) {
//基础模板多个品牌
$result['shopTemplateType'] = $shopIntro['shopTemplateType'];
$result['multBrandShopType'] = $shopIntro['multBrandShopType'];
$result['shopId'] = $shopIntro['shopId'];
$result['brandNameEn'] = '';
$result['brandNameCn'] = $shopIntro['brandName'];
break;
}
$this->shopHome($shopId);
}
exit(0);
break;
case 2:
//店铺页面
//$shopTemplateType 1基础模板,2经典模板,
if ($result['shopTemplateType'] === 2 && !empty($result['shopId'])) {
$this->shopHome($result['shopId']);
exit(0);
}
break;
default:
break;
}
// 判断是否是基础模板
$isBasicTpl = !empty($result['shopTemplateType']) && $result['shopTemplateType'] === 1 && !empty($result['shopId']);
//基础模板
if ($isBasicTpl) {
$basisData = ShopModel::basisTemplate($result['shopId']);
$result['shopBanner'] = empty($basisData['shopTopBanner_base']['banner']) ?
$result['brandBanner'] : $basisData['shopTopBanner_base']['banner'] . '?';
$result['signboard'] = $basisData['signboard'];
if (isset($result['node'])) {
unset($result['node']);
}
}
//传品牌ID参数
$condition = array();
if (!empty($result['multBrandShopType']) && !empty($result['shopId']) && $result['multBrandShopType'] === 2) {
//多品牌按shop搜索
$condition['shop'] = $result['shopId'];
} else {
$condition['brand'] = isset($result['brandId']) ? $result['brandId'] : '';
}
$order = $this->get('order');
if (empty($order)) {
$condition['order'] = 'brand_desc';
}
//品牌系列参数
$condition['folder_id'] = $this->get('folder_id');
// 品牌型类
$condition['series_id'] = $this->get('series');
//$options参数数组
$options = array();
$options['brandName'] = $domain;//品牌域名
$options['uid'] = $uid;
$options['brandId'] = isset($result['brandId']) ? $result['brandId'] : '';
$options['node'] = isset($result['node']) ? $result['node'] : '';//左侧广告node
$options['brandBanner'] = isset($result['brandBanner']) ? $result['brandBanner'] : '';//品牌banner
$options['brandNameEn'] = isset($result['brandNameEn']) ? $result['brandNameEn'] : '';//品牌英文名
$options['brandNameCn'] = isset($result['brandNameCn']) ? $result['brandNameCn'] : '';//品牌中文名
$options['reviewNum'] = 6;//底部浏览记录显示个数
$options['controller'] = 'Index';//说明当前控制器名
$options['action'] = 'brand';//说明当前方法名
//调用模型获得品牌页数据
$data = BrandsModel::getBrandSearchData($condition, $options);
/* 为使用基础模板的店铺添加 banner */
if ($isBasicTpl) {
if (isset($result['shopBanner']) && !empty($result['shopBanner'])) {
$shopIntro = ShopModel::getIntro($result['shopId'], $uid);
$data['shopBanner'] = array(
'banner' => $result['shopBanner'],
'shopHome' => Helpers::url('', array('shopId' => $result['shopId']), $domain),
'shopIntro' => Helpers::url('/aboutShop', array('shopId' => $result['shopId'])),
'coled' => $shopIntro['isFavorite'],
'shopId' => $result['shopId']
);
$data['brandBanner'] = array(); // 刪除品牌banner
}
}
$data['signboard'] = isset($result['signboard']) ? $result['signboard'] : '';//水牌
//统计前三个商品
$skn = array();
$arr = array();
if (isset($data['goods']) && !empty($data['goods'])) {
$arr = array_slice($data['goods'], 0, 3);
foreach ($arr as $key => $value) {
$skn[] = $value['skn'];
}
$arr = array('skn' => $skn);
} else {
$arr = array('skn' => array());
}
/* if (!empty($result['multBrandShopType']) && !empty($result['shopId']) && $result['multBrandShopType'] === 2) {
//多品牌无banner
$data['brandBanner'] = array();
}*/
$seo = $data['seo'];
$data = array(
//初始化js
'brandPage' => true,
'list' => $data,
'criteo' => $arr
);
$this->setBrandSeo($seo);
$this->setWebNavHeader();
//渲染模板
$this->_view->display('list', $data);
}
/**
* 异步请求水牌数据
*/
public function getNodeContentAction()
{
if (!$this->isAjax()) {
return '';
}
$node = $this->post('node');
if (!isset($node)) {
return '';
}
$nodeContent = BrandData::getByNodeContent($node);
if (isset($nodeContent['code']) && $nodeContent['code'] == 200) {
echo '<br>', Helpers::getUrlSafe($nodeContent['data']);
}
}
/**
* 异步请求品牌系列
*/
public function getAdnavAction()
{
if (!$this->isAjax()) {
return array();
}
$brandId = $this->post('brandId');
//$status = $this->post('status');
if (!isset($brandId)) {
return array('code' => 201, 'brandId is null');
}
$result = BrandsModel::getAdNav($brandId);
$this->echoJson($result);
}
/**
* 品牌介绍页
*/
public function aboutAction()
{
//品牌域名
$domain = $this->param('named');
if (empty($domain)) {
$this->go(SITE_MAIN);
}
$uid = $this->getUid();
//根据品牌域名获取品牌id(同时判断品牌域名是否有效),无效跳转首页
$result = BrandsModel::getBrandByDomain($domain);
if (!$result) {
$this->go(SITE_MAIN);
}
//$options参数数组
$options = array();
$options['brandName'] = $domain;//品牌域名
$options['uid'] = $uid;
$options['brandId'] = isset($result['brandId']) ? $result['brandId'] : '';//品牌id
$options['brandBanner'] = isset($result['brandBanner']) ? $result['brandBanner'] : '';//品牌banner
$options['brandAbout'] = isset($result['brandAbout']) ? $result['brandAbout'] : '';//品牌介绍数据
$options['channel'] = HomeModel::getSwitchChannel();//获取当前频道
$options['brandNameEn'] = isset($result['brandNameEn']) ? $result['brandNameEn'] : '';//品牌英文名
$options['brandNameCn'] = isset($result['brandNameCn']) ? $result['brandNameCn'] : '';//品牌中文名
//调用模型获得数据
$data = BrandsModel::getBrandIntro($options);
$data = array(
//初始化js
'searchListPage' => true,
'list' => $data
);
$this->setTitle($options['brandNameCn'] . $options['brandNameEn'], true, '|');
$this->setWebNavHeader();
//渲染模板
$this->_view->display('list', $data);
}
/**
* 店铺介绍
*/
public function aboutShopAction()
{
$shopId = $this->get('shopId');
$domain = $this->param('named');
$uid = $this->getUid();
$shopIntro = ShopModel::getIntro($shopId, $uid);
$data = array(
//初始化js
'searchListPage' => true,
);
if (!empty($shopId)) {
$basisData = ShopModel::basisTemplate($shopId);
if (!empty($basisData)) {
$data['list'] = array(
'shopBanner' => array(
'banner' => $basisData['shopTopBanner_base']['banner'], // 2600x150
'shopHome' => Helpers::url('/', array('shopId' => $shopId), $domain),
'shopIntro' => Helpers::url('/aboutShop', array('shopId' => $shopId)),
'coled' => $shopIntro['isFavorite'],
'shopId' => $shopId
),
'shopAbout' => empty($shopIntro['brandCont']) ? $shopIntro['brandName']: $shopIntro['brandCont']
);
} else {
return array('code' => 201, 'no data get from api or data error');
}
} else {
return array('code' => 201, 'no shop id');
}
$this->setWebNavHeader();
$this->setTitle($shopIntro['brandName'] . $shopIntro['domain'], true, '|');
$this->_view->display('list', $data);
}
/**
* 收藏品牌ajax请求
*/
public function favoriteBrandAction()
{
if (!$this->isAjax()) {
return;
}
$result = array(
'code' => 400,
'message' => '操作失败'
);
$uid = $this->getUid();
$brandId = $this->post('brandId');
do {
if (!$uid) {
$result = array(
'code' => 403,
'message' => '用户ID不存在',
'data' => array('url' => Helpers::url('/signin.html', array())),
);
break;
}
if ($uid && $brandId) {
//调用接口收藏或取消收藏
$result = FavoriteData::changeFavoriteBrand($uid, $brandId);
break;
}
} while (false);
//返回json格式
$this->echoJson($result);
}
/**
* 收藏店鋪,基礎模板
*/
public function favoriteShopAction()
{
if (!$this->isAjax()) {
return;
}
$result = array(
'code' => 400,
'message' => '操作失败'
);
$uid = $this->getUid();
$shopId = $this->post('shopId');
$isFavorite = $this->post('isFavorite');
$needColloect = $this->post('needColloect', 0);
do {
if (!$uid) {
$result = array(
'code' => 403,
'message' => '用户ID不存在',
'data' => array('url' => Helpers::url('/signin.html', array())),
);
break;
}
if ($uid && $shopId) {
//调用接口收藏或取消收藏
$result = ShopModel::setFavorite($shopId, $isFavorite, $uid);
break;
}
} while (false);
//返回json格式
$this->echoJson($result);
}
/**
* 判断品牌是否收藏
*/
public function isFavoriteBrandAction()
{
if (!$this->isAjax()) {
return;
}
$uid = $this->getUid();
$brandId = $this->post('brandId');
if ($uid && $brandId) {
//调用接口收藏或取消收藏
$result = FavoriteData::isFavoriteBrand($uid, $brandId);
$this->echoJson($result);
}
}
/**
* 设置品牌页面的SEO信息
*
* @return void
*/
private function setBrandSeo($seo)
{
$this->setTitle($seo['title']);
$this->setKeywords($seo['keywords']);
$this->setDescription($seo['description']);
}
/**
* 热销排行
*/
public function hotrankAction()
{
//获取频道
$channel = HotrankModel::getChannelResource();
$this->setWebNavHeader();
$this->setTitle('热销排行|YOHO!BUY有货');
$page = $this->get('page', 1);
$sort = $this->get('sid', 1);
$data = array('hotrankPage' => true,
'footerTop' => true,
'hotrank' => HotrankModel::getHotrankResource($channel, $sort, $page)
);
$this->_view->display('hotrank', $data);
}
/*
* 一周热卖加载更多
*/
public function getdataAction()
{
$page = $this->get('page', 1);
//加载到100个以后停止
if ($page > 2) {
echo json_encode(array('code' => 201, 'data' => ''));
exit;
}
$sid = $this->get('sid', 1);
//获取频道资源
$channel = HotrankModel::getChannelResource();
//获取一周热卖资源
$data = HotrankModel::getListData($channel, $sid, $page);
$this->echoJson($data);
}
/**
* 品牌店铺首页
*/
public function shopHome($shopId)
{
// 设置头部数据
$this->setWebNavHeader();
$misort = $this->get('misort');
$pjax = $this->get('_pjax');
if ($pjax) {
$data = ShopModel::getGoods(
array(
'shop' => $shopId
),
array(
'controller' => 'Index',
'action' => 'index',
'misort' => $misort
)
);
$data['shopIndexPage'] = true;
// 渲染模板
$this->_view->display('goods-list', $data);
exit();
}
//获取uid
$uid = $this->getUid();
$parameters = array(
'condition' => array(
'shop' => $shopId
),
'options' => array(
'controller' => 'Index',
'action' => 'index',
'misort' => $misort
),
'uid' => $uid,
'navBar' => $this->get('navBar', 0),
'brand' => $this->get('brand', 0),
'shopId' => $shopId
);
$data = array_merge(
array(
'shopIndexPage' => true,
'pathNav' => false, // pathNav数据结构同其他页面
'coupon' => false, // 先不做
'trendInfo' => ShopModel::getArticle($shopId),
),
ShopModel::getData($shopId, $parameters)
);
$this->_view->display('shop-index', $data);
}
//店铺列表页
public function shopListAction()
{
$shopId = $this->get('shopId', 0);
if (empty($shopId)) {
$this->go(SITE_MAIN);
}
//获取uid
$uid = $this->getUid();
// 设置头部数据
$this->setWebNavHeader();
$parameters = array(
'condition' => array(
'shop' => $shopId
),
'options' => array(
'controller' => 'Index',
'action' => 'index',
),
'uid' => $uid,
'navBar' => $this->get('navBar', 1),
'shopId' => $this->get('shopId', 0),
'brand' => $this->get('brand', 0)
);
$data = array_merge(
array(
'shopIndexPage' => true,
'pathNav' => false, // pathNav数据结构同其他页面
'coupon' => false, // 先不做
),
ShopModel::getShopListData($shopId, $parameters)
);
$this->_view->display('shop-list', $data);
}
/**
* 店铺收藏与取消,經典模板
* @return type json
*/
public function setFavoriteAction()
{
$result = $this->_information;
if (!$this->isAjax()) {
return;
}
//获取uid
$uid = $this->getUid();
do {
if (empty($uid)) {
$result = array(
'code' => 401,
'message' => '请先登录!',
'url' => Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN)))
);
break;
}
$shopId = $this->post('shopId');
$isFavorite = $this->post('isFavorite');
$needColloect = $this->post('needColloect', 0);
if (empty($shopId)) {
break;
}
//$needColloect 说明刚登录状态 是cookie传的值
$isFavorite = $needColloect * 1 === 1 ? true : $isFavorite;
$result = ShopModel::setFavorite($shopId, $isFavorite, $uid);
} while (false);
$this->echoJson($result);
}
}