Authored by hf

code review by fei.hong: do huodong girlday coupon

  1 +{{> cuxiao/xinshili/header}}
  2 + <div class="main-wrap home">
  3 + <div class="header"></div>
  4 + <a class="coupon" href="{{couponUrl}}"></a>
  5 + <div class="share">
  6 + 快去分享给小伙伴吧 <span class="arrow"></span>
  7 + </div>
  8 + <a class="banner" href="{{banner.url}}">
  9 + <img src="{{banner.img}}">
  10 + </a>
  11 + {{#unless isApp}}
  12 + <div class="download">
  13 + <a class="weixin" href="{{weixinUrl}}">
  14 + 关注有货微信 <span class="arrow"></span>
  15 + </a>
  16 + <a class="app" href="{{appUrl}}">
  17 + 下载YOHO!BUY有货APP <span class="arrow"></span>
  18 + </a>
  19 + </div>
  20 + {{/unless}}
  21 + <div class="footer">
  22 + </div>
  23 + </div>
  24 + <div class="mask hide">
  25 + <div class="pengyouquan">
  26 + </div>
  27 + <div class="arrow">
  28 + </div>
  29 + <p>
  30 + 点击右上角<br>
  31 + 微信分享至朋友圈
  32 + </p>
  33 + </div>
  34 + <div class="tip-wrap hide">
  35 + <div class="tip hide fail">
  36 + <div class="title">
  37 + 领取失败<br>
  38 + 请刷新重新领取
  39 + </div>
  40 + <div class="desc">
  41 + 如多次领取失败,请联系客服人员<br>
  42 + 带来不便敬请谅解
  43 + </div>
  44 + <a class="button" href="">
  45 + 刷新
  46 + </a>
  47 + </div>
  48 + </div>
  49 +
  50 + <div class="tip-wrap hide">
  51 + <div class="tip hide geted">
  52 + <div class="title">
  53 + 你已领取过优惠券
  54 + </div>
  55 + <div class="sub-title">
  56 + 快去分享给更多<br>
  57 + 喜爱<span class="title">潮流</span>的小伙伴吧!
  58 + </div>
  59 + <a class="button close" href="">
  60 + 返回
  61 + </a>
  62 + </div>
  63 + </div>
  64 +
  65 + {{#if isApp}}
  66 + <input type="hidden" value="{{getCouponUrl}}" id="getCouponUrl">
  67 + {{/if}}
  68 +{{> cuxiao/xinshili/footer}}
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: Administrator
  5 + * Date: 2016/3/4
  6 + * Time: 12:18
  7 + */
  8 +namespace Cuxiao;
  9 +use LibModels\Wap\Cuxiao\ActivityData;
  10 +
  11 +class GirldayModel
  12 +{
  13 + /**
  14 + * 获取领券活动结果
  15 + *
  16 + * @param int $uid 用户id
  17 + * @param int $actId 活动id
  18 + * @return array
  19 + */
  20 + public static function getGirldayCoupon($uid, $actId)
  21 + {
  22 + $result = array('code' => 201);
  23 +
  24 + do {
  25 + if (empty($uid) || empty($actId)) {
  26 + break;
  27 + }
  28 +
  29 + $result = ActivityData::getCouponAll($uid, $actId);
  30 + if (!$result) {
  31 + $result = array('code' => 201);
  32 + break;
  33 + }
  34 +
  35 + if (intval($result['code']) === 200) {
  36 + self::sendMessage($uid, '【优惠券】您有4张春潮新势力优惠券', '尊敬的客户:恭喜您成功获得4张春潮新势力优惠券 !您可以在个人中心查看优惠券详情。');
  37 + }
  38 + } while (false);
  39 +
  40 + return $result;
  41 + }
  42 +
  43 + /**
  44 + * 发送站内信
  45 + *
  46 + * @param int $uid 用户ID
  47 + * @param string $title 站内信标题
  48 + * @param string $content 站内信内容
  49 + */
  50 + private static function sendMessage($uid, $title, $content)
  51 + {
  52 + try {
  53 + ActivityData::message($uid, $title, $content);
  54 + } catch (Exception $e) {
  55 + // do nothing
  56 + }
  57 + }
  58 +}
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: Administrator
  5 + * Date: 2016/3/4
  6 + * Time: 11:53
  7 + */
  8 +use Action\HuodongAction;
  9 +use Cuxiao\GirldayModel;
  10 +use Plugin\Helpers;
  11 +
  12 +/**
  13 + * 女生节第二波
  14 + */
  15 +class GirldayController extends HuodongAction
  16 +{
  17 +
  18 + // const STATIC_FILE = 'http://localhost:2222/1.0.4';
  19 + const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016xinshili-2/1.0.4';
  20 +
  21 + /**
  22 + * 检测登录状态
  23 + *
  24 + */
  25 + private function getLoggedUid()
  26 + {
  27 + if ($this->_isApp) {
  28 + $uid = $this->get('uid');
  29 + } else {
  30 + $uid = $this->getUid();
  31 + }
  32 +
  33 + return $uid;
  34 + }
  35 +
  36 + /**
  37 + * 判断是否登陆
  38 + */
  39 + private function checkLogin()
  40 + {
  41 + $playUrl = Helpers::url('/cuxiao/girlday/index');
  42 +
  43 + if (!$this->getLoggedUid()) {
  44 + if (!$this->_isApp) {
  45 + $this->go(Helpers::url('/signin.html', array('refer' => $playUrl), 'default'));
  46 + } else {
  47 + $playUrlEncode = strtr($playUrl, array('/' => '\\/'));
  48 + $this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
  49 + }
  50 + }
  51 + }
  52 +
  53 + /**
  54 + * 领券活动页面控制器
  55 + */
  56 + public function indexAction()
  57 + {
  58 + $this->checkLogin();
  59 +
  60 + //获取跳转到个人中心-我的优惠券链接,并调用接口,完成领券操作
  61 + $myCouponUrl = Helpers::url('/home/coupons', null, 'default') . '?openby:yohobuy={"action":"go.coupon"}';
  62 +
  63 + $this->_view->display('index', array(
  64 + 'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
  65 + 'staticFile' => self::STATIC_FILE,
  66 + 'staticJS' => array(
  67 + 'home.js'
  68 + ),
  69 + 'couponUrl' => $myCouponUrl, // 个人中心优惠券地址
  70 + 'isApp' => $this->_isApp,
  71 + 'getCouponUrl' => Helpers::url('/cuxiao/girlday/sendCoupon', array('uid' => $this->getLoggedUid())),
  72 + 'banner' => array(
  73 + 'img' => 'http://img02.yohoboys.com/staticimg/2016/03/10/10/02b9827b20adc91409b5301f2232dc9144.jpg',
  74 + 'url' => 'http://feature.yoho.cn/0310/0310APPHOME/index.html?openby:yohobuy={"action":"go.h5","params":{"title":"YOHO!BUY有货【春潮新势力】", "url":"http://feature.yoho.cn/0310/0310APPHOME/index.html?","share":"\/operations\/api\/v5\/webshare\/getShare","shareparam":{"share_id":"382"},"param":{"share_id":"382"}}}'
  75 + ),
  76 + 'selectUrl' => 'http://m.yohobuy.com/home/coupons?openby:yohobuy={"action":"go.coupon"}',
  77 + 'weixinUrl' => 'http://mp.weixin.qq.com/s?__biz=MjM5ODI5MDA4MA==&mid=201849402&idx=1&sn=c0089812f9769d82e0075f69d771f6e1#rd', // 微信关注地址
  78 + 'appUrl' => 'http://www.yohoshow.com/about/index/yohobuyqr', // APP 下载地址
  79 + 'shareTitle' => 'YOHO!BUY有货【春潮新势力】火力全开!320元优惠券限时派送中!',
  80 + 'shareDesc' => '换我做主,用新陪伴!白色情人节限时2件7折!',
  81 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
  82 + 'shareLink' => 'http://feature.yoho.cn/0310/0310APPHOME/index.html'
  83 + ));
  84 + }
  85 +
  86 + /**
  87 + * 领券接口
  88 + */
  89 + public function sendCouponAction()
  90 + {
  91 + $result = array('code' => 201);
  92 +
  93 + do {
  94 + if (!$this->isAjax()) {
  95 + break;
  96 + }
  97 +
  98 + $activityId = $this->getActivityId();
  99 + $uid = $this->getLoggedUid();
  100 + $result = GirldayModel::getGirldayCoupon($uid, $activityId);
  101 + } while (false);
  102 +
  103 + $this->echoJson($result);
  104 + }
  105 +
  106 + /**
  107 + * 根据环境来获取活动ID
  108 + *
  109 + * @return int
  110 + */
  111 + private function getActivityId()
  112 + {
  113 + // 设置环境变量
  114 + switch (APPLICATION_ENV) {
  115 + case 'production': // 生产
  116 + return 528;
  117 + case 'preview': // 预览
  118 + case 'testing': // 测试
  119 + case 'develop': // 开发
  120 + default:
  121 + return 528; //490
  122 + }
  123 + }
  124 +
  125 +}