Coupon.php
3.41 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
<?php
namespace Index;
use WebPlugin\Helpers;
use WebPlugin\Images;
use Index\HomeModel;
use LibModels\Web\Home\CouponData;
/**
* 领券频道模型层
*/
class CouponModel
{
/**
* 获取领券频道资源
* @param type $uid 用户uid
* @param type $contentCode 频道位置码
*/
public static function getCouponData($contentCode, $uid = 0)
{
$data = array();
$result = array(
'couponCenterPage' => true,
'pathNav' => array(
HomeModel::getHomeChannelNav('boys'),
array('name' => '领券频道')
),
'footerTop' => true,
'slide' => array(),
'categories' => array(),
);
//获取领券数据
$coupon = CouponData::getCouponRousource($contentCode, $uid);
do {
if (!isset($coupon['data']) || empty($coupon['data'])) {
break;
}
$i = 0;
foreach ($coupon['data'] as $couponlistkey => $couponlistval) {
//头部banner
if (isset($couponlistval['templateName']) && $couponlistval['templateName'] == 'focus') {
foreach ($couponlistval['data'] as $focus) {
$result['slide']['list'][] = array(
'href' => $focus['url'], //banner跳转链接
'img' => Images::getImageUrl($focus['src'], 0, 0)//banner图片
);
}
}
else if (isset($couponlistval['template_name']) && $couponlistval['template_name'] == 'getCoupon') {
//优惠券楼层
if (!isset($coupon['data'][$couponlistkey - 1]['data']['text'])) {
continue;
}
$result['categories'][$i] = array(
'title' => $coupon['data'][$couponlistkey - 1]['data']['text'], //楼层标题
'coupons' => array()
);
foreach ($couponlistval['data'] as $couponskey => $couponsval) {
$result['categories'][$i]['coupons'][$couponskey] = array(
'id' => $couponsval['couponID'], //优惠券号
'img' => Images::getImageUrl($couponsval['image']['src'], 0, 0), //优惠券图片
'url' => $couponsval['image']['url'] //去逛逛链接
);
//领取状态判断
switch ($couponsval['status']) {
case 3 :
$result['categories'][$i]['coupons'][$couponskey]['got'] = true; //优惠券已领取
break;
case 2 :
$result['categories'][$i]['coupons'][$couponskey]['empty'] = true; //优惠券已抢光
break;
default :
$result['categories'][$i]['coupons'][$couponskey]['normal'] = true; //可领取优惠券
}
}
$i = $i + 1;
}
}
}
while (false);
return $result;
}
}