Authored by hf

code review by fei.hong: do merge huodong girlday the four times

  1 +{{> cuxiao/girlsday-4/header}}
  2 + <div class="main-wrap home">
  3 + <div class="header">
  4 + </div>
  5 + {{#if tab}}
  6 + <div class="tab type">
  7 + {{#tab}}
  8 + <div class="tab-item" data-type="{{.}}"></div>
  9 + {{/tab}}
  10 + <input type="hidden" id="more-brand" value="{{moreBrand}}">
  11 + </div>
  12 + {{/if}}
  13 + <div class="content">
  14 + </div>
  15 + <script type="text/tmpl" id="tmpl">
  16 + <div class="coupons">
  17 + \{{#coupons}}
  18 + <a class="coupon" href="\{{../jumpUrl}}" data-id="\{{id}}">
  19 + <img class="lazy" src="" data-original="{{imgUrl}}/\{{img}}">
  20 + </a>
  21 + \{{/coupons}}
  22 + </div>
  23 + <div class="brands clearfix">
  24 + \{{#brands}}
  25 + <a class="brand" href='\{{url}}'>
  26 + <img class="lazy" src="" data-original="{{imgUrl}}/\{{img}}">
  27 + </a>
  28 + \{{/brands}}
  29 + <div class="after"></div>
  30 + </div>
  31 + <div class="more">
  32 + <div class="more-title">
  33 + </div>
  34 + <a class="link" href='\{{more.url}}'>
  35 + <img class="lazy" src="" data-original="{{imgUrl}}/\{{more.img}}">
  36 + </a>
  37 + </div>
  38 + </script>
  39 + </div>
  40 + <div class="footer">
  41 + </div>
  42 + <div class="tip-wrap hide">
  43 + <div class="tip hide fail">
  44 + <div class="title">
  45 + 领取失败<br>
  46 + 请刷新重新领取
  47 + </div>
  48 + <a class="button" href="">
  49 + 刷新
  50 + </a>
  51 + </div>
  52 + </div>
  53 +
  54 + <div class="tip-wrap hide">
  55 + <div class="tip hide success">
  56 + <div class="title">
  57 + 领取成功
  58 + </div>
  59 + <div class="sub-title">
  60 + 快去分享给更多<br>
  61 + 喜爱<span class="title">潮流</span>的小伙伴吧!
  62 + </div>
  63 + <a class="button close" href="">
  64 + 返回
  65 + </a>
  66 + </div>
  67 + </div>
  68 +
  69 + <div class="tip-wrap hide">
  70 + <div class="tip hide geted">
  71 + <div class="title">
  72 + 您已领取过了
  73 + </div>
  74 + <div class="sub-title">
  75 + 快去分享给更多<br>
  76 + 喜爱<span class="title">潮流</span>的小伙伴吧!
  77 + </div>
  78 + <a class="button close" href="">
  79 + 返回
  80 + </a>
  81 + </div>
  82 + </div>
  83 + <div class="loading-mask hide">
  84 + <div class="loading">
  85 + <div></div>
  86 + <div></div>
  87 + <div></div>
  88 + </div>
  89 + </div>
  90 +
  91 + <input type="hidden" value="{{pageType}}" id="page-type">
  92 + <input type="hidden" value="{{activityId}}" id="activity-id">
  93 + <input type="hidden" value="{{jumpUrl}}" id="jump-url">
  94 + {{#if isApp}}
  95 + <input type="hidden" value="{{getCouponUrl}}" id="getCouponUrl">
  96 + {{/if}}
  97 + <script type="text/javascript">
  98 + var isOnline = {{isOnline}};
  99 + {{#if isApp}}
  100 + var isApp = 1;
  101 + {{#if isAppLogin}}
  102 + var isAppLogin = 1;
  103 + {{/if}}
  104 + {{/if}}
  105 +
  106 + </script>
  107 +{{> cuxiao/girlsday-4/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="{{shareLink}}">
  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="{{jsUrl}}/2016xinshili-4/js/libs.js"></script>
  7 +{{#staticJS}}
  8 +<script type="text/javascript" src="{{../jsUrl}}/2016xinshili-4/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="format-detection" content="telephone=no">
  8 + <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">
  9 + <meta name="apple-mobile-web-app-capable" content="yes">
  10 + <meta name="apple-mobile-web-app-status-bar-style" content="grey">
  11 + <script type="text/javascript">
  12 + (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);
  13 + </script>
  14 + <link rel="stylesheet" href="{{jsUrl}}/2016xinshili-4/css/style.css">
  15 +</head>
  16 +<body class="{{pageType}}">
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: Administrator
  5 + * Date: 2016/3/18
  6 + * Time: 10:30
  7 + */
  8 +use Action\HuodongAction;
  9 +use Plugin\Helpers;
  10 +use LibModels\Wap\Cuxiao\ActivityData;
  11 +use Plugin\Cache;
  12 +use Configs\CacheConfig;
  13 +
  14 +class GirlfourController extends HuodongAction
  15 +{
  16 + const SESSION_UID = 'coupon_uid';
  17 +
  18 + /**
  19 + * 女生节第四波领券活动-男生品牌页面控制器
  20 + */
  21 + public function boyAction()
  22 + {
  23 + // 判断是否是应用访问, 拼接APP需要的URL参数
  24 + $isApp = null !== $this->get('app_version');
  25 + $isAppLogged = true;
  26 + if ($isApp) {
  27 + $isLogged = $this->get('uid') !== null;
  28 + $isAppLogged = $this->checkIsLogin();
  29 + } else {
  30 + $isLogged = $this->getUid();
  31 + }
  32 + $urlKids = Helpers::url('/cuxiao/girlfour/boy');
  33 + $urlEncode = strtr($urlKids, array('/' => '\\/'));
  34 +
  35 + $this->_view->display('index', array(
  36 + 'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
  37 + 'staticJS' => array(
  38 + 'main.js'
  39 + ),
  40 + 'jumpUrl' => $isAppLogged ? 'javascript:;' : $urlKids . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $urlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}',
  41 + 'pageType' => 'boy',
  42 + 'isOnline' => $this->getisOnline(),
  43 + 'tab' => array('jp', 'hk', 'cn', 'trousers', 'more'),
  44 + 'moreBrand' => 'http://feature.yoho.cn/0318/TICKETSBOY/index.html',
  45 + 'isApp' => $this->_isApp,
  46 + 'isAppLogin' => $isAppLogged,
  47 + 'getCouponUrl' => Helpers::url('/cuxiao/girlfour/getnamed', array('uid' => $this->getLoggedUid())),
  48 + 'shareTitle' => 'YOHO!BUY有货【春潮新势力】千万元优惠券限时派送中!',
  49 + 'shareDesc' => '全球1000+潮牌春季上新,万款新品首发,唤醒潮流尽在有货【春潮新势力】!',
  50 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
  51 + 'shareLink' => 'http://feature.yoho.cn/0318/0318APPHOME/index.html',
  52 + ));
  53 + }
  54 +
  55 +
  56 + /**
  57 + * 女生节第四波领券活动-女生品牌页面控制器
  58 + */
  59 + public function girlAction()
  60 + {
  61 + // 判断是否是应用访问, 拼接APP需要的URL参数
  62 + $isApp = null !== $this->get('app_version');
  63 + $isAppLogged = true;
  64 + if ($isApp) {
  65 + $isLogged = $this->get('uid') !== null;
  66 + $isAppLogged = $this->checkIsLogin();
  67 + } else {
  68 + $isLogged = $this->getUid();
  69 + }
  70 + $urlKids = Helpers::url('/cuxiao/girlfour/girl');
  71 + $urlEncode = strtr($urlKids, array('/' => '\\/'));
  72 +
  73 + $this->_view->display('index', array(
  74 + 'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
  75 + 'staticJS' => array(
  76 + 'main.js'
  77 + ),
  78 + 'jumpUrl' => $isAppLogged ? 'javascript:;' : $urlKids . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $urlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}',
  79 + 'pageType' => 'girl',
  80 + 'isOnline' => $this->getisOnline(),
  81 + 'tab' => array('hk', 'yohope', 'jean', 'shoes', 'more'),
  82 + 'moreBrand' => 'http://feature.yoho.cn/0318/TICKETSBOY/index.html',
  83 + 'isApp' => $this->_isApp,
  84 + 'isAppLogin' => $isAppLogged,
  85 + 'getCouponUrl' => Helpers::url('/cuxiao/girlfour/getnamed', array('uid' => $this->getLoggedUid())),
  86 + 'shareTitle' => 'YOHO!BUY有货【春潮新势力】千万元优惠券限时派送中!',
  87 + 'shareDesc' => '全球1000+潮牌春季上新,万款新品首发,唤醒潮流尽在有货【春潮新势力】!',
  88 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
  89 + 'shareLink' => 'http://feature.yoho.cn/0318/0318APPHOME/index.html',
  90 + ));
  91 + }
  92 +
  93 + /**
  94 + * 女生节第四波领券活动-童品牌页面控制器
  95 + */
  96 + public function kidAction()
  97 + {
  98 + // 判断是否是应用访问, 拼接APP需要的URL参数
  99 + $isApp = null !== $this->get('app_version');
  100 + $isAppLogged = true;
  101 + if ($isApp) {
  102 + $isLogged = $this->get('uid') !== null;
  103 + $isAppLogged = $this->checkIsLogin();
  104 + } else {
  105 + $isLogged = $this->getUid();
  106 + }
  107 + $urlKids = Helpers::url('/cuxiao/girlfour/kid');
  108 + $urlEncode = strtr($urlKids, array('/' => '\\/'));
  109 +
  110 + $this->_view->display('index', array(
  111 + 'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
  112 + 'staticJS' => array(
  113 + 'main.js'
  114 + ),
  115 + 'jumpUrl' => $isAppLogged ? 'javascript:;' : $urlKids . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $urlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}',
  116 + 'isOnline' => $this->getisOnline(),
  117 + 'pageType' => 'kid',
  118 + // 'tab' => array('us', 'bag', 'yohope', 'shoes', 'more'),
  119 + 'isApp' => $this->_isApp,
  120 + 'isAppLogin' => $isAppLogged,
  121 + 'getCouponUrl' => Helpers::url('/cuxiao/girlfour/getnamed', array('uid' => $this->getLoggedUid())),
  122 + 'shareTitle' => 'YOHO!BUY有货【春潮新势力】千万元优惠券限时派送中!',
  123 + 'shareDesc' => '全球1000+潮牌春季上新,万款新品首发,唤醒潮流尽在有货【春潮新势力】!',
  124 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
  125 + 'shareLink' => 'http://feature.yoho.cn/0318/0318APPHOME/index.html',
  126 + ));
  127 + }
  128 +
  129 + /**
  130 + * 女生节第四波领券活动-创意生活品牌页面控制器
  131 + */
  132 + public function lifestyleAction()
  133 + {
  134 + // 判断是否是应用访问, 拼接APP需要的URL参数
  135 + $isApp = null !== $this->get('app_version');
  136 + $isAppLogged = true;
  137 + if ($isApp) {
  138 + $isLogged = $this->get('uid') !== null;
  139 + $isAppLogged = $this->checkIsLogin();
  140 + } else {
  141 + $isLogged = $this->getUid();
  142 + }
  143 + $urlKids = Helpers::url('/cuxiao/girlfour/lifestyle');
  144 + $urlEncode = strtr($urlKids, array('/' => '\\/'));
  145 +
  146 + $this->_view->display('index', array(
  147 + 'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
  148 + 'staticJS' => array(
  149 + 'main.js'
  150 + ),
  151 + 'jumpUrl' => $isAppLogged ? 'javascript:;' : $urlKids . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $urlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}',
  152 + 'isOnline' => $this->getisOnline(),
  153 + 'pageType' => 'lifestyle',
  154 + 'tab' => array('us', 'hot', 'more'),
  155 + 'moreBrand' => 'http://feature.yoho.cn/0318/TICKETSLIFE/index.html',
  156 + 'isApp' => $this->_isApp,
  157 + 'isAppLogin' => $isAppLogged,
  158 + 'getCouponUrl' => Helpers::url('/cuxiao/girlfour/getnamed', array('uid' => $this->getLoggedUid())),
  159 + 'shareTitle' => 'YOHO!BUY有货【春潮新势力】千万元优惠券限时派送中!',
  160 + 'shareDesc' => '全球1000+潮牌春季上新,万款新品首发,唤醒潮流尽在有货【春潮新势力】!',
  161 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
  162 + 'shareLink' => 'http://feature.yoho.cn/0318/0318APPHOME/index.html',
  163 + ));
  164 + }
  165 +
  166 + /**
  167 + * 领取指定的优惠券
  168 + *
  169 + * @param int activityId 活动ID
  170 + * @param int couponId 优惠券ID
  171 + * @return json
  172 + */
  173 + public function getnamedAction()
  174 + {
  175 + $result = array('code' => 401, 'message' => '领取失败', 'data' => '');
  176 + do {
  177 + /* 判断是不是AJAX请求 */
  178 + if (!$this->isAjax()) {
  179 + break;
  180 + }
  181 +
  182 + /* 判断参数是否有效 */
  183 + $couponId = $this->post('couponId');
  184 + $activityId = $this->getActivityId();
  185 + if (!is_numeric($activityId) || !is_numeric($couponId)) {
  186 + break;
  187 + }
  188 + $uid = $this->getLoggedUid();
  189 + if (!$uid) {
  190 + $result['code'] = 400;
  191 + $result['message'] = '请先登录';
  192 + $result['data'] = Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', '/')), 'default');
  193 + break;
  194 + }
  195 +
  196 + /* 领取指定的优惠券操作 */
  197 + $result = ActivityData::getCouponNamed($uid, $activityId, $couponId);
  198 + if ($uid && isset($result['code']) && intval($result['code'])==200) {
  199 + $couponfour='couponnvshengjiedisibo'.$uid;
  200 + $status = Cache::get($couponfour);
  201 + if(!$status){
  202 + $this->sendMessage($uid, '【优惠券】您已成功领取春潮新势力-品牌优惠券。', '尊敬的客户:恭喜您成功获得春潮新势力-品牌优惠券 !您可以在个人中心查看优惠券详情。');
  203 + Cache::set($couponfour,true,3600*24*5);
  204 + }
  205 + }
  206 + } while (false);
  207 +
  208 + $this->echoJson($result);
  209 + }
  210 +
  211 + /**
  212 + * 检测登录状态
  213 + *
  214 + */
  215 + private function getLoggedUid()
  216 + {
  217 + if ($this->_isApp) {
  218 + $uid = $this->get('uid');
  219 + } else {
  220 + $uid = $this->getUid();
  221 + }
  222 +
  223 + return $uid;
  224 + }
  225 +
  226 + /**
  227 + * 发送站内信
  228 + *
  229 + * @param int $uid 用户ID
  230 + */
  231 + private function sendMessage($uid, $title, $content)
  232 + {
  233 + try {
  234 + ActivityData::message($uid, $title, $content);
  235 + } catch (Exception $e) {
  236 + // do nothing
  237 + }
  238 + }
  239 +
  240 + /**
  241 + * 检查用户是否登录
  242 + *
  243 + * @return bool (false:表示未登录,true:表示已登录)
  244 + */
  245 + private function checkIsLogin()
  246 + {
  247 + do {
  248 + /* 判断是否有参数 */
  249 + $uid = $this->get('uid');
  250 + if (empty($uid) || !is_numeric($uid)) {
  251 + break;
  252 + }
  253 +
  254 + /* 判断参数是否有效 */
  255 + $secret = $this->get('client_secret');
  256 + if (!isset($secret)) {
  257 + break;
  258 + }
  259 +
  260 + $this->setSession(self::SESSION_UID, $uid);
  261 +
  262 + return true;
  263 + } while (false);
  264 +
  265 + return false;
  266 + }
  267 +
  268 + /**
  269 + * 根据环境来获取线上线下
  270 + *
  271 + * @return int
  272 + */
  273 + private function getisOnline()
  274 + {
  275 + // 设置环境变量
  276 + switch (APPLICATION_ENV) {
  277 + case 'production': // 生产
  278 + return 1;
  279 + case 'preview': // 预览
  280 + case 'testing': // 测试
  281 + case 'develop': // 开发
  282 + default:
  283 + return 0;
  284 + }
  285 + }
  286 +
  287 + /**
  288 + * 根据环境来获取活动ID
  289 + *
  290 + * @return int
  291 + */
  292 + private function getActivityId()
  293 + {
  294 + // 设置环境变量
  295 + switch (APPLICATION_ENV) {
  296 + case 'production': // 生产
  297 + return 558;
  298 + case 'preview': // 预览
  299 + case 'testing': // 测试
  300 + case 'develop': // 开发
  301 + default:
  302 + return 496;
  303 + }
  304 + }
  305 +
  306 +}
  307 +
  308 +?>