|
|
<?php
|
|
|
|
|
|
use Action\HuodongAction;
|
|
|
use Index\UserModel;
|
|
|
use Cuxiao\YuanxiaoModel;
|
|
|
use Plugin\Helpers;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -9,55 +9,163 @@ use Plugin\Helpers; |
|
|
*/
|
|
|
class YuanxiaoController extends HuodongAction
|
|
|
{
|
|
|
const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016yuanxiao/1.0.0';
|
|
|
const ENCRYPT_KEY = 'iamgtskkwhoareyou';
|
|
|
|
|
|
/**
|
|
|
* 元宵抽签
|
|
|
* 通过当前用户审判是否跳到登录页
|
|
|
*
|
|
|
*/
|
|
|
public function indexAction()
|
|
|
private function auditJumpLogin()
|
|
|
{
|
|
|
//获取登录者ID,未登录返回false
|
|
|
$uid = $this->getLoggedUid();
|
|
|
if (!$uid || !is_numeric($uid)) {
|
|
|
//未登录的用户访问,跳转到登录页面。并且在登陆后跳转回本页面
|
|
|
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/newyear/coupon')), 'default'));
|
|
|
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 元宵抽签
|
|
|
*/
|
|
|
public function indexAction()
|
|
|
{
|
|
|
// 该变量用来控制和显示页面的弹出提示
|
|
|
$showPopupFlag = '0';
|
|
|
|
|
|
$userData = UserModel::getUserProfileData($uid);
|
|
|
|
|
|
$result = array();
|
|
|
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('coupon', array(
|
|
|
'staticTitle' => 'YOHO!BUY有货新年寻宝大作战',
|
|
|
$this->_view->display('index', array(
|
|
|
'staticTitle' => '元宵抽签',
|
|
|
'staticFile' => self::STATIC_FILE,
|
|
|
'weixinShare' => $this->_isApp ? false : true, // 是否需要微信分享
|
|
|
'shareLink' => 'http://feature.yoho.cn/2016lishifeng/index.html',
|
|
|
'shareTitle' => 'YOHO!BUY有货新年寻宝大作战,千元利是等你赢!',
|
|
|
'shareDesc' => 'YOHO!BUY有货,全球800+潮流品牌每日上新!',
|
|
|
'shareImg' => 'http://img12.static.yhbimg.com/couponImg/2015/12/30/12/02008a9724b898dee56852de9f1a3978bf.jpg',
|
|
|
'showPopupFlag' => $showPopupFlag,
|
|
|
'useData' => $userData,
|
|
|
'bannerUrl_1' => 'http://m.yohobuy.com/boys?openby:yohobuy={"action":"go.home","params":{"channel":"1"}}',
|
|
|
'bannerUrl_2' => 'http://m.yohobuy.com/girls?openby:yohobuy={"action":"go.home","params":{"channel":"2"}}',
|
|
|
'bannerUrl_3' => 'http://m.yohobuy.com/kids?openby:yohobuy={"action":"go.home","params":{"channel":"3"}}',
|
|
|
'bannerUrl_4' => 'http://m.yohobuy.com/lifestyle?openby:yohobuy={"action":"go.home","params":{"channel":"4"}}',
|
|
|
'playAgain' => 'http://feature.yoho.cn/2016lishifeng/index.html',
|
|
|
'appUrl_1' => 'http://www.yohoshow.com/about/index/yohobuyqr',
|
|
|
'appUrl_2' => 'http://www.yohoshow.com/about/index/yohoboysqr',
|
|
|
));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 元宵抽签 信息
|
|
|
*/
|
|
|
public function infoAction()
|
|
|
{
|
|
|
// 审判跳转登录页
|
|
|
$this->auditJumpLogin();
|
|
|
|
|
|
// POST提交请求
|
|
|
if (!empty($this->post())) {
|
|
|
$birthday = $this->post('birthday', '');
|
|
|
$gender = $this->post('gender', 0);
|
|
|
|
|
|
// 调用接口
|
|
|
$result = array(
|
|
|
'code' => 200,
|
|
|
'data' => array(
|
|
|
'name' => '李四',
|
|
|
'type' => 'P1',
|
|
|
'count' => 8888
|
|
|
)
|
|
|
);
|
|
|
if ($result['code'] === 200) { // 处理成功就跳转到等待页
|
|
|
// 将返回的结果存入cookeie中15分钟
|
|
|
$this->setCookie('yuanxiaochouqian', json_encode($result['data']), time() + 15*60);
|
|
|
$this->go(Helpers::url('/cuxiao/yuanxiao/wait'));
|
|
|
} else { // 不成功就显示返回的错误信息
|
|
|
$this->_view->display('info', array(
|
|
|
'staticTitle' => '元宵抽签',
|
|
|
'staticFile' => self::STATIC_FILE,
|
|
|
'staticJS' => array(
|
|
|
'info.js'
|
|
|
),
|
|
|
'birthday' => $birthday,
|
|
|
'gender' => $gender,
|
|
|
'message' => $result['message']
|
|
|
));
|
|
|
}
|
|
|
} else {
|
|
|
$uid = $this->getUid();
|
|
|
$userData = YuanxiaoModel::getUserProfileData($uid);
|
|
|
|
|
|
$this->_view->display('info', array(
|
|
|
'staticTitle' => '元宵抽签',
|
|
|
'staticFile' => self::STATIC_FILE,
|
|
|
'staticJS' => array(
|
|
|
'info.js'
|
|
|
),
|
|
|
'birthday' => $userData['birthday'],
|
|
|
'gender' => $userData['gender'],
|
|
|
));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 元宵抽签 等待
|
|
|
*/
|
|
|
public function waitAction()
|
|
|
{
|
|
|
// 审判跳转登录页
|
|
|
$this->auditJumpLogin();
|
|
|
|
|
|
$this->_view->display('wait', array(
|
|
|
'staticTitle' => '元宵抽签',
|
|
|
'staticFile' => self::STATIC_FILE
|
|
|
));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 元宵抽签 结果
|
|
|
*/
|
|
|
public function resultAction()
|
|
|
{
|
|
|
// 审判跳转登录页
|
|
|
$this->auditJumpLogin();
|
|
|
|
|
|
$result = $this->getCookie('yuanxiaochouqian', null);
|
|
|
if (empty($result)) { // 未取到信息就重新测试
|
|
|
$this->go(Helpers::url('/cuxiao/yuanxiao/info'));
|
|
|
}
|
|
|
// cookie中存的结果
|
|
|
$result = json_decode($result, true);
|
|
|
$shareUrl = Helpers::url('/cuxiao/yuanxiao/share', array(
|
|
|
'name' => $this->encrypt($result['name']),
|
|
|
'hash' => $this->encrypt($this->getUid())
|
|
|
));
|
|
|
|
|
|
$this->_view->display('result', array(
|
|
|
'staticTitle' => '元宵抽签',
|
|
|
'staticFile' => self::STATIC_FILE,
|
|
|
'result' => $result,
|
|
|
'shareUrl' => $shareUrl,
|
|
|
'staticJS' => array(
|
|
|
'result.js'
|
|
|
)
|
|
|
));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 元宵抽签 分享
|
|
|
*/
|
|
|
public function shareAction()
|
|
|
{
|
|
|
// 昵称从url中解析
|
|
|
$name = $this->decrypt($this->get('name', ''));
|
|
|
// 用户UID
|
|
|
$uid = $this->decrypt($this->get('hash', ''));
|
|
|
|
|
|
// 调用接口获取type和count
|
|
|
$result = array('type' => 'M1', 'count' => 9887);
|
|
|
|
|
|
$this->_view->display('share', array(
|
|
|
'staticTitle' => '元宵抽签',
|
|
|
'staticFile' => self::STATIC_FILE,
|
|
|
'result' => array(
|
|
|
'name' => $name,
|
|
|
'type' => $result['type']
|
|
|
),
|
|
|
'count' => $result['count'],
|
|
|
'staticJS' => array(
|
|
|
'share.js'
|
|
|
)
|
|
|
));
|
|
|
}
|
|
|
|
...
|
...
|
@@ -68,8 +176,6 @@ class YuanxiaoController extends HuodongAction |
|
|
*/
|
|
|
private function getLoggedUid()
|
|
|
{
|
|
|
// 判断是否是应用访问, 拼接APP需要的URL参数
|
|
|
$this->_isApp = (null !== $this->get('app_version') || null !== $this->get('uid'));
|
|
|
if ($this->_isApp) {
|
|
|
$uid = $this->get('uid');
|
|
|
} else {
|
...
|
...
|
@@ -78,4 +184,72 @@ class YuanxiaoController extends HuodongAction |
|
|
|
|
|
return $uid;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 加密字符串
|
|
|
*
|
|
|
* @param string $data 需要加密的字符串
|
|
|
* @return string 加密之后的字符串
|
|
|
*/
|
|
|
private function encrypt($data)
|
|
|
{
|
|
|
$data = strval($data);
|
|
|
$key = md5(self::ENCRYPT_KEY);
|
|
|
$x = 0;
|
|
|
$len = strlen($data);
|
|
|
$l = strlen($key);
|
|
|
$char = '';
|
|
|
$str = '';
|
|
|
|
|
|
for ($i = 0; $i < $len; $i++) {
|
|
|
if ($x == $l)
|
|
|
{
|
|
|
$x = 0;
|
|
|
}
|
|
|
$char .= $key{$x};
|
|
|
$x++;
|
|
|
}
|
|
|
|
|
|
for ($i = 0; $i < $len; $i++) {
|
|
|
$str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
|
|
|
}
|
|
|
|
|
|
return base64_encode($str);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 解密字符串
|
|
|
*
|
|
|
* @param string $data 需要解密的字符串
|
|
|
* @return string 解密之后的字符串
|
|
|
*/
|
|
|
private function decrypt($data)
|
|
|
{
|
|
|
$key = md5(self::ENCRYPT_KEY);
|
|
|
$x = 0;
|
|
|
$data = base64_decode($data);
|
|
|
$len = strlen($data);
|
|
|
$l = strlen($key);
|
|
|
$char = '';
|
|
|
$str = '';
|
|
|
|
|
|
for ($i = 0; $i < $len; $i++) {
|
|
|
if ($x == $l)
|
|
|
{
|
|
|
$x = 0;
|
|
|
}
|
|
|
$char .= substr($key, $x, 1);
|
|
|
$x++;
|
|
|
}
|
|
|
|
|
|
for ($i = 0; $i < $len; $i++) {
|
|
|
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
|
|
|
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
|
|
|
} else {
|
|
|
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $str;
|
|
|
}
|
|
|
} |
...
|
...
|
|