Favorite.php
19.7 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
<?php
namespace Home;
use WebPlugin\Images;
use WebPlugin\Helpers;
use WebPlugin\Paging;
use LibModels\Web\Product\FavoriteData;
/**
* 个人中心——我的收藏相关业务逻辑
*/
class FavoriteModel
{
/**
* 我的收藏-tabs
* @param type $type
* @return boolean
*/
public static function getFavoriteTabs($type = 'product')
{
$tabs = array(
array(
'url' => Helpers::url('/home/favorite', array('type' => 'product')),
'name' => '商品收藏'
),
array(
'url' => Helpers::url('/home/favorite', array('type' => 'brand')),
'name' => '品牌收藏'
),
array(
'url' => Helpers::url('/home/favorite', array('type' => 'article')),
'name' => '文章收藏'
)
);
switch (strval($type)) {
case 'brand':
$tabs[1]['active'] = true;
break;
case 'article':
$tabs[2]['active'] = true;
break;
default:
$tabs[0]['active'] = true;
break;
}
return $tabs;
}
/**
*
* @param type $uid 用户id
* @param type $page 当前页
* @param type $limit 每页显示数量
* @param type $type 收藏类别
* @param type $sort 商品分类
* @param type $subscribe 订阅降价通知判断
* @param type $reduction 降价商品判断
* @param type $promotion 参加活动商品判断
* @return type
*/
public static function favoriteProductList($uid, $page, $limit, $type, $sort = 0, $subscribe = 'N', $reduction = 'N', $promotion = 'N')
{
$data = array();
$product = array();
$result = array('sort' => array(), 'reduction' => array(), 'filter' => array(), 'goods' => array(), 'pager' => array());
//商品收藏
$product = FavoriteData::getFavoriteProductList($uid);
if (!empty($product['data']['category_list'])) {
$result['sort'] = self::getSortInfo($product['data']['category_list'], $sort); //分类
}
$result['reduction'] = self::redutionCount($uid); //降价通知数量
$productList = array();
//根据不同条件过滤相应商品
do {
if (empty($product['data']['product_list']) || !isset($product['data']['product_list'])) {
break;
}
//参加活动的降价商品
if ($reduction == 'Y' && $promotion == 'Y') {
foreach ($product['data']['product_list'] as $product) {
if ($product['is_price_down'] == 'Y' && $promotion == 'Y') {
$productList[] = $product;
}
}
break;
}
//商品分类过滤
if (!empty($sort)) {
foreach ($product['data']['product_list'] as $product) {
if ($product['category_id'] == $sort) {
$productList[] = $product;
}
}
break;
}
//订阅降价通知过滤
if ($subscribe == 'Y') {
foreach ($product['data']['product_list'] as $product) {
if ($product['is_subscribe_reduction'] == 'Y') {
$productList[] = $product;
}
}
break;
}
//降价商品过滤
if ($reduction == 'Y') {
foreach ($product['data']['product_list'] as $product) {
if ($product['is_price_down'] == 'Y') {
$productList[] = $product;
}
}
break;
}
//参加活动商品过滤
if ($promotion == 'Y') {
foreach ($product['data']['product_list'] as $product) {
if ($product['is_join_promotion'] == 'Y') {
$productList[] = $product;
}
}
break;
}
$productList = $product['data']['product_list'];
}
//降价商品和活动商品过滤器
while (false);
do {
if ($reduction == 'N' && $promotion == 'N') {
$result['filter'] = array('reductionUrl' => Helpers::url('/home/favorite', array('is_reduction' => 'Y')), 'reductionChecked' => '',
'activityUrl' => Helpers::url('/home/favorite', array('is_promotion' => 'Y')), 'activityChecked' => '');
break;
}
if ($reduction == 'N' && $promotion == 'Y') {
$result['filter'] = array('reductionUrl' => Helpers::url('/home/favorite', array('is_reduction' => 'Y', 'is_promotion' => 'Y')), 'reductionChecked' => '',
'activityUrl' => Helpers::url('/home/favorite'), 'activityChecked' => '');
break;
}
if ($reduction == 'Y' && $promotion == 'N') {
$result['filter'] = array('reductionUrl' => Helpers::url('/home/favorite'), 'reductionChecked' => '',
'activityUrl' => Helpers::url('/home/favorite', array('is_reduction' => 'Y', 'is_promotion' => 'Y')), 'activityChecked' => '');
break;
}
$result['filter'] = array('reductionUrl' => Helpers::url('/home/favorite', array('is_promotion' => 'Y')), 'reductionChecked' => '',
'activityUrl' => Helpers::url('/home/favorite', array('is_reduction' => 'Y')), 'activityChecked' => '');
}
while (false);
//分页
$total = count($productList); //商品总数
$pageTotal = ceil($total / $limit); //总页数
$page = $page > $pageTotal ? $pageTotal : $page; //当前页超多总页数取总页数
$result['goods'] = self::getGoodsInfo($productList, $page, $limit); //收藏商品列表
$result['pager'] = self::getPager($page, $total, $pageTotal, $limit, $type);
return $result;
}
/**
* 品牌收藏列表
* @param type $uid 用户id
* @param type $page 当前页
* @param type $limit 每页显示数量
*/
public static function favoriteBrandList($uid, $page, $limit, $type)
{
$result = array('brands' => array('empty' => '您没有收藏品牌'), 'pager' => array());
$brand = FavoriteData::favoriteBrandData($uid, $page, $limit);
do {
if (empty($brand['data']) || empty($brand['data']['page_total'])) {
break;
}
if ($brand['data']['page_total'] < $page) {
$page = $brand['data']['page_total'];
$brand = FavoriteData::favoriteBrandData($uid, $page, $limit);
}
if (empty($brand['data']['brand_list'])) {
break;
}
$brands = array();
foreach ($brand['data']['brand_list'] as $brandkey => $brandval) {
$brands[$brandkey]['id'] = $brandval['brand_id']; //品牌id
$brands[$brandkey]['brandOrShopType'] = empty($brandval['brandOrShopType']) ? '' : $brandval['brandOrShopType'];
$brands[$brandkey]['shop_id'] = empty($brandval['shop_id']) ? '' : $brandval['shop_id'];
$brands[$brandkey]['img'] = Images::getImageUrl($brandval['brand_ico'], 100, 100); //品牌缩略图
$brands[$brandkey]['url'] = Helpers::url('', '', $brandval['brand_domain']); //品牌链接
$brands[$brandkey]['name'] = $brandval['brand_name']; //品牌名
$brands[$brandkey]['naCount'] = $brandval['new_product_num']; //新品到着数量
$brands[$brandkey]['colCount'] = $brandval['brand_favorite_num']; //收藏人气
}
$result['brands'] = $brands;
$total = isset($brand['data']['total']) ? $brand['data']['total'] : 0; //消息总条数
$pageTotal = isset($brand['data']['page_total']) ? $brand['data']['page_total'] : 0; //总页数
$page = isset($brand['data']['page']) ? $brand['data']['page'] : 0; //当前页
$result['pager'] = self::getPager($page, $total, $pageTotal, $limit, $type);
}
while (false);
return $result;
}
/**
* 文章收藏列表
* @param type $uid 用户id
* @param type $page 当前页
* @param type $limit 每页显示数量
*/
public static function favoriteArticleList($uid, $udid, $page, $limit, $type)
{
$result = array('articles' => array(), 'pager' => array());
$article = FavoriteData::favoriteArticleData($uid, $udid, $page, $limit);
if (!empty($article['data']) && !empty($article['data']['data'])) {
foreach ($article['data']['data'] as $artkey => $artval) {
$articles[$artkey]['id'] = $artval['id']; //文章标题
$articles[$artkey]['name'] = $artval['title']; //文章标题
$articles[$artkey]['img'] = Images::getImageUrl($artval['src'], 146, 96); //文章图片
$articles[$artkey]['desc'] = $artval['intro']; //文章介绍
$articles[$artkey]['url'] = Helpers::url('/' . $artval['id'] . '.html', '', 'guang'); //文章链接
$result['articles'] = $articles;
}
$total = isset($article['data']['total']) ? $article['data']['total'] : 0; //消息总条数
$pageTotal = isset($article['data']['totalPage']) ? $article['data']['totalPage'] : 0; //总页数
$result['pager'] = self::getPager($page, $total, $pageTotal, $limit, $type);
}
else {
$result['articles'] = array('empty' => '你尚未收藏任何文章!');
}
return $result;
}
/**
* 商品收藏——商品分类数据整理
* @param array $categoryList 商品分类数据
* @param int $sort 分类id
* @return int
*/
protected static function getSortInfo(array $categoryList, $sort)
{
$result = array('default' => array(), 'all' => array());
$defaultCategory = array('name' => '全部', 'url' => Helpers::url('/home/favorite'), 'count' => 0, 'focus' => '');
foreach ($categoryList as $category) {
$result['all'][] = array(
'name' => $category['category_name'],
'url' => Helpers::url('/home/favorite', array('sort_id' => $category['category_id'])),
'count' => $category['num'],
'focus' => $category['category_id'] == $sort ? true : '',
);
$defaultCategory['count'] += $category['num'];
$defaultCategory['focus'] = $sort == 0 ? true : '';
}
array_unshift($result['all'], $defaultCategory);
$result['default'] = array_slice($result['all'], 0, 7); //默认分类
return $result;
}
/**
* 商品收藏——商品信息整理
* @param type $data 商品数据
* @param type $page 当前页
* @param type $limit 每页显示数量
* @return string
*/
protected static function getGoodsInfo($data, $page, $limit)
{
$result = array();
$begin = ($page - 1) * $limit; //每页第一个商品键名
if (!empty($data)) {
$data = array_slice($data, $begin, $limit); //截取该页显示的商品列表
foreach ($data as $goodkey => $goodsval) {
$result[$goodkey]['skn'] = $goodsval['product_id']; //商品id
$result[$goodkey]['img'] = Images::getImageUrl($goodsval['image'], 100, 100);
$result[$goodkey]['name'] = $goodsval['product_name'];
$result[$goodkey]['url'] = Helpers::getUrlBySkc($goodsval['product_id'], $goodsval['goodsId'], $goodsval['cnAlphabet']);
$result[$goodkey]['price'] = $goodsval['sales_price'];
$result[$goodkey]['priceDown'] = $goodsval['price_down'];
$result[$goodkey]['buyNow'] = Helpers::getUrlBySkc($goodsval['product_id'], $goodsval['goodsId'], $goodsval['cnAlphabet']);
//立即购买
$result[$goodkey]['soldOut'] = $goodsval['storage'] == 0 ? true : ''; //判断已售罄
$result[$goodkey]['hadNoticed'] = $goodsval['is_subscribe_reduction'] == 'Y' ? true : ''; //是否订阅降价通知
//商品可参加的活动
if (empty($goodsval['promotion_list'])) {
continue;
}
$result[$goodkey]['activites']['count'] = count($goodsval['promotion_list']);
foreach ($goodsval['promotion_list'] as $promotionval) {
$result[$goodkey]['activites']['list'][] = array('type' => $promotionval['promotion_type'],
'name' => $promotionval['promotion_title']);
}
}
}
else {
$result = array('empty' => '您没有收藏商品');
}
return $result;
}
/**
* 设置分页数据
* @param type $page 当前页
* @param type $total 列表数量
* @param type $totalPage 总页数
* @param type $size 每页显示数量
* @return type
*/
public static function getPager($page, $total, $totalPage, $size, $type)
{
$result = array();
if (isset($page) && isset($total) && isset($totalPage)) {
$result['count'] = $total;
$result['curPage'] = $page;
$result['totalPages'] = $totalPage;
$result['hasCheckAll'] = true;
$paging = new Paging('yoho');
$paging->setTotal($total)->setSize($size)->setQuery(array('page' => $page, 'type' => $type));
$result['pagerHtml'] = $paging->view(false);
}
return $result;
}
/**
* 新品到着
* @param type $uid 用户uid
* @param type $page 当前页码
* @param type $limit 每页显示数量
* @param type $id 品牌id
*/
public static function newproduct($uid, $page, $limit, $id)
{
$product = array();
$result = array();
//调用品牌列表数据
$product = FavoriteData::favoriteBrandData($uid, $page, $limit);
if (!empty($product['data']['brand_list'])) {
foreach ($product['data']['brand_list'] as $listkey => $listval) {
if ($id != $listval['brand_id']) {
continue;
}
//新品数量为0
if ($listval['new_product_num'] == 0) {
continue;
}
foreach ($listval['new_product'] as $newkey => $newval) {
//显示新品数量20
if ($newkey > 20) {
break;
}
$result[$newkey]['img'] = Images::getImageUrl($newval['default_images'], 100, 100); //新品图片
$result[$newkey]['url'] = Helpers::getUrlBySkc($newval['product_id'], $newval['goods'][0]['id'], $newval['cnAlphabet']); //详情页链接
$result[$newkey]['name'] = $newval['product_name']; //新品名称
$result[$newkey]['salePrice'] = $newval['sales_price'] == $newval['market_price'] ? '': $newval['sales_price']; //打折价格
$result[$newkey]['marketPrice'] = $newval['market_price'];
}
}
}
return $result;
}
/**
* 订阅降价通知数量
* @param type $uid
* @return type
*/
public static function redutionCount($uid)
{
$result = array('count' => 0, 'url' => '/home/favorite/reduction', 'phone' => '');
$data = FavoriteData::redutionCount($uid);
if (isset($data['data']['num'])) {
$result['count'] = intval($data['data']['num']);
$result['phone'] = $data['data']['mobile'];
}
return $result;
}
/**
* 商品收藏搜索
* @param array $product
* @param type $sort
* @param type $subscribe
* @param type $reduction
* @param type $promotion
* @return array
*/
public static function searchProductList(array $product, $sort, $subscribe, $reduction, $promotion)
{
$productList = array();
do {
if (!isset($product['data']['product_list'])) {
break;
}
//商品分类过滤
if (!empty($sort)) {
foreach ($product['data']['product_list'] as $product) {
if ($product['category_id'] == $sort) {
$productList[] = $product;
}
}
break;
}
//订阅降价通知过滤
if ($subscribe == 'Y') {
foreach ($product['data']['product_list'] as $product) {
if ($product['is_subscribe_reduction'] == 'Y') {
$productList[] = $product;
}
}
break;
}
//降价商品过滤
if ($reduction == 'Y') {
foreach ($product['data']['product_list'] as $product) {
if ($product['is_price_down'] == 'Y') {
$productList[] = $product;
}
}
break;
}
//参加活动商品过滤
if ($promotion == 'Y') {
foreach ($product['data']['product_list'] as $product) {
if ($product['is_join_promotion'] == 'Y') {
$productList[] = $product;
}
}
break;
}
$productList = $product['data']['product_list'];
}
while (false);
return $productList;
}
/**
* 降价商品和活动商品过滤器
* @param type $reduction
* @param type $promotion
* @return type
*/
public static function getFilterData($reduction, $promotion)
{
$result = array();
do {
if ($reduction == 'N' && $promotion == 'N') {
$result = array('reductionUrl' => Helpers::url('/home/favorite', array('is_reduction' => 'Y')), 'reductionChecked' => '',
'activityUrl' => Helpers::url('/home/favorite', array('is_promotion' => 'Y')), 'activityChecked' => '');
break;
}
if ($reduction == 'N' && $promotion == 'Y') {
$result = array('reductionUrl' => Helpers::url('/home/favorite', array('is_reduction' => 'Y')), 'reductionChecked' => '',
'activityUrl' => Helpers::url('/home/favorite'), 'activityChecked' => '');
break;
}
if ($reduction == 'Y' && $promotion == 'N') {
$resul = array('reductionUrl' => Helpers::url('/home/favorite'), 'reductionChecked' => '',
'activityUrl' => Helpers::url('/home/favorite', array('is_promotion' => 'Y')), 'activityChecked' => '');
break;
}
$result = array('reductionUrl' => Helpers::url('/home/favorite'), 'reductionChecked' => '',
'activityUrl' => Helpers::url('/home/favorite'), 'activityChecked' => '');
}
while (false);
return $result;
}
}