Authored by Rock Zhang

添加女生节领券活动wap端的部分代码

  1 +<?php
  2 +use Action\HuodongAction;
  3 +use LibModels\Wap\Cuxiao\ActivityData;
  4 +use Plugin\Helpers;
  5 +
  6 +/**
  7 + * 女生节领券活动
  8 + */
  9 +class GirlsdayController extends HuodongAction
  10 +{
  11 +
  12 + /**
  13 + * 检测登录状态
  14 + *
  15 + * @return int
  16 + */
  17 + private function getLoggedUid()
  18 + {
  19 + if ($this->_isApp) {
  20 + $uid = $this->get('uid');
  21 + } else {
  22 + $uid = $this->getUid();
  23 + }
  24 +
  25 + return $uid;
  26 + }
  27 +
  28 + /**
  29 + * 判断是否登陆
  30 + */
  31 + private function checkLogin()
  32 + {
  33 + $playUrl = Helpers::url('/cuxiao/girlsday/index');
  34 + $playUrlEncode = strtr($playUrl, array('/' => '\\/'));
  35 +
  36 + $uid = $this->getLoggedUid();
  37 + if (!$uid) {
  38 + if (!$this->_isApp) {
  39 + $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
  40 + } else {
  41 + $playUrl = Helpers::url('/cuxiao/yuanxiao/index');
  42 + $this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
  43 + }
  44 + }
  45 +
  46 + return $uid;
  47 + }
  48 +
  49 + /**
  50 + * 领券活动
  51 + */
  52 + public function indexAction()
  53 + {
  54 + $uid = $this->checkLogin();
  55 +
  56 + // 该变量用来控制和显示页面的弹出提示
  57 + $showPopupFlag = '0';
  58 +
  59 + //获取跳转到个人中心-我的优惠券链接,并调用接口,完成领券操作
  60 + $myCouponUrl = Helpers::url('/home/coupons', null, 'default') . '?openby:yohobuy={"action":"go.coupon"}';
  61 + $activityId = $this->getActivityId();
  62 + $result = ActivityData::getCouponAll($uid, $activityId);
  63 + if (isset($result['code'])) {
  64 + switch (intval($result['code'])) {
  65 + case 200: // 领取成功, 发送站内信消息
  66 + $showPopupFlag = '0';
  67 + $this->sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');
  68 + break;
  69 + case 201: // 已领取过, 提示重复领券
  70 + $showPopupFlag = '1';
  71 + break;
  72 + default: // 领取失败, 提示领券失败
  73 + $showPopupFlag = '2';
  74 + break;
  75 + }
  76 + }
  77 +
  78 + $this->_view->display('index', array(
  79 + 'staticTitle' => '女生节领劵活动',
  80 + 'staticJS' => array(
  81 + 'home.js'
  82 + ),
  83 + 'weixinShare' => $this->_isApp ? false : true, // 是否需要微信分享
  84 + 'showPopupFlag' => $showPopupFlag,
  85 + 'myCouponUrl' => $myCouponUrl,
  86 + 'shareDesc' => '女生节领劵活动',
  87 + 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
  88 + 'shareUrl' => Helpers::url('/cuxiao/girlsday/index')
  89 + ));
  90 + }
  91 +
  92 + /**
  93 + * 根据环境来获取活动ID
  94 + *
  95 + * @return int
  96 + */
  97 + private function getActivityId()
  98 + {
  99 + // 设置环境变量
  100 + switch (APPLICATION_ENV) {
  101 + case 'production': // 生产
  102 + return 388;
  103 + case 'preview': // 预览
  104 + case 'testing': // 测试
  105 + case 'develop': // 开发
  106 + default:
  107 + return 84;
  108 + }
  109 + }
  110 +
  111 + /**
  112 + * 发送站内信
  113 + *
  114 + * @param int $uid 用户ID
  115 + * @param string $title 站内信标题
  116 + * @param string $content 站内信内容
  117 + */
  118 + private function sendMessage($uid, $title, $content)
  119 + {
  120 + try {
  121 + ActivityData::message($uid, $title, $content);
  122 + } catch (Exception $e) {
  123 + // do nothing
  124 + }
  125 + }
  126 +}