Authored by Rock Zhang

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

1 -<?php  
2 -use Action\HuodongAction;  
3 -use LibModels\Wap\Cuxiao\ActivityData;  
4 -use Plugin\Helpers;  
5 -  
6 -/**  
7 - * 女生节领券活动  
8 - */  
9 -class GirlsdayController extends HuodongAction  
10 -{  
11 -  
12 - /**  
13 - * 检测登录状态  
14 - *  
15 - * @return int  
16 - */  
17 - private function getLoggedUid()  
18 - {  
19 - if ($this->_isApp) {  
20 - $uid = $this->get('uid');  
21 - } else {  
22 - $uid = $this->getUid();  
23 - }  
24 -  
25 - return $uid;  
26 - }  
27 -  
28 - /**  
29 - * 判断是否登陆  
30 - */  
31 - private function checkLogin()  
32 - {  
33 - $playUrl = Helpers::url('/cuxiao/girlsday/index');  
34 - $playUrlEncode = strtr($playUrl, array('/' => '\\/'));  
35 -  
36 - $uid = $this->getLoggedUid();  
37 - if (!$uid) {  
38 - if (!$this->_isApp) {  
39 - $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));  
40 - } else {  
41 - $playUrl = Helpers::url('/cuxiao/yuanxiao/index');  
42 - $this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');  
43 - }  
44 - }  
45 -  
46 - return $uid;  
47 - }  
48 -  
49 - /**  
50 - * 领券活动  
51 - */  
52 - public function indexAction()  
53 - {  
54 - $uid = $this->checkLogin();  
55 -  
56 - // 该变量用来控制和显示页面的弹出提示  
57 - $showPopupFlag = '0';  
58 -  
59 - //获取跳转到个人中心-我的优惠券链接,并调用接口,完成领券操作  
60 - $myCouponUrl = Helpers::url('/home/coupons', null, 'default') . '?openby:yohobuy={"action":"go.coupon"}';  
61 - $activityId = $this->getActivityId();  
62 - $result = ActivityData::getCouponAll($uid, $activityId);  
63 - if (isset($result['code'])) {  
64 - switch (intval($result['code'])) {  
65 - case 200: // 领取成功, 发送站内信消息  
66 - $showPopupFlag = '0';  
67 - $this->sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');  
68 - break;  
69 - case 201: // 已领取过, 提示重复领券  
70 - $showPopupFlag = '1';  
71 - break;  
72 - default: // 领取失败, 提示领券失败  
73 - $showPopupFlag = '2';  
74 - break;  
75 - }  
76 - }  
77 -  
78 - $this->_view->display('index', array(  
79 - 'staticTitle' => '女生节领劵活动',  
80 - 'staticJS' => array(  
81 - 'home.js'  
82 - ),  
83 - 'weixinShare' => $this->_isApp ? false : true, // 是否需要微信分享  
84 - 'showPopupFlag' => $showPopupFlag,  
85 - 'myCouponUrl' => $myCouponUrl,  
86 - 'shareDesc' => '女生节领劵活动',  
87 - 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',  
88 - 'shareUrl' => Helpers::url('/cuxiao/girlsday/index')  
89 - ));  
90 - }  
91 -  
92 - /**  
93 - * 根据环境来获取活动ID  
94 - *  
95 - * @return int  
96 - */  
97 - private function getActivityId()  
98 - {  
99 - // 设置环境变量  
100 - switch (APPLICATION_ENV) {  
101 - case 'production': // 生产  
102 - return 388;  
103 - case 'preview': // 预览  
104 - case 'testing': // 测试  
105 - case 'develop': // 开发  
106 - default:  
107 - return 84;  
108 - }  
109 - }  
110 -  
111 - /**  
112 - * 发送站内信  
113 - *  
114 - * @param int $uid 用户ID  
115 - * @param string $title 站内信标题  
116 - * @param string $content 站内信内容  
117 - */  
118 - private function sendMessage($uid, $title, $content)  
119 - {  
120 - try {  
121 - ActivityData::message($uid, $title, $content);  
122 - } catch (Exception $e) {  
123 - // do nothing  
124 - }  
125 - }  
126 -}  
1 <?php 1 <?php
2 2
3 use Action\HuodongAction; 3 use Action\HuodongAction;
  4 +use LibModels\Wap\Cuxiao\ActivityData;
4 use Plugin\Helpers; 5 use Plugin\Helpers;
5 6
6 /** 7 /**
7 - * 元宵抽签活动 8 + * 新势力领券活动
8 */ 9 */
9 class XinshiliController extends HuodongAction 10 class XinshiliController extends HuodongAction
10 { 11 {
11 // const STATIC_FILE = 'http://localhost:2222/1.0.0'; 12 // const STATIC_FILE = 'http://localhost:2222/1.0.0';
12 const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016xinshili/1.0.0'; 13 const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016xinshili/1.0.0';
13 14
  15 +
  16 + /**
  17 + * 检测登录状态
  18 + *
  19 + * @return int
  20 + */
  21 + private function getLoggedUid()
  22 + {
  23 + if ($this->_isApp) {
  24 + $uid = $this->get('uid');
  25 + } else {
  26 + $uid = $this->getUid();
  27 + }
  28 +
  29 + return $uid;
  30 + }
  31 +
  32 + /**
  33 + * 判断是否登陆
  34 + */
  35 + private function checkLogin()
  36 + {
  37 + $playUrl = Helpers::url('/cuxiao/girlsday/index');
  38 + $playUrlEncode = strtr($playUrl, array('/' => '\\/'));
  39 +
  40 + $uid = $this->getLoggedUid();
  41 + if (!$uid) {
  42 + if (!$this->_isApp) {
  43 + $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
  44 + } else {
  45 + $playUrl = Helpers::url('/cuxiao/yuanxiao/index');
  46 + $this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
  47 + }
  48 + }
  49 +
  50 + return $uid;
  51 + }
  52 +
14 /** 53 /**
15 - * 元宵抽签 54 + * 领券活动页面控制器
16 */ 55 */
17 public function indexAction() 56 public function indexAction()
18 { 57 {
  58 + $uid = $this->checkLogin();
  59 +
  60 + // 该变量用来控制和显示页面的弹出提示
  61 + $showPopupFlag = '0';
  62 +
  63 + //获取跳转到个人中心-我的优惠券链接,并调用接口,完成领券操作
  64 + $myCouponUrl = Helpers::url('/home/coupons', null, 'default') . '?openby:yohobuy={"action":"go.coupon"}';
  65 +
19 $this->_view->display('index', array( 66 $this->_view->display('index', array(
20 - 'staticTitle' => '新势力', 67 + 'staticTitle' => '新势力领劵活动',
21 'staticFile' => self::STATIC_FILE, 68 'staticFile' => self::STATIC_FILE,
22 'staticJS' => array( 69 'staticJS' => array(
23 'home.js' 70 'home.js'
24 ), 71 ),
25 - 'couponUrl' => '', // 个人中心优惠券地址 72 + 'couponUrl' => $myCouponUrl, // 个人中心优惠券地址
26 'banner' => array( 73 'banner' => array(
27 'img' => '', 74 'img' => '',
28 'url' => '' 75 'url' => ''
29 ), 76 ),
30 - 'weixinUrl' => '', // 微信关注地址  
31 - 'appUrl' => '', // APP 下载地址 77 + 'weixinUrl' => 'http://mp.weixin.qq.com/s?__biz=MjM5ODI5MDA4MA==&amp;mid=201849402&amp;idx=1&amp;sn=c0089812f9769d82e0075f69d771f6e1#rd', // 微信关注地址
  78 + 'appUrl' => 'http://www.yohoshow.com/about/index/yohobuyqr', // APP 下载地址
32 'shareTitle' => '新势力', 79 'shareTitle' => '新势力',
33 'shareDesc' => '新势力领券', 80 'shareDesc' => '新势力领券',
34 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png', 81 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
35 - 'shareLink' => Helpers::url('/cuxiao/yuanxiao/index') 82 + 'shareLink' => Helpers::url('/cuxiao/girlsday/index')
36 )); 83 ));
37 } 84 }
38 85
  86 + /**
  87 + * 领券接口
  88 + */
  89 + public function sendCoupon()
  90 + {
  91 + $result = array('code' => 201);
  92 +
  93 + do {
  94 + if (!$this->isAjax()) {
  95 + break;
  96 + }
  97 +
  98 + $activityId = $this->getActivityId();
  99 + $uid = $this->getLoggedUid();
  100 + $result = ActivityData::getCouponAll($uid, $activityId);
  101 + if (!isset($result['code'])) {
  102 + break;
  103 + }
  104 +
  105 + if (intval($result['code']) === 200) {
  106 + $this->sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');
  107 + }
  108 + } while (false);
  109 +
  110 + $this->echoJson($result);
  111 + }
  112 +
  113 + /**
  114 + * 根据环境来获取活动ID
  115 + *
  116 + * @return int
  117 + */
  118 + private function getActivityId()
  119 + {
  120 + // 设置环境变量
  121 + switch (APPLICATION_ENV) {
  122 + case 'production': // 生产
  123 + return 388;
  124 + case 'preview': // 预览
  125 + case 'testing': // 测试
  126 + case 'develop': // 开发
  127 + default:
  128 + return 84;
  129 + }
  130 + }
  131 +
  132 + /**
  133 + * 发送站内信
  134 + *
  135 + * @param int $uid 用户ID
  136 + * @param string $title 站内信标题
  137 + * @param string $content 站内信内容
  138 + */
  139 + private function sendMessage($uid, $title, $content)
  140 + {
  141 + try {
  142 + ActivityData::message($uid, $title, $content);
  143 + } catch (Exception $e) {
  144 + // do nothing
  145 + }
  146 + }
  147 +
39 } 148 }