Authored by Rock Zhang

添加新势力领券活动的领券接口

<?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
<?php
use Action\HuodongAction;
use LibModels\Wap\Cuxiao\ActivityData;
use Plugin\Helpers;
/**
* 元宵抽签活动
* 新势力领券活动
*/
class XinshiliController extends HuodongAction
{
// const STATIC_FILE = 'http://localhost:2222/1.0.0';
const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016xinshili/1.0.0';
/**
* 检测登录状态
*
* @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"}';
$this->_view->display('index', array(
'staticTitle' => '新势力',
'staticTitle' => '新势力领劵活动',
'staticFile' => self::STATIC_FILE,
'staticJS' => array(
'home.js'
),
'couponUrl' => '', // 个人中心优惠券地址
'couponUrl' => $myCouponUrl, // 个人中心优惠券地址
'banner' => array(
'img' => '',
'url' => ''
),
'weixinUrl' => '', // 微信关注地址
'appUrl' => '', // APP 下载地址
'weixinUrl' => 'http://mp.weixin.qq.com/s?__biz=MjM5ODI5MDA4MA==&amp;mid=201849402&amp;idx=1&amp;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/yuanxiao/index')
'shareLink' => Helpers::url('/cuxiao/girlsday/index')
));
}
/**
* 领券接口
*/
public function sendCoupon()
{
$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
}
}
}
... ...