Authored by hf

code review by fei.hong : do format yuchouqian huodong

@@ -40,6 +40,13 @@ class HuodongAction extends Controller_Abstract @@ -40,6 +40,13 @@ class HuodongAction extends Controller_Abstract
40 * @var array 40 * @var array
41 */ 41 */
42 protected $_data; 42 protected $_data;
  43 +
  44 + /**
  45 + * 是否是APP访问
  46 + *
  47 + * @var bool
  48 + */
  49 + protected $_isApp;
43 50
44 /** 51 /**
45 * 初始化 52 * 初始化
@@ -58,6 +65,8 @@ class HuodongAction extends Controller_Abstract @@ -58,6 +65,8 @@ class HuodongAction extends Controller_Abstract
58 if (isset($config->css->url)) { 65 if (isset($config->css->url)) {
59 $this->_view->assign('imgUrl', $config->img->url); 66 $this->_view->assign('imgUrl', $config->img->url);
60 } 67 }
  68 +
  69 + $this->_isApp = (null !== $this->get('app_version') || null !== $this->get('uid'));
61 } 70 }
62 71
63 /** 72 /**
@@ -20,6 +20,9 @@ class ActivityData @@ -20,6 +20,9 @@ class ActivityData
20 const URI_GET_NAMED_COUPON = 'event/api/v1/activity/getCoupon'; 20 const URI_GET_NAMED_COUPON = 'event/api/v1/activity/getCoupon';
21 const URI_GET_ALL_COUPON = 'event/api/v1/activity/getCoupon'; 21 const URI_GET_ALL_COUPON = 'event/api/v1/activity/getCoupon';
22 const URI_SEND_MESSAGE = 'inbox/service/v1/inbox'; 22 const URI_SEND_MESSAGE = 'inbox/service/v1/inbox';
  23 + const URI_YUANXIAO_CHOUQIAN = 'union/ActivityRest/draw';
  24 + const URI_YUANXIAO_CHOUQIAN_SHARE = 'union/ActivityRest/getDrawInfo';
  25 + const URL_YUANXIAO_API = 'http://union.yoho.cn/';
23 26
24 /** 27 /**
25 * 用户获取某个活动指定的单个优惠券 28 * 用户获取某个活动指定的单个优惠券
@@ -69,16 +72,58 @@ class ActivityData @@ -69,16 +72,58 @@ class ActivityData
69 } 72 }
70 73
71 /** 74 /**
  75 + * 获取元宵抽签的结果
  76 + *
  77 + * @param int $uid 用户UID
  78 + * @param string $nickName 用户昵称
  79 + * @param string $birthday 用户生日
  80 + * @param int $gender 用户性别
  81 + * @return mixed 抽签的结果
  82 + */
  83 + public static function getYuanxiaoInfo($uid, $nickName, $birthday, $gender)
  84 + {
  85 + $param = array();
  86 + $param['method'] = 'wap.activity.draw';
  87 + $param['uid'] = $uid;
  88 + $param['nickname'] = $nickName;
  89 + $param['birthday'] = $birthday;
  90 + $param['gender'] = $gender;
  91 +
  92 + return Yohobuy::jsonPost(self::URL_YUANXIAO_API . self::URI_YUANXIAO_CHOUQIAN, $param);
  93 + }
  94 +
  95 + /**
  96 + * 获取分享结果页元宵抽签的结果
  97 + *
  98 + * @param int $uid 用户UID
  99 + * @return mixed 抽签的结果
  100 + */
  101 + public static function getYuanxiaoShareInfo($uid)
  102 + {
  103 + $param = array();
  104 + $param['method'] = 'wap.activity.draw';
  105 + $param['uid'] = $uid;
  106 +
  107 + return Yohobuy::jsonPost(self::URL_YUANXIAO_API . self::URI_YUANXIAO_CHOUQIAN_SHARE, $param);
  108 + }
  109 +
  110 + /**
72 * 发送站内信 111 * 发送站内信
73 - *  
74 - * @param int $activityId 活动ID 112 + *
  113 + * @param int $uid
  114 + * @param string $title
  115 + * @param int $content
  116 + * @param int $type
  117 + * @param string $verify_key
  118 + * @param int $send_uid
  119 + * @param string $call_back
75 * @return array 120 * @return array
76 */ 121 */
77 public static function message($uid, $title, $content, $type = 1, $verify_key = '', $send_uid = 0, $call_back = '') 122 public static function message($uid, $title, $content, $type = 1, $verify_key = '', $send_uid = 0, $call_back = '')
78 { 123 {
79 //调用接口发送站内信 124 //调用接口发送站内信
80 return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_SEND_MESSAGE, 'setSingleMessage', array( 125 return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_SEND_MESSAGE, 'setSingleMessage', array(
81 - $uid, $title, $content, $type, $verify_key, $send_uid, $call_back 126 + $uid, $title, $content, $type, $verify_key, $send_uid, $call_back
82 )); 127 ));
83 } 128 }
84 129
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>
  7 + </div>
  8 + <a class="start" href="{{playUrl}}"></a>
  9 + <div class="footer">
  10 + <a class="arrow animated infinite pulse" href="{{playUrl}}"></a>
  11 + <div class="yohobuy"></div>
  12 + </div>
19 </div> 13 </div>
20 -</body> 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 + {{#if message}}
  11 + <div class="err-tip">
  12 + 活动太火爆,请稍后再试
  13 + </div>
  14 + {{else}}
  15 + <form class="user" method="POST">
  16 + <div class="user-info nick">
  17 + <div class="title">
  18 + 昵称
  19 + </div>
  20 + <input type="text" name="nick" placeholder="请输入您帅气的名字!" value="" maxlength="20">
  21 + </div>
  22 + <div class="user-info birthday">
  23 + <div class="title">
  24 + 生日
  25 + </div>
  26 + <input class="birthday-picker" type="text" name="birthday" value="{{birthday}}" data-number="{{birthdayNumber}}" readonly>
  27 + </div>
  28 + <div class="gender">
  29 + <div class="title">
  30 + 性<br>别
  31 + </div>
  32 + <div class="icon boy">
  33 + <span class="check {{#if isBoy}}checked{{/if}}" data-gender="1"></span>
  34 + </div>
  35 + <div class="icon girl">
  36 + <span class="check {{#unless isBoy}}checked{{/if}}" data-gender="2"></span>
  37 + </div>
  38 + <input type="hidden" name="gender" id="gender" value="{{gender}}">
  39 + </div>
  40 + </form>
  41 +
  42 + <div class="footer">
  43 + <div class="submit">
  44 + 开始测试
  45 + </div>
  46 + </div>
  47 +
  48 + {{/if}}
  49 +
  50 + <div class="mask hide">
  51 + <div class="modal">
  52 + <div class="icon close"></div>
  53 + <div class="text">
  54 + 请输入您
  55 + <br>
  56 + 帅气的名字!
  57 + </div>
  58 + <div class="btn close">
  59 + 现在就完善
  60 + </div>
  61 + </div>
  62 + </div>
  63 + </div>
  64 +<link rel="stylesheet" type="text/css" href="http://cdn.yoho.cn/huodong/2016yuanxiao/AnyPicker/dist/anypicker-all.min.css" />
  65 +{{> 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 + {{#if needShare}}
  22 + <div class="share">
  23 + 分享2016年潮流运势
  24 + </div>
  25 + {{/if}}
  26 + </div>
  27 +
  28 + <div class="mask hide">
  29 + <div class="share-icon">
  30 + </div>
  31 + </div>
  32 + </div>
  33 +
  34 +{{> cuxiao/yuanxiao/type}}
  35 +{{> 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">
  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 = '{{activityUrl}}';
  21 +
  22 + // location.href = '{{activityUrl}}?openby:yohobuy={"action":"go.h5","params":{"title":"元宵抽签","url":"{{activityUrl}}","share":"\/operations\/api\/v5\/webshare\/getShare","shareparam":{"share_id":"1"},"param":{"share_id":"1"}}}';
  23 + }, 2000);
  24 + </script>
  25 +{{> cuxiao/yuanxiao/footer}}
  1 +<input type="hidden" id="shareTitle" value="{{shareTitle}}">
  2 +<input type="hidden" id="shareDesc" value="{{shareDesc}}">
  3 +<input type="hidden" id="shareImg" value="{{shareImg}}">
  4 +<input type="hidden" id="shareLink" value="{{shareUrl}}">
  5 +<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
  6 +<script type="text/javascript" src="{{staticFile}}/js/libs.js"></script>
  7 +{{#staticJS}}
  8 +<script type="text/javascript" src="{{../staticFile}}/js/{{.}}"></script>
  9 +{{/staticJS}}
  10 +</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 flyIn "></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
  2 +
  3 +namespace Cuxiao;
  4 +use LibModels\Wap\Cuxiao\ActivityData;
  5 +use LibModels\Wap\Home\UserData;
  6 +
  7 +/**
  8 + * Created by PhpStorm.
  9 + * User: Gtskk
  10 + * Date: 2016/2/18
  11 + * Time: 16:26
  12 + *
  13 + * @name YuanxiaoModel
  14 + * @package models/Cuxiao
  15 + * @author Gtskk(tttt6399998@126.com)
  16 + */
  17 +class YuanxiaoModel
  18 +{
  19 + /**
  20 + * 处理用户详情数据
  21 + *
  22 + * @param int $uid 用户ID
  23 + * @return array|mixed 处理之后的个人详情数据
  24 + */
  25 + public static function getUserProfileData($uid)
  26 + {
  27 + $result = array(
  28 + 'birthday' => '2000-01-01',
  29 + 'gender' => 2
  30 + );
  31 +
  32 + // 调用接口获取个人详情
  33 + $userData = UserData::userData($uid, false);
  34 +
  35 + // 处理个人详情数
  36 + if (isset($userData['data']) && !empty($userData['data'])) {
  37 + $result['birthday'] = $userData['data']['birthday'] ?: '2000-01-01';
  38 + $result['gender'] = $userData['data']['gender'];
  39 + }
  40 +
  41 + return $result;
  42 + }
  43 +
  44 + /**
  45 + * @param int $uid 用户UID
  46 + * @param sring $nickName 用户昵称
  47 + * @param string $birthday 用户生日
  48 + * @param int $gender 用户性别
  49 + * @return array 处理之后抽签的结果
  50 + */
  51 + public static function getChouqianInfo($uid, $nickName, $birthday, $gender)
  52 + {
  53 + $result = array('code' => 400, 'message' => '出错啦~');
  54 +
  55 + do {
  56 + if (empty($uid)) {
  57 + break;
  58 + }
  59 +
  60 + if (empty($nickName)) {
  61 + $result['message'] = '昵称不能为空';
  62 + break;
  63 + }
  64 +
  65 + if (empty($birthday)) {
  66 + $result['message'] = '生日不能为空';
  67 + break;
  68 + }
  69 +
  70 + if (empty($gender)) {
  71 + $result['message'] = '性别不能为空';
  72 + break;
  73 + }
  74 +
  75 + $chouqian = ActivityData::getYuanxiaoInfo($uid, $nickName, $birthday, $gender);
  76 + if ($chouqian) {
  77 + $result = $chouqian;
  78 + }
  79 + } while (false);
  80 +
  81 + return $result;
  82 + }
  83 +
  84 + /**
  85 + * @param int $uid 用户UID
  86 + * @return array|mixed 抽奖的结果
  87 + */
  88 + public static function getChoujiangShareInfo($uid)
  89 + {
  90 + $result = array('code' => 400, 'message' => '出错啦~');
  91 +
  92 + do {
  93 + if (empty($uid)) {
  94 + break;
  95 + }
  96 +
  97 + $chouqian = ActivityData::getYuanxiaoShareInfo($uid);
  98 + if (isset($chouqian['data'])) {
  99 + $result = array(
  100 + 'name' => $chouqian['data']['nickname'],
  101 + 'type' => $chouqian['data']['randomCode'],
  102 + 'total' => $chouqian['data']['total']
  103 + );
  104 + }
  105 + } while (false);
  106 +
  107 + return $result;
  108 + }
  109 +}
1 <?php 1 <?php
2 2
3 use Action\HuodongAction; 3 use Action\HuodongAction;
  4 +use Cuxiao\YuanxiaoModel;
4 use Plugin\Helpers; 5 use Plugin\Helpers;
5 -use LibModels\Wap\Cuxiao\ActivityData;  
6 -use Api\Yohobuy;  
7 6
8 /** 7 /**
9 * 元宵抽签活动 8 * 元宵抽签活动
10 */ 9 */
11 class YuanxiaoController extends HuodongAction 10 class YuanxiaoController extends HuodongAction
12 { 11 {
  12 + // const STATIC_FILE = 'http://localhost:2222/assets/1.1.3';
  13 + const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016yuanxiao/1.1.3';
  14 + const ENCRYPT_KEY = 'iamgtskkwhoareyou';
  15 +
  16 + /**
  17 + * 通过当前用户审判是否跳到登录页
  18 + *
  19 + */
  20 + private function auditJumpLogin()
  21 + {
  22 + $uid = $this->getLoggedUid();
  23 + if (!$uid || !is_numeric($uid)) {
  24 + $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
  25 + }
  26 + }
  27 +
13 /** 28 /**
14 * 元宵抽签 29 * 元宵抽签
15 */ 30 */
16 public function indexAction() 31 public function indexAction()
17 { 32 {
  33 + $playUrl = Helpers::url('/cuxiao/yuanxiao/info');
  34 + $playUrlEncode = strtr($playUrl, array('/' => '\\/'));
  35 +
18 $this->_view->display('index', array( 36 $this->_view->display('index', array(
19 - 'staticTitle' => '元宵抽签' 37 + 'staticTitle' => '2016潮流运势测试!',
  38 + 'staticFile' => self::STATIC_FILE,
  39 + 'staticJS' => array(
  40 + 'home.js'
  41 + ),
  42 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
  43 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
  44 + 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
  45 + 'playUrl' => $this->isApp() ? $playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}': $playUrl,
  46 + ));
  47 + }
  48 +
  49 + /**
  50 + * 元宵抽签 信息
  51 + */
  52 + public function infoAction()
  53 + {
  54 + $uid = $this->getLoggedUid();
  55 + if (!$uid) {
  56 + if (!$this->_isApp) {
  57 + $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
  58 + } else {
  59 + exit();
  60 + }
  61 + }
  62 +
  63 + // POST提交请求
  64 + $posts = $this->post();
  65 + if (!empty($posts)) {
  66 + $nickName = $this->post('nick', '');
  67 + $birthday = $this->post('birthday', '');
  68 + $gender = $this->post('gender', 1);
  69 +
  70 + // 格式化日期以便接口接收
  71 + $FormatBirthday = date_format(date_create_from_format('Y年m月d日', $birthday), 'Y-m-d');
  72 +
  73 + // 调用接口
  74 + $result = YuanxiaoModel::getChouqianInfo($uid, $nickName, $FormatBirthday, $gender);
  75 + if ($result['code'] === 200) { // 处理成功就跳转到等待页
  76 + // 将返回的结果存入cookeie中15分钟
  77 + $cookieData = array(
  78 + 'name' => $nickName,
  79 + 'type' => $result['data']['randomCode']
  80 + );
  81 + $this->setCookie('yuanxiaochouqian', json_encode($cookieData), time() + 15 * 60);
  82 + $this->go(Helpers::url('/cuxiao/yuanxiao/wait'));
  83 + } else { // 不成功就显示返回的错误信息
  84 + $this->_view->display('info', array(
  85 + 'staticTitle' => '2016潮流运势测试!',
  86 + 'staticFile' => self::STATIC_FILE,
  87 + 'staticJS' => array(
  88 + 'info.js'
  89 + ),
  90 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
  91 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
  92 + 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
  93 + 'birthday' => $birthday,
  94 + 'birthdayNumber' => $FormatBirthday,
  95 + 'gender' => $gender,
  96 + 'isBoy' => $gender == 1, // 性别是否是女标志位
  97 + 'message' => $result['message']
  98 + ));
  99 + }
  100 + } else {
  101 + $userData = YuanxiaoModel::getUserProfileData($uid);
  102 + // 接口返回空数据时,设置默认值
  103 + if (empty($userData['birthday']) || $userData['birthday'] === '0000-00-00') {
  104 + $userData = array(
  105 + 'birthday' => '1990-01-01',
  106 + 'gender' => '3',
  107 + );
  108 + }
  109 +
  110 + $this->_view->display('info', array(
  111 + 'staticTitle' => '2016潮流运势测试!',
  112 + 'staticFile' => self::STATIC_FILE,
  113 + 'staticJS' => array(
  114 + 'info.js'
  115 + ),
  116 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
  117 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
  118 + 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
  119 + 'birthday' => date_format(date_create($userData['birthday']), 'Y年m月d日'),
  120 + 'birthdayNumber' => $userData['birthday'],
  121 + 'gender' => $userData['gender'],
  122 + 'isBoy' => $userData['gender'] == 1 // 性别是否是女标志位
  123 + ));
  124 + }
  125 + }
  126 +
  127 + /**
  128 + * 元宵抽签 等待
  129 + */
  130 + public function waitAction()
  131 + {
  132 + // 审判跳转登录页
  133 + // $this->auditJumpLogin();
  134 +
  135 + $this->_view->display('wait', array(
  136 + 'staticTitle' => '2016潮流运势测试!',
  137 + 'staticFile' => self::STATIC_FILE,
  138 + 'activityUrl' => Helpers::url('/cuxiao/yuanxiao/result'),
  139 + 'staticJS' => array(
  140 + 'wait.js'
  141 + ),
  142 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
  143 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
  144 + 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
  145 + ));
  146 + }
  147 +
  148 + /**
  149 + * 元宵抽签 结果
  150 + */
  151 + public function resultAction()
  152 + {
  153 + // 审判跳转登录页
  154 + //$this->auditJumpLogin();
  155 +
  156 + $result = $this->getCookie('yuanxiaochouqian', null);
  157 + if (empty($result)) { // 未取到信息就重新测试
  158 + $this->go(Helpers::url('/cuxiao/yuanxiao/info'));
  159 + }
  160 +
  161 + // cookie中存的结果
  162 + $result = json_decode($result, true);
  163 + $shareUrl = Helpers::url('/cuxiao/yuanxiao/share', array(
  164 + 'hash' => $this->encrypt($this->getUid()),
  165 + 'type' => $this->encrypt($result['type'])
  166 + ));
  167 +
  168 + $this->_view->display('result', array(
  169 + 'staticTitle' => '2016潮流运势测试!',
  170 + 'needShare' => $this->checkNeedShare(), // 是否需要微信分享
  171 + 'staticFile' => self::STATIC_FILE,
  172 + 'result' => $result,
  173 + 'shareTitle' => $result['name'] . '的2016年潮流运势是' . $this->getChouqianTitle($result['type']),
  174 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
  175 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
  176 + 'shareUrl' => $shareUrl,
  177 + 'staticJS' => array(
  178 + 'result.js'
  179 + )
  180 + ));
  181 + }
  182 +
  183 + /**
  184 + * 元宵抽签 分享
  185 + */
  186 + public function shareAction()
  187 + {
  188 + // 用户UID
  189 + $uid = $this->decrypt($this->get('hash', ''));
  190 + if (empty($uid)) {
  191 + $this->go(Helpers::url('/cuxiao/yuanxiao/index'));
  192 + }
  193 + // 抽签结果
  194 + $type = $this->decrypt($this->get('type', ''));
  195 +
  196 + // 调用接口获取type和count
  197 + $result = YuanxiaoModel::getChoujiangShareInfo($uid);
  198 +
  199 + $this->_view->display('share', array(
  200 + 'staticTitle' => '2016潮流运势测试!',
  201 + 'staticFile' => self::STATIC_FILE,
  202 + 'result' => array(
  203 + 'name' => $result['name'],
  204 + 'type' => $type ?: $result['type']
  205 + ),
  206 + 'count' => $result['total'],
  207 + 'staticJS' => array(
  208 + 'share.js'
  209 + ),
  210 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
  211 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png'
20 )); 212 ));
21 } 213 }
  214 +
  215 + /**
  216 + * 根据结果类型获取抽签结果标题
  217 + * @param $type
  218 + */
  219 + private function getChouqianTitle($type)
  220 + {
  221 + $data = array(
  222 + 'P1' => '成为一个大写加粗的潮人!',
  223 + 'P2' => '逼格满载盐值爆表!',
  224 + 'P3' => '运气爆棚,拥有Yeezy不是梦!',
  225 + 'P4' => '街拍不断,成为网红不是梦!',
  226 + 'M1' => '穿着MA-1飞行夹克一飞冲天!',
  227 + 'M2' => '把妹不花钱!买鞋不排队!',
  228 + 'M3' => '穿着跑鞋到达人生巅峰!',
  229 + 'M4' => '帅气多金颜值高!',
  230 + 'F1' => '拥有拆不完的快递和礼物!',
  231 + 'F2' => '被男神强势壁咚!',
  232 + 'F3' => '腿细胸大屁股翘!',
  233 + 'F4' => '任何style都轻松驾驭!'
  234 + );
  235 +
  236 + return $data[$type];
  237 + }
  238 +
  239 + /**
  240 + * 检测登录状态
  241 + *
  242 + * @return int
  243 + */
  244 + private function getLoggedUid()
  245 + {
  246 + if ($this->_isApp) {
  247 + $uid = $this->get('uid');
  248 + } else {
  249 + $uid = $this->getUid();
  250 + }
  251 +
  252 + return $uid;
  253 + }
  254 +
  255 + /**
  256 + * 判断是否是APP访问
  257 + *
  258 + * @return bool
  259 + */
  260 + private function isApp()
  261 + {
  262 + return (null !== $this->get('app_version'));
  263 + }
  264 +
  265 + /**
  266 + * 判断是否需要微信分享
  267 + * @return bool
  268 + */
  269 + private function checkNeedShare()
  270 + {
  271 + if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false || $this->_isApp) {
  272 + return true;
  273 + }
  274 +
  275 + return false;
  276 + }
  277 +
  278 + /**
  279 + * 加密字符串
  280 + *
  281 + * @param string $data 需要加密的字符串
  282 + * @return string 加密之后的字符串
  283 + */
  284 + private function encrypt($data)
  285 + {
  286 + $data = strval($data);
  287 + $key = md5(self::ENCRYPT_KEY);
  288 + $x = 0;
  289 + $len = strlen($data);
  290 + $l = strlen($key);
  291 + $char = '';
  292 + $str = '';
  293 +
  294 + for ($i = 0; $i < $len; $i++) {
  295 + if ($x == $l) {
  296 + $x = 0;
  297 + }
  298 + $char .= $key{$x};
  299 + $x++;
  300 + }
  301 +
  302 + for ($i = 0; $i < $len; $i++) {
  303 + $str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
  304 + }
  305 +
  306 + return base64_encode($str);
  307 + }
  308 +
  309 + /**
  310 + * 解密字符串
  311 + *
  312 + * @param string $data 需要解密的字符串
  313 + * @return string 解密之后的字符串
  314 + */
  315 + private function decrypt($data)
  316 + {
  317 + $key = md5(self::ENCRYPT_KEY);
  318 + $x = 0;
  319 + $data = base64_decode($data);
  320 + $len = strlen($data);
  321 + $l = strlen($key);
  322 + $char = '';
  323 + $str = '';
  324 +
  325 + for ($i = 0; $i < $len; $i++) {
  326 + if ($x == $l) {
  327 + $x = 0;
  328 + }
  329 + $char .= substr($key, $x, 1);
  330 + $x++;
  331 + }
  332 +
  333 + for ($i = 0; $i < $len; $i++) {
  334 + if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
  335 + $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
  336 + } else {
  337 + $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
  338 + }
  339 + }
  340 +
  341 + return $str;
  342 + }
  343 +
22 } 344 }