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
1 -<!DOCTYPE html>  
2 -<html>  
3 -<head>  
4 - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
5 - <meta charset="utf-8">  
6 - <title>{{staticTitle}}</title>  
7 - <!-- <meta name="apple-mobile-web-app-title" content="SUMMER SALE"> -->  
8 - <meta name="format-detection" content="telephone=no">  
9 - <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">  
10 - <meta name="apple-mobile-web-app-capable" content="yes">  
11 - <meta name="apple-mobile-web-app-status-bar-style" content="grey">  
12 - <script>  
13 - (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);  
14 - </script>  
15 -</head>  
16 -<body>  
17 - <div class="main-wrap">  
18 - 元宵节抽签 1 +{{> cuxiao/yuanxiao/header}}
  2 + <div class="main-wrap home">
  3 + <div class="header"></div>
  4 + <div class="people">
  5 + <div class="flower flower-l"></div>
  6 + <div class="flower flower-r"></div>
19 </div> 7 </div>
20 -</body> 8 + <a class="start" href="/cuxiao/yuanxiao/info"></a>
  9 + <div class="footer">
  10 + <a class="arrow animated infinite pulse" href="/cuxiao/yuanxiao/info"></a>
  11 + <div class="yohobuy"></div>
  12 + </div>
  13 + </div>
  14 +{{> cuxiao/yuanxiao/footer}}
  1 +{{> cuxiao/yuanxiao/header}}
  2 + <div class="main-wrap info">
  3 + <div class="header">
  4 + <span class="title chao">潮</span>
  5 + <span class="title liu">流</span>
  6 +
  7 + <div class="sub-title">&nbsp;开运测试</div>
  8 + </div>
  9 +
  10 + <form class="user" method="POST">
  11 + <div class="user-info nick">
  12 + <div class="title">
  13 + 昵称
  14 + </div>
  15 + <input type="text" name="nick" placeholder="请输入您帅气的名字!" value="" maxlength="5">
  16 + </div>
  17 + <div class="user-info birthday">
  18 + <div class="title">
  19 + 生日
  20 + </div>
  21 + <input type="date" name="birthday" value="2011-12-13">
  22 + </div>
  23 + <div class="gender">
  24 + <div class="title">
  25 + 性<br>别
  26 + </div>
  27 + <div class="icon boy">
  28 + <span class="check {{#if gender}}checked{{/if}}" data-gender="{{#if gender}}1{{/if}}"></span>
  29 + </div>
  30 + <div class="icon girl">
  31 + <span class="check {{#unless gender}}checked{{/if}}" data-gender="{{#if gender}}0{{/if}}"></span>
  32 + </div>
  33 + <input type="hidden" name="gender" id="gender" value="{{gender}}">
  34 + </div>
  35 + </form>
  36 +
  37 + <div class="footer">
  38 + <div class="submit">
  39 + 开始测试
  40 + </div>
  41 + </div>
  42 +
  43 + <div class="mask hide">
  44 + <div class="modal">
  45 + <div class="icon close"></div>
  46 + <div class="text">
  47 + 你还没有<br>完善信息哦
  48 + </div>
  49 + <div class="btn close">
  50 + 现在就完善
  51 + </div>
  52 + </div>
  53 + </div>
  54 + </div>
  55 +{{> cuxiao/yuanxiao/footer}}
  1 +{{> cuxiao/yuanxiao/header}}
  2 + <div class="main-wrap result">
  3 + <div class="flower flower-l"></div>
  4 + <div class="flower flower-r"></div>
  5 +
  6 + <div class="title">
  7 + <p>
  8 + {{result.name}}
  9 + </p>
  10 + 2016年潮流运势是
  11 + </div>
  12 +
  13 + <div class="hr">
  14 + </div>
  15 +
  16 + <div class="type {{result.type}}" data-type="{{result.type}}">
  17 +
  18 + </div>
  19 +
  20 + <div class="footer">
  21 + <div class="share">
  22 + 分享2016年潮流运势
  23 + </div>
  24 + </div>
  25 + </div>
  26 +{{> cuxiao/yuanxiao/type}}
  27 +{{> cuxiao/yuanxiao/footer}}
  1 +{{> cuxiao/yuanxiao/header}}
  2 + <div class="main-wrap share">
  3 + <div class="header"></div>
  4 + <div class="flower flower-l"></div>
  5 + <div class="flower flower-r"></div>
  6 +
  7 + <div class="title">
  8 + <p>
  9 + {{result.name}}
  10 + </p>
  11 + 2016年潮流运势是
  12 + </div>
  13 +
  14 + <div class="type {{result.type}}" data-type="{{result.type}}">
  15 +
  16 + </div>
  17 +
  18 + <div class="count">
  19 + 已有{{count}}人参与
  20 + </div>
  21 +
  22 + <div class="footer">
  23 + <a class="entry" href="/cuxiao/yuanxiao/index">
  24 + 我也要测
  25 + </a>
  26 + </div>
  27 + </div>
  28 +{{> cuxiao/yuanxiao/type}}
  29 +{{> cuxiao/yuanxiao/footer}}
  1 +{{> cuxiao/yuanxiao/header}}
  2 + <div class="main-wrap wait">
  3 + <div class="flower flower-l"></div>
  4 + <div class="flower flower-r"></div>
  5 +
  6 + <div class="tip">
  7 + 正在分析你的<br>潮流运势<br>…
  8 + </div>
  9 +
  10 + <div class="loading animated infinite rotateIn">
  11 + </div>
  12 + <div class="hat">
  13 + </div>
  14 +
  15 + <div class="footer">
  16 + </div>
  17 + </div>
  18 + <script type="text/javascript">
  19 + setTimeout(function (){
  20 + location.href = "/cuxiao/yuanxiao/result";
  21 + }, 2000);
  22 + </script>
  23 +{{> cuxiao/yuanxiao/footer}}
  1 +<script type="text/javascript" src="{{staticFile}}/js/libs.js"></script>
  2 +{{#staticJS}}
  3 +<script type="text/javascript" src="{{../staticFile}}/js/{{.}}"></script>
  4 +{{/staticJS}}
  5 +</body>
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5 + <meta charset="utf-8">
  6 + <title>{{staticTitle}}</title>
  7 + <!-- <meta name="apple-mobile-web-app-title" content="SUMMER SALE"> -->
  8 + <meta name="format-detection" content="telephone=no">
  9 + <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">
  10 + <meta name="apple-mobile-web-app-capable" content="yes">
  11 + <meta name="apple-mobile-web-app-status-bar-style" content="grey">
  12 + <script type="text/javascript">
  13 + (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);
  14 + </script>
  15 + <link rel="stylesheet" href="{{staticFile}}/css/style.css">
  16 +</head>
  17 +<body>
  1 +<script type="text/tmpl" id="P1">
  2 + <div class="bg-guang"></div>
  3 + <div class="bg-yuan"></div>
  4 + <div class="title">成为一个大写加粗的</div>
  5 + <div class="chaoren animated infinite pulse"></div>
  6 +</script>
  7 +<script type="text/tmpl" id="P2">
  8 + <div class="bg-bige animated zoomIn"></div>
  9 + <div class="bg-manzai animated zoomIn"></div>
  10 + <div class="bg-ren"></div>
  11 + <div class="title animated infinite pulse"></div>
  12 + <div class="yzbb animated slideInDown"></div>
  13 +</script>
  14 +<script type="text/tmpl" id="P3">
  15 + <div class="bg-yunqi animated zoomIn"></div>
  16 + <div class="shoes animated infinite swing"></div>
  17 + <div class="yeezy animated slideInDown"></div>
  18 +</script>
  19 +<script type="text/tmpl" id="P4">
  20 + <div class="bg-car"></div>
  21 + <div class="hands animated infinite swing"></div>
  22 + <div class="wanghong animated slideInRight"></div>
  23 +</script>
  24 +<script type="text/tmpl" id="M1">
  25 + <div class="bg-majia"></div>
  26 + <div class="bg-yifei animated slideInUp"></div>
  27 + <div class="flyman animated infinite "></div>
  28 +</script>
  29 +<script type="text/tmpl" id="M2">
  30 + <div class="bg-bamei animated slideInRight"></div>
  31 + <div class="meizi animated infinite swing"></div>
  32 + <div class="shoes"></div>
  33 +</script>
  34 +<script type="text/tmpl" id="M3">
  35 + <div class="bg-cloud1 animated slideInRight"></div>
  36 + <div class="bg-chuanzhe animated slideInLeft"></div>
  37 + <div class="shan"></div>
  38 + <div class="rensheng"></div>
  39 + <div class="cloud2 animated slideInRight"></div>
  40 + <div class="shoes animated infinite swing"></div>
  41 +</script>
  42 +<script type="text/tmpl" id="M4">
  43 + <div class="bg-guang"></div>
  44 + <div class="bg-jin1 animated slideInright"></div>
  45 + <div class="ren"></div>
  46 + <div class="jin2 animated slideInDown"></div>
  47 + <div class="jin3 animated slideInDown"></div>
  48 + <div class="shuaiqi animated slideInDown"></div>
  49 +</script>
  50 +<script type="text/tmpl" id="F1">
  51 + <div class="bg-hezi1 animated slideInLeft"></div>
  52 + <div class="bg-hezi2 animated slideInDown"></div>
  53 + <div class="bg-hezi3 animated slideInRight"></div>
  54 + <div class="sun animated infinite zoomIn"></div>
  55 + <div class="kuaidi animated slideInDown"></div>
  56 +</script>
  57 +<script type="text/tmpl" id="F2">
  58 + <div class="bg-love1 animated infinite zoomIn"></div>
  59 + <div class="bg-love2"></div>
  60 + <div class="boy animated slideInRight"></div>
  61 + <div class="girl animated slideInLeft"></div>
  62 + <div class="bidong animated slideInRight"></div>
  63 +</script>
  64 +<script type="text/tmpl" id="F3">
  65 + <div class="bg-bra animated infinite pulse"></div>
  66 + <div class="xiongda animated zoomIn"></div>
  67 +</script>
  68 +<script type="text/tmpl" id="F4">
  69 + <div class="bg-guang animated infinite zoomIn"></div>
  70 + <div class="bg-shoes1 animated slideInLeft"></div>
  71 + <div class="bg-shoes2 animated slideInRight"></div>
  72 + <div class="bg-shoes3 animated slideInDown"></div>
  73 + <div class="style animated slideInUp"></div>
  74 +</script>
1 <?php 1 <?php
2 2
3 use Action\HuodongAction; 3 use Action\HuodongAction;
4 -use Index\UserModel; 4 +use Cuxiao\YuanxiaoModel;
5 use Plugin\Helpers; 5 use Plugin\Helpers;
6 6
7 /** 7 /**
@@ -9,55 +9,163 @@ use Plugin\Helpers; @@ -9,55 +9,163 @@ use Plugin\Helpers;
9 */ 9 */
10 class YuanxiaoController extends HuodongAction 10 class YuanxiaoController extends HuodongAction
11 { 11 {
  12 + const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016yuanxiao/1.0.0';
  13 + const ENCRYPT_KEY = 'iamgtskkwhoareyou';
  14 +
12 /** 15 /**
13 - * 元宵抽签 16 + * 通过当前用户审判是否跳到登录页
  17 + *
14 */ 18 */
15 - public function indexAction() 19 + private function auditJumpLogin()
16 { 20 {
17 - //获取登录者ID,未登录返回false  
18 $uid = $this->getLoggedUid(); 21 $uid = $this->getLoggedUid();
19 if (!$uid || !is_numeric($uid)) { 22 if (!$uid || !is_numeric($uid)) {
20 - //未登录的用户访问,跳转到登录页面。并且在登陆后跳转回本页面  
21 - $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/newyear/coupon')), 'default')); 23 + $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
  24 + }
22 } 25 }
23 26
  27 + /**
  28 + * 元宵抽签
  29 + */
  30 + public function indexAction()
  31 + {
24 // 该变量用来控制和显示页面的弹出提示 32 // 该变量用来控制和显示页面的弹出提示
25 $showPopupFlag = '0'; 33 $showPopupFlag = '0';
26 34
27 - $userData = UserModel::getUserProfileData($uid);  
28 -  
29 - $result = array();  
30 - if (isset($result['code'])) {  
31 - switch (intval($result['code'])) {  
32 - case 200: // 领取成功, 发送站内信消息  
33 - $showPopupFlag = '0';  
34 - $this->sendMessage($uid, '【优惠券】您有1000元套券', '尊敬的客户:恭喜您成功获得1000元套券 !您可以在个人中心的交易管理中查看‘我的优惠券’。');  
35 - break;  
36 - case 201: // 已领取过, 提示重复领券  
37 - $showPopupFlag = '1';  
38 - break;  
39 - default: // 领取失败, 提示领券失败  
40 - $showPopupFlag = '2';  
41 - break;  
42 - }  
43 - }  
44 -  
45 - $this->_view->display('coupon', array(  
46 - 'staticTitle' => 'YOHO!BUY有货新年寻宝大作战', 35 + $this->_view->display('index', array(
  36 + 'staticTitle' => '元宵抽签',
  37 + 'staticFile' => self::STATIC_FILE,
47 'weixinShare' => $this->_isApp ? false : true, // 是否需要微信分享 38 'weixinShare' => $this->_isApp ? false : true, // 是否需要微信分享
48 'shareLink' => 'http://feature.yoho.cn/2016lishifeng/index.html', 39 'shareLink' => 'http://feature.yoho.cn/2016lishifeng/index.html',
49 'shareTitle' => 'YOHO!BUY有货新年寻宝大作战,千元利是等你赢!', 40 'shareTitle' => 'YOHO!BUY有货新年寻宝大作战,千元利是等你赢!',
50 'shareDesc' => 'YOHO!BUY有货,全球800+潮流品牌每日上新!', 41 'shareDesc' => 'YOHO!BUY有货,全球800+潮流品牌每日上新!',
51 'shareImg' => 'http://img12.static.yhbimg.com/couponImg/2015/12/30/12/02008a9724b898dee56852de9f1a3978bf.jpg', 42 'shareImg' => 'http://img12.static.yhbimg.com/couponImg/2015/12/30/12/02008a9724b898dee56852de9f1a3978bf.jpg',
52 'showPopupFlag' => $showPopupFlag, 43 'showPopupFlag' => $showPopupFlag,
53 - 'useData' => $userData,  
54 - 'bannerUrl_1' => 'http://m.yohobuy.com/boys?openby:yohobuy={"action":"go.home","params":{"channel":"1"}}',  
55 - 'bannerUrl_2' => 'http://m.yohobuy.com/girls?openby:yohobuy={"action":"go.home","params":{"channel":"2"}}',  
56 - 'bannerUrl_3' => 'http://m.yohobuy.com/kids?openby:yohobuy={"action":"go.home","params":{"channel":"3"}}',  
57 - 'bannerUrl_4' => 'http://m.yohobuy.com/lifestyle?openby:yohobuy={"action":"go.home","params":{"channel":"4"}}',  
58 - 'playAgain' => 'http://feature.yoho.cn/2016lishifeng/index.html',  
59 - 'appUrl_1' => 'http://www.yohoshow.com/about/index/yohobuyqr',  
60 - 'appUrl_2' => 'http://www.yohoshow.com/about/index/yohoboysqr', 44 + ));
  45 + }
  46 +
  47 + /**
  48 + * 元宵抽签 信息
  49 + */
  50 + public function infoAction()
  51 + {
  52 + // 审判跳转登录页
  53 + $this->auditJumpLogin();
  54 +
  55 + // POST提交请求
  56 + if (!empty($this->post())) {
  57 + $birthday = $this->post('birthday', '');
  58 + $gender = $this->post('gender', 0);
  59 +
  60 + // 调用接口
  61 + $result = array(
  62 + 'code' => 200,
  63 + 'data' => array(
  64 + 'name' => '李四',
  65 + 'type' => 'P1',
  66 + 'count' => 8888
  67 + )
  68 + );
  69 + if ($result['code'] === 200) { // 处理成功就跳转到等待页
  70 + // 将返回的结果存入cookeie中15分钟
  71 + $this->setCookie('yuanxiaochouqian', json_encode($result['data']), time() + 15*60);
  72 + $this->go(Helpers::url('/cuxiao/yuanxiao/wait'));
  73 + } else { // 不成功就显示返回的错误信息
  74 + $this->_view->display('info', array(
  75 + 'staticTitle' => '元宵抽签',
  76 + 'staticFile' => self::STATIC_FILE,
  77 + 'staticJS' => array(
  78 + 'info.js'
  79 + ),
  80 + 'birthday' => $birthday,
  81 + 'gender' => $gender,
  82 + 'message' => $result['message']
  83 + ));
  84 + }
  85 + } else {
  86 + $uid = $this->getUid();
  87 + $userData = YuanxiaoModel::getUserProfileData($uid);
  88 +
  89 + $this->_view->display('info', array(
  90 + 'staticTitle' => '元宵抽签',
  91 + 'staticFile' => self::STATIC_FILE,
  92 + 'staticJS' => array(
  93 + 'info.js'
  94 + ),
  95 + 'birthday' => $userData['birthday'],
  96 + 'gender' => $userData['gender'],
  97 + ));
  98 + }
  99 + }
  100 +
  101 + /**
  102 + * 元宵抽签 等待
  103 + */
  104 + public function waitAction()
  105 + {
  106 + // 审判跳转登录页
  107 + $this->auditJumpLogin();
  108 +
  109 + $this->_view->display('wait', array(
  110 + 'staticTitle' => '元宵抽签',
  111 + 'staticFile' => self::STATIC_FILE
  112 + ));
  113 + }
  114 +
  115 + /**
  116 + * 元宵抽签 结果
  117 + */
  118 + public function resultAction()
  119 + {
  120 + // 审判跳转登录页
  121 + $this->auditJumpLogin();
  122 +
  123 + $result = $this->getCookie('yuanxiaochouqian', null);
  124 + if (empty($result)) { // 未取到信息就重新测试
  125 + $this->go(Helpers::url('/cuxiao/yuanxiao/info'));
  126 + }
  127 + // cookie中存的结果
  128 + $result = json_decode($result, true);
  129 + $shareUrl = Helpers::url('/cuxiao/yuanxiao/share', array(
  130 + 'name' => $this->encrypt($result['name']),
  131 + 'hash' => $this->encrypt($this->getUid())
  132 + ));
  133 +
  134 + $this->_view->display('result', array(
  135 + 'staticTitle' => '元宵抽签',
  136 + 'staticFile' => self::STATIC_FILE,
  137 + 'result' => $result,
  138 + 'shareUrl' => $shareUrl,
  139 + 'staticJS' => array(
  140 + 'result.js'
  141 + )
  142 + ));
  143 + }
  144 +
  145 + /**
  146 + * 元宵抽签 分享
  147 + */
  148 + public function shareAction()
  149 + {
  150 + // 昵称从url中解析
  151 + $name = $this->decrypt($this->get('name', ''));
  152 + // 用户UID
  153 + $uid = $this->decrypt($this->get('hash', ''));
  154 +
  155 + // 调用接口获取type和count
  156 + $result = array('type' => 'M1', 'count' => 9887);
  157 +
  158 + $this->_view->display('share', array(
  159 + 'staticTitle' => '元宵抽签',
  160 + 'staticFile' => self::STATIC_FILE,
  161 + 'result' => array(
  162 + 'name' => $name,
  163 + 'type' => $result['type']
  164 + ),
  165 + 'count' => $result['count'],
  166 + 'staticJS' => array(
  167 + 'share.js'
  168 + )
61 )); 169 ));
62 } 170 }
63 171
@@ -68,8 +176,6 @@ class YuanxiaoController extends HuodongAction @@ -68,8 +176,6 @@ class YuanxiaoController extends HuodongAction
68 */ 176 */
69 private function getLoggedUid() 177 private function getLoggedUid()
70 { 178 {
71 - // 判断是否是应用访问, 拼接APP需要的URL参数  
72 - $this->_isApp = (null !== $this->get('app_version') || null !== $this->get('uid'));  
73 if ($this->_isApp) { 179 if ($this->_isApp) {
74 $uid = $this->get('uid'); 180 $uid = $this->get('uid');
75 } else { 181 } else {
@@ -78,4 +184,72 @@ class YuanxiaoController extends HuodongAction @@ -78,4 +184,72 @@ class YuanxiaoController extends HuodongAction
78 184
79 return $uid; 185 return $uid;
80 } 186 }
  187 +
  188 + /**
  189 + * 加密字符串
  190 + *
  191 + * @param string $data 需要加密的字符串
  192 + * @return string 加密之后的字符串
  193 + */
  194 + private function encrypt($data)
  195 + {
  196 + $data = strval($data);
  197 + $key = md5(self::ENCRYPT_KEY);
  198 + $x = 0;
  199 + $len = strlen($data);
  200 + $l = strlen($key);
  201 + $char = '';
  202 + $str = '';
  203 +
  204 + for ($i = 0; $i < $len; $i++) {
  205 + if ($x == $l)
  206 + {
  207 + $x = 0;
  208 + }
  209 + $char .= $key{$x};
  210 + $x++;
  211 + }
  212 +
  213 + for ($i = 0; $i < $len; $i++) {
  214 + $str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
  215 + }
  216 +
  217 + return base64_encode($str);
  218 + }
  219 +
  220 + /**
  221 + * 解密字符串
  222 + *
  223 + * @param string $data 需要解密的字符串
  224 + * @return string 解密之后的字符串
  225 + */
  226 + private function decrypt($data)
  227 + {
  228 + $key = md5(self::ENCRYPT_KEY);
  229 + $x = 0;
  230 + $data = base64_decode($data);
  231 + $len = strlen($data);
  232 + $l = strlen($key);
  233 + $char = '';
  234 + $str = '';
  235 +
  236 + for ($i = 0; $i < $len; $i++) {
  237 + if ($x == $l)
  238 + {
  239 + $x = 0;
  240 + }
  241 + $char .= substr($key, $x, 1);
  242 + $x++;
  243 + }
  244 +
  245 + for ($i = 0; $i < $len; $i++) {
  246 + if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
  247 + $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
  248 + } else {
  249 + $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
  250 + }
  251 + }
  252 +
  253 + return $str;
  254 + }
81 } 255 }