Authored by Rock Zhang

Merge branch 'feature/wap/yuanxiao' into develop/wap

... ... @@ -42,6 +42,13 @@ class HuodongAction extends Controller_Abstract
protected $_data;
/**
* 是否是应用访问标志位
*
* @var boolean
*/
protected $_isApp;
/**
* 初始化
*/
public function init()
... ... @@ -58,6 +65,9 @@ class HuodongAction extends Controller_Abstract
if (isset($config->css->url)) {
$this->_view->assign('imgUrl', $config->img->url);
}
// 判断是否是应用访问, 拼接APP需要的URL参数
$this->_isApp = (null !== $this->get('app_version') || null !== $this->get('uid'));
}
/**
... ... @@ -196,7 +206,7 @@ class HuodongAction extends Controller_Abstract
* @param string $name cookie的名字
* @param string $value cookie的值
* @param integer $expire cookie过期时间
* @param integer $path cookie可用的路径
* @param string $path cookie可用的路径
* @param string $domain cookie可用域名
*/
protected function setCookie($name, $value, $expire = 0, $path = '/', $domain = '.yohobuy.com')
... ...
... ... @@ -2,6 +2,7 @@
namespace LibModels\Wap\Cuxiao;
use Api\Sign;
use Api\Yohobuy;
/**
... ... @@ -69,9 +70,35 @@ class ActivityData
}
/**
* @param int $uid 用户UID
* @param string $nickName 用户昵称
* @param string $birthday 用户生日
* @param int $gender 用户性别
* @return mixed 抽签的结果
*/
public static function getYuanxiaoInfo($uid, $nickName, $birthday, $gender)
{
$param = Yohobuy::param();
$param['method'] = 'wap.activity.draw';
$param['uid'] = $uid;
$param['nick_name'] = $nickName;
$param['birthday'] = $birthday;
$param['gender'] = $gender;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 发送站内信
*
* @param int $activityId 活动ID
* @param int $uid
* @param string $title
* @param int $content
* @param int $type
* @param string $verify_key
* @param int $send_uid
* @param string $call_back
* @return array
*/
public static function message($uid, $title, $content, $type = 1, $verify_key = '', $send_uid = 0, $call_back = '')
... ...
... ... @@ -21,7 +21,6 @@ class UserData
* 个人详情数据
*
* @param int $uid 用户ID
* @param int $udid 客户端唯一标识
* @return array 个人详情接口返回的数据
*/
public static function userData($uid)
... ...
<!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>
</body>
<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>
{{> 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="{{birthday}}">
</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}}2{{/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
namespace Cuxiao;
use LibModels\Wap\Cuxiao\ActivityData;
use LibModels\Wap\Home\UserData;
/**
* Created by PhpStorm.
* User: Gtskk
* Date: 2016/2/18
* Time: 16:26
*
* @name YuanxiaoModel
* @package models/Cuxiao
* @author Gtskk(tttt6399998@126.com)
*/
class YuanxiaoModel
{
/**
* 处理用户详情数据
*
* @param int $uid 用户ID
* @return array|mixed 处理之后的个人详情数据
*/
public static function getUserProfileData($uid)
{
$result = array(
'birthday' => '2000-01-01',
'gender' => 2
);
// 调用接口获取个人详情
$userData = UserData::userData($uid);
// 处理个人详情数
if (isset($userData['data']) && !empty($userData['data'])) {
$result['birthday'] = $userData['data']['birthday'] ?: '2000-01-01';
$result['gender'] = $userData['data']['gender'] == 1 ? '男' : '女';
}
return $result;
}
/**
* @param int $uid 用户UID
* @param sring $nickName 用户昵称
* @param string $birthday 用户生日
* @param int $gender 用户性别
* @return array 处理之后抽签的结果
*/
public static function getChouqianInfo($uid, $nickName, $birthday, $gender)
{
$result = array('code' => 400, 'message' => '出错啦~');
do {
if (empty($uid)) {
break;
}
if (empty($nickName)) {
$result['message'] = '昵称不能为空';
break;
}
if (empty($birthday)) {
$result['message'] = '生日不能为空';
break;
}
if (empty($gender)) {
$result['message'] = '性别不能为空';
break;
}
$chouqian = ActivityData::getYuanxiaoInfo($uid, $nickName, $birthday, $gender);
if ($chouqian) {
$result = $chouqian;
}
} while (false);
return $result;
}
}
\ No newline at end of file
... ...
... ... @@ -11,7 +11,7 @@ use LibModels\Wap\Cuxiao\ActivityData;
class ChristmasController extends HuodongAction
{
private $_isApp = false;
// private $_isApp = false;
/**
* 备注:2015年12月11号上线
... ...
<?php
use Action\HuodongAction;
use Cuxiao\YuanxiaoModel;
use Plugin\Helpers;
use LibModels\Wap\Cuxiao\ActivityData;
use Api\Yohobuy;
/**
* 元宵抽签活动
*/
class YuanxiaoController extends HuodongAction
{
// const STATIC_FILE = 'http://localhost:2222/assets/1.0.1';
const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016yuanxiao/1.0.1';
const ENCRYPT_KEY = 'iamgtskkwhoareyou';
/**
* 通过当前用户审判是否跳到登录页
*
*/
private function auditJumpLogin()
{
$uid = $this->getLoggedUid();
if (!$uid || !is_numeric($uid)) {
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
}
}
/**
* 元宵抽签
*/
public function indexAction()
{
// 该变量用来控制和显示页面的弹出提示
$showPopupFlag = '0';
$this->_view->display('index', array(
'staticTitle' => '元宵抽签'
'staticTitle' => '元宵抽签',
'staticFile' => self::STATIC_FILE,
'staticJS' => array(
'home.js'
),
'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,
));
}
/**
* 元宵抽签 信息
*/
public function infoAction()
{
// 审判跳转登录页
$this->auditJumpLogin();
$uid = $this->getUid();
// POST提交请求
if (!empty($this->post())) {
$nickName = $this->post('nick', '');
$birthday = $this->post('birthday', '');
$gender = $this->post('gender', 0);
// 调用接口
$result = YuanxiaoModel::getChouqianInfo($uid, $nickName, $birthday, $gender);
$result['code'] = 200;
$result['data'] = array('name' => '王五', 'type' => 'M2');
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 {
$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,
'staticJS' => array(
'wait.js'
),
));
}
/**
* 元宵抽签 结果
*/
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())
));
$result['type'] = $this->get('type', 'M2');
$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'
)
));
}
/**
* 检测登录状态
*
* @return int
*/
private function getLoggedUid()
{
if ($this->_isApp) {
$uid = $this->get('uid');
} else {
$uid = $this->getUid();
}
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;
}
}
... ...