Coupon.php
6.05 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
<?php
/**
* Created by PhpStorm.
* User: Targaryen
* Date: 2016/4/11
* Time: 16:31
*/
use Action\AbstractAction;
use Coupon\CouponModel;
use LibModels\Wap\Coupon\CouponData;
use Plugin\DataProcess\CouponFloorProcess;
use Plugin\Helpers;
class CouponController extends AbstractAction
{
/**
* 领券楼层数据列表
*
* @author chengyao.guo
*/
public function floorAction()
{
if (!$this->isApp()) {
$this->setNavHeader('领券中心', true, SITE_MAIN);
}
$receiveData = filter_input_array(INPUT_GET, array(
'code' => FILTER_DEFAULT
));
$result = array();
$uid = '';
if ($this->isApp()) {
$uid = $this->get('uid');
} else {
$uid = $this->getUid();
}
$resource = CouponData::getCouponRousource($receiveData['code'], $uid);
if (isset($resource['code']) && $resource['code'] === 200) {
$result = CouponFloorProcess::getContent($resource['data']);
}else{
$this->_view->display('index', array(
'content' => array(
'noData' => true,
),
'floorPage' => true
));
}
// 分享
$shareData = CouponFloorProcess::getShare($receiveData['code'], '领券中心');
$result[count($result)] = $shareData;
$this->_view->display('index', array(
'content' => $result,
'floorPage' => true
));
}
/**
* 领券操作
*
* @author chengyao.guo
*/
public function receiveCouponAction()
{
$returnData = array();
// 获取优惠券 ID
$receiveData = filter_input_array(INPUT_GET, array(
'couponID' => FILTER_DEFAULT
));
// 跳转 URl
$playUrl = Helpers::url('/coupon/floor');
// 判断用户是否登录
$isLogin = false;
if ($this->isApp()) {
if ($this->get('uid') && is_numeric($this->get('uid'))) {
$isLogin = true;
}
} else {
if ($this->getUid() && is_numeric($this->getUid())) {
$isLogin = true;
}
}
if (!$isLogin) {
// 用户未登录,跳转登录页面
$returnData['noLogin'] = true;
if (!$this->isApp()) {
$returnData['url'] = Helpers::url('/signin.html', array('refer' => $playUrl), 'default');
} else {
$playUrlEncode = strtr($playUrl, array('/' => '\\/'));
$returnData['url'] = $playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
}
} else {
// 登录后调用领券接口
$result = CouponData::receiveCoupon($this->getUid(), $receiveData['couponID']);
switch ($result['code']) {
case 200:
$returnData = array(
'msg' => '领券成功!',
'status' => true,
);
break;
default:
$returnData = array(
'msg' => '领券失败!',
'status' => false,
);
break;
}
}
echo json_encode($returnData);
}
/**
* 判断是否是 APP
*
* @return bool
*/
public function isApp()
{
/* $userAgent = $this->getUserAgent();
if (stristr($userAgent, 'ipad')) {
return false;
}
$mobileAgents = array('iphone', 'android', "240x320", "acer", "acoon", "acs-", "abacho", "ahong", "airness", "alcatel", "amoi", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm-", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly_", "fly-", "go.web", "goodaccess", "gradiente", "grundig", "haier", "hedy", "hitachi", "htc", "huawei", "hutchison", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge-", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh-", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshiba", "tsm", "up.browser", "utec", "utstar", "verykool", "virgin", "vk-", "voda", "voxtel", "vx", "wap", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte");
$isMobile = false;
foreach ($mobileAgents as $device) {
if (stristr($userAgent, $device)) {
$isMobile = true;
break;
}
}*/
$isMobile = $this->get('app_version');
return !empty($isMobile);
}
/**
* 获取用户User-Agent
* @return bool
*/
public function getUserAgent()
{
if (!isset($_SERVER['HTTP_USER_AGENT']) || empty($_SERVER['HTTP_USER_AGENT'])) {
return '';
}
return $_SERVER['HTTP_USER_AGENT'];
}
/**
* 获取优惠券
*/
public function couponSendAction()
{
$callback = $this->get('callback');
$token = $this->get('token', '');
$uid = $this->getUid(true);
$app = $this->get('app', array());
$result = CouponModel::couponSend($uid, $token, $app);
$this->helpJsonCallbackResult($callback, $result['code'], $result['message'], $result['data']);
}
}