Authored by Rock Zhang

Merge branch 'feature/wap/yuanxiao' of git.dev.yoho.cn:web/yohobuy into feature/wap/yuanxiao

Conflicts:
	yohobuy/huodong.m.yohobuy.com/application/modules/Cuxiao/controllers/Yuanxiao.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>{{staticTitle}}</title>
<!-- <meta name="apple-mobile-web-app-title" content="SUMMER SALE"> -->
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="grey">
<script>
(function(d,c){var e=d.documentElement,a="orientationchange" in window?"orientationchange":"resize",b=function(){var f=e.clientWidth;if(!f){return}if(f>=640){e.style.fontSize="80px"}else{e.style.fontSize=80*(f/640)+"px"}};if(!d.addEventListener){return}b();c.addEventListener(a,b,false);d.addEventListener("DOMContentLoaded",b,false)})(document,window);
</script>
</head>
<body>
<div class="main-wrap">
元宵节抽签
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap home">
<div class="header"></div>
<div class="people">
<div class="flower flower-l"></div>
<div class="flower flower-r"></div>
</div>
<a class="start" href="/cuxiao/yuanxiao/info"></a>
<div class="footer">
<a class="arrow animated infinite pulse" href="/cuxiao/yuanxiao/info"></a>
<div class="yohobuy"></div>
</div>
</div>
</body>
{{> cuxiao/yuanxiao/footer}}
... ...
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap info">
<div class="header">
<span class="title chao">潮</span>
<span class="title liu">流</span>
<div class="sub-title">&nbsp;开运测试</div>
</div>
<form class="user" method="POST">
<div class="user-info nick">
<div class="title">
昵称
</div>
<input type="text" name="nick" placeholder="请输入您帅气的名字!" value="" maxlength="5">
</div>
<div class="user-info birthday">
<div class="title">
生日
</div>
<input type="date" name="birthday" value="2011-12-13">
</div>
<div class="gender">
<div class="title">
性<br>别
</div>
<div class="icon boy">
<span class="check {{#if gender}}checked{{/if}}" data-gender="{{#if gender}}1{{/if}}"></span>
</div>
<div class="icon girl">
<span class="check {{#unless gender}}checked{{/if}}" data-gender="{{#if gender}}0{{/if}}"></span>
</div>
<input type="hidden" name="gender" id="gender" value="{{gender}}">
</div>
</form>
<div class="footer">
<div class="submit">
开始测试
</div>
</div>
<div class="mask hide">
<div class="modal">
<div class="icon close"></div>
<div class="text">
你还没有<br>完善信息哦
</div>
<div class="btn close">
现在就完善
</div>
</div>
</div>
</div>
{{> cuxiao/yuanxiao/footer}}
... ...
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap result">
<div class="flower flower-l"></div>
<div class="flower flower-r"></div>
<div class="title">
<p>
{{result.name}}
</p>
2016年潮流运势是
</div>
<div class="hr">
</div>
<div class="type {{result.type}}" data-type="{{result.type}}">
</div>
<div class="footer">
<div class="share">
分享2016年潮流运势
</div>
</div>
</div>
{{> cuxiao/yuanxiao/type}}
{{> cuxiao/yuanxiao/footer}}
... ...
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap share">
<div class="header"></div>
<div class="flower flower-l"></div>
<div class="flower flower-r"></div>
<div class="title">
<p>
{{result.name}}
</p>
2016年潮流运势是
</div>
<div class="type {{result.type}}" data-type="{{result.type}}">
</div>
<div class="count">
已有{{count}}人参与
</div>
<div class="footer">
<a class="entry" href="/cuxiao/yuanxiao/index">
我也要测
</a>
</div>
</div>
{{> cuxiao/yuanxiao/type}}
{{> cuxiao/yuanxiao/footer}}
... ...
{{> cuxiao/yuanxiao/header}}
<div class="main-wrap wait">
<div class="flower flower-l"></div>
<div class="flower flower-r"></div>
<div class="tip">
正在分析你的<br>潮流运势<br>…
</div>
<div class="loading animated infinite rotateIn">
</div>
<div class="hat">
</div>
<div class="footer">
</div>
</div>
<script type="text/javascript">
setTimeout(function (){
location.href = "/cuxiao/yuanxiao/result";
}, 2000);
</script>
{{> cuxiao/yuanxiao/footer}}
... ...
<script type="text/javascript" src="{{staticFile}}/js/libs.js"></script>
{{#staticJS}}
<script type="text/javascript" src="{{../staticFile}}/js/{{.}}"></script>
{{/staticJS}}
</body>
... ...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>{{staticTitle}}</title>
<!-- <meta name="apple-mobile-web-app-title" content="SUMMER SALE"> -->
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="grey">
<script type="text/javascript">
(function(d,c){var e=d.documentElement,a="orientationchange" in window?"orientationchange":"resize",b=function(){var f=e.clientWidth;if(!f){return}if(f>=640){e.style.fontSize="40px"}else{e.style.fontSize=40*(f/640)+"px"}};if(!d.addEventListener){return}b();c.addEventListener(a,b,false);d.addEventListener("DOMContentLoaded",b,false)})(document,window);
</script>
<link rel="stylesheet" href="{{staticFile}}/css/style.css">
</head>
<body>
... ...
<script type="text/tmpl" id="P1">
<div class="bg-guang"></div>
<div class="bg-yuan"></div>
<div class="title">成为一个大写加粗的</div>
<div class="chaoren animated infinite pulse"></div>
</script>
<script type="text/tmpl" id="P2">
<div class="bg-bige animated zoomIn"></div>
<div class="bg-manzai animated zoomIn"></div>
<div class="bg-ren"></div>
<div class="title animated infinite pulse"></div>
<div class="yzbb animated slideInDown"></div>
</script>
<script type="text/tmpl" id="P3">
<div class="bg-yunqi animated zoomIn"></div>
<div class="shoes animated infinite swing"></div>
<div class="yeezy animated slideInDown"></div>
</script>
<script type="text/tmpl" id="P4">
<div class="bg-car"></div>
<div class="hands animated infinite swing"></div>
<div class="wanghong animated slideInRight"></div>
</script>
<script type="text/tmpl" id="M1">
<div class="bg-majia"></div>
<div class="bg-yifei animated slideInUp"></div>
<div class="flyman animated infinite "></div>
</script>
<script type="text/tmpl" id="M2">
<div class="bg-bamei animated slideInRight"></div>
<div class="meizi animated infinite swing"></div>
<div class="shoes"></div>
</script>
<script type="text/tmpl" id="M3">
<div class="bg-cloud1 animated slideInRight"></div>
<div class="bg-chuanzhe animated slideInLeft"></div>
<div class="shan"></div>
<div class="rensheng"></div>
<div class="cloud2 animated slideInRight"></div>
<div class="shoes animated infinite swing"></div>
</script>
<script type="text/tmpl" id="M4">
<div class="bg-guang"></div>
<div class="bg-jin1 animated slideInright"></div>
<div class="ren"></div>
<div class="jin2 animated slideInDown"></div>
<div class="jin3 animated slideInDown"></div>
<div class="shuaiqi animated slideInDown"></div>
</script>
<script type="text/tmpl" id="F1">
<div class="bg-hezi1 animated slideInLeft"></div>
<div class="bg-hezi2 animated slideInDown"></div>
<div class="bg-hezi3 animated slideInRight"></div>
<div class="sun animated infinite zoomIn"></div>
<div class="kuaidi animated slideInDown"></div>
</script>
<script type="text/tmpl" id="F2">
<div class="bg-love1 animated infinite zoomIn"></div>
<div class="bg-love2"></div>
<div class="boy animated slideInRight"></div>
<div class="girl animated slideInLeft"></div>
<div class="bidong animated slideInRight"></div>
</script>
<script type="text/tmpl" id="F3">
<div class="bg-bra animated infinite pulse"></div>
<div class="xiongda animated zoomIn"></div>
</script>
<script type="text/tmpl" id="F4">
<div class="bg-guang animated infinite zoomIn"></div>
<div class="bg-shoes1 animated slideInLeft"></div>
<div class="bg-shoes2 animated slideInRight"></div>
<div class="bg-shoes3 animated slideInDown"></div>
<div class="style animated slideInUp"></div>
</script>
... ...
<?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;
}
}
... ...