Coupon.php
2.87 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
<?php
use Action\WebAction;
use WebPlugin\Helpers;
use WebPlugin\Encryption;
use Index\HomeModel;
use Index\CouponModel;
use LibModels\Web\Home\CouponData;
/**
* 领券频道
*/
class CouponController extends WebAction
{
/**
* 判断是否登录
*/
private function checkLogin()
{
$playUrl = Helpers::url('/coupon/index');
$uid = $this->getUid();
if (!$uid) {
$this->go(Helpers::url('/signin.html', array('refer' => $playUrl), 'default'));
}
}
/**
* 领券页面控制器
*/
public function indexAction()
{
$channel = Helpers::getChannelNameByCookie();
//领券频道头部
$this->setWebNavHeader($channel);
//获取领券频道资源
$uid = $this->getUid();
$code_coupon = filter_input_array(INPUT_GET, array('contentCode' => FILTER_DEFAULT ));//领券频道资源码
// $data = CouponModel :: getCouponData(HomeModel::CODE_COUPON_CHANNEL, $uid);
$data = CouponModel :: getCouponData( $code_coupon['contentCode'], $uid);
$this->_view->display('index', $data);
}
/**
* 领券接口
*/
public function sendCouponAction()
{
$result = array('code' => 400, 'message' => '领取失败', 'data' => '');
do {
if (!$this->isAjax()) {
break;
}
$couponId = $this->get('id', '');
if (empty($couponId)) {
break;
}
//解密
$couponId = Encryption::decrypt($couponId);
$uid = $this->getUid();
if (!$uid) {
$playUrl = Helpers::url('/coupon/index');
$result = array('code' => 403, 'message' => '未登录', 'data' => '',
'url' => Helpers::url('/signin.html', array('refer' => $playUrl), 'default'));
break;
}
//领取优惠券
$sendcoupon = CouponData::sendCoupon($couponId, $uid);
switch ($sendcoupon['code']) {
case 200 :
$result = array('code' => 200, 'message' => '恭喜您,成功领取优惠券',
'data' => '', 'url' => Helpers::url('/home/coupons'));
break;
case 401 :
$result = array('code' => 401, 'message' => '您已领取过优惠券', 'data' => '');
break;
case 315;
$result = array('code' => 315, 'message' => '优惠券已过期', 'data' => '');
break;
default :
$result = array('code' => 400, 'message' => '领取失败', 'data' => ''); //403已领完 400未登录
}
}
while (false);
$this->echoJson($result);
}
}