Xinshili.php
4.14 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
<?php
use Action\HuodongAction;
use LibModels\Wap\Cuxiao\ActivityData;
use Plugin\Helpers;
/**
* 新势力领券活动
*/
class XinshiliController extends HuodongAction
{
// const STATIC_FILE = 'http://localhost:2222/1.0.1';
const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016xinshili/1.0.1';
/**
* 检测登录状态
*
* @return int
*/
private function getLoggedUid()
{
if ($this->_isApp) {
$uid = $this->get('uid');
} else {
$uid = $this->getUid();
}
return $uid;
}
/**
* 判断是否登陆
*/
private function checkLogin()
{
$playUrl = Helpers::url('/cuxiao/xinshili/index');
$playUrlEncode = strtr($playUrl, array('/' => '\\/'));
$uid = $this->getLoggedUid();
if (!$uid) {
if (!$this->_isApp) {
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/xinshili/index')), 'default'));
} else {
$playUrl = Helpers::url('/cuxiao/xinshili/index');
$this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
}
}
}
/**
* 领券活动页面控制器
*/
public function indexAction()
{
$this->checkLogin();
//获取跳转到个人中心-我的优惠券链接,并调用接口,完成领券操作
$myCouponUrl = Helpers::url('/home/coupons', null, 'default') . '?openby:yohobuy={"action":"go.coupon"}';
$this->_view->display('index', array(
'staticTitle' => '新势力领劵活动',
'staticFile' => self::STATIC_FILE,
'staticJS' => array(
'home.js'
),
'couponUrl' => $myCouponUrl, // 个人中心优惠券地址
'banner' => array(
'img' => '',
'url' => ''
),
'weixinUrl' => 'http://mp.weixin.qq.com/s?__biz=MjM5ODI5MDA4MA==&mid=201849402&idx=1&sn=c0089812f9769d82e0075f69d771f6e1#rd', // 微信关注地址
'appUrl' => 'http://www.yohoshow.com/about/index/yohobuyqr', // APP 下载地址
'shareTitle' => '新势力',
'shareDesc' => '新势力领券',
'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
'shareLink' => Helpers::url('/cuxiao/xinshili/index')
));
}
/**
* 领券接口
*/
public function sendCouponAction()
{
$result = array('code' => 201);
do {
if (!$this->isAjax()) {
break;
}
$activityId = $this->getActivityId();
$uid = $this->getLoggedUid();
$result = ActivityData::getCouponAll($uid, $activityId);
if (!isset($result['code'])) {
break;
}
if (intval($result['code']) === 200) {
$this->sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');
}
} while (false);
$this->echoJson($result);
}
/**
* 根据环境来获取活动ID
*
* @return int
*/
private function getActivityId()
{
// 设置环境变量
switch (APPLICATION_ENV) {
case 'production': // 生产
return 388;
case 'preview': // 预览
case 'testing': // 测试
case 'develop': // 开发
default:
return 84;
}
}
/**
* 发送站内信
*
* @param int $uid 用户ID
* @param string $title 站内信标题
* @param string $content 站内信内容
*/
private function sendMessage($uid, $title, $content)
{
try {
ActivityData::message($uid, $title, $content);
} catch (Exception $e) {
// do nothing
}
}
}