Authored by Rock Zhang

添加女生节领券活动wap端的部分代码

<?php
use Action\HuodongAction;
use LibModels\Wap\Cuxiao\ActivityData;
use Plugin\Helpers;
/**
* 女生节领券活动
*/
class GirlsdayController extends HuodongAction
{
/**
* 检测登录状态
*
* @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/girlsday/index');
$playUrlEncode = strtr($playUrl, array('/' => '\\/'));
$uid = $this->getLoggedUid();
if (!$uid) {
if (!$this->_isApp) {
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
} else {
$playUrl = Helpers::url('/cuxiao/yuanxiao/index');
$this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
}
}
return $uid;
}
/**
* 领券活动
*/
public function indexAction()
{
$uid = $this->checkLogin();
// 该变量用来控制和显示页面的弹出提示
$showPopupFlag = '0';
//获取跳转到个人中心-我的优惠券链接,并调用接口,完成领券操作
$myCouponUrl = Helpers::url('/home/coupons', null, 'default') . '?openby:yohobuy={"action":"go.coupon"}';
$activityId = $this->getActivityId();
$result = ActivityData::getCouponAll($uid, $activityId);
if (isset($result['code'])) {
switch (intval($result['code'])) {
case 200: // 领取成功, 发送站内信消息
$showPopupFlag = '0';
$this->sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');
break;
case 201: // 已领取过, 提示重复领券
$showPopupFlag = '1';
break;
default: // 领取失败, 提示领券失败
$showPopupFlag = '2';
break;
}
}
$this->_view->display('index', array(
'staticTitle' => '女生节领劵活动',
'staticJS' => array(
'home.js'
),
'weixinShare' => $this->_isApp ? false : true, // 是否需要微信分享
'showPopupFlag' => $showPopupFlag,
'myCouponUrl' => $myCouponUrl,
'shareDesc' => '女生节领劵活动',
'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
'shareUrl' => Helpers::url('/cuxiao/girlsday/index')
));
}
/**
* 根据环境来获取活动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
}
}
}
\ No newline at end of file
... ...