Coupons.php
3.59 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
<?php
use Action\WebAction;
use WebPlugin\Helpers;
use Home\UserModel;
use Home\CouponsModel;
use WebPlugin\Paging;
class CouponsController extends WebAction
{
public function indexAction()
{
//判断是否登录
$uid = $this->auditJumpLogin();
//头部导航
$channel = Helpers::getChannelNameByCookie();
$this->setWebNavHeader($channel);
//面包屑-左侧导航
$path = UserModel::getCenterCrumb('我的优惠券');
$leftNav = UserModel::getCenterLeftNav('我的优惠券', $uid);
//分页
$page = $this->get('page', 1);
$limit = 10;
$type = $this->get('type', CouponsModel::UNUSED);
//优惠券信息
$coupons = CouponsModel::getCouponsList($uid, $type, $page, $limit);
$data = array (
'path' => $path,
'homeNav' => $leftNav,
'userThumb' => UserModel::getUserHeadImg($uid),
);
$total = isset($coupons['pager']['total']) ? $coupons['pager']['total'] : 0;
$pageTotal = isset($coupons['pager']['pageTotal']) ? $coupons['pager']['pageTotal'] : 0;
$page = isset($coupons['pager']['page']) ? $coupons['pager']['page'] : 0;
unset($coupons['pager']);
$paging = new Paging('yoho');
$paging->setTotal($total)->setSize($limit)->setQuery(array('type' => $type, 'page' => $page));
$data['pager'] = array(
'hasCheckAll' => false,
'count' => $total,
'curPage' => $page,
'totalPages' => $pageTotal,
'pagerHtml' => $paging->view(false)
);
if ($type == CouponsModel::UNUSED) {
if (count($coupons) == 0) {
$data['unUseCoupons'] = array('empty' => '您没有优惠券');
} else {
$data['unUseCoupons'] = $coupons;
}
$data['unUse'] = true;
} else if ($type == CouponsModel::USED) {
if (count($coupons) == 0) {
$data['usedCoupons'] = array('empty' => '您没有优惠券');
} else {
$data['usedCoupons'] = $coupons;
}
$data['used'] = true;
} else if ($type == CouponsModel::INVALID) {
if (count($coupons) == 0) {
$data['noValidCoupons'] = array('empty' => '您没有优惠券');
} else {
$data['noValidCoupons'] = $coupons;
}
$data['noValid'] = true;
}
$unusedUrl = Helpers::url('/home/coupons', array('type' => CouponsModel::UNUSED));
$usedUrl = Helpers::url('/home/coupons', array('type' => CouponsModel::USED));
$overTimeUrl = Helpers::url('/home/coupons', array('type' => CouponsModel::INVALID));
$data['tabs'] = array(
array(
'active' => $type == CouponsModel::UNUSED ? true : false,
'url' => $unusedUrl,
'name' => '未使用优惠券'
),
array(
'active' => $type == CouponsModel::USED ? true : false,
'url' => $usedUrl,
'name' => '已使用优惠券'
),
array(
'active' => $type == CouponsModel::INVALID ? true : false,
'url' => $overTimeUrl,
'name' => '已失效优惠券'
)
);
$this->_view->display('coupons', array(
'meCoupons' => $data,
'hasCoupons' => count($coupons) == 0 ? false : true,
));
}
}