Girlfour.php 11.3 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/3/18
 * Time: 10:30
 */
use Action\HuodongAction;
use Plugin\Helpers;
use LibModels\Wap\Cuxiao\ActivityData;
use Plugin\Cache;
use Configs\CacheConfig;

class GirlfourController extends HuodongAction
{
    const SESSION_UID = 'coupon_uid';

    /**
     * 女生节第四波领券活动-男生品牌页面控制器
     */
    public function boyAction()
    {
        // 判断是否是应用访问, 拼接APP需要的URL参数
        $isApp = null !== $this->get('app_version');
        $isAppLogged = true;
        if ($isApp) {
            $isLogged = $this->get('uid') !== null;
            $isAppLogged = $this->checkIsLogin();
        } else {
            $isLogged = $this->getUid();
        }
        $urlKids = Helpers::url('/cuxiao/girlfour/boy');
        $urlEncode = strtr($urlKids, array('/' => '\\/'));

        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticJS' => array(
                'main.js'
            ),
            'jumpUrl' => $isAppLogged ? 'javascript:;' : $urlKids . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $urlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}',
            'pageType' => 'boy',
            'isOnline' =>  $this->getisOnline(),
            'tab' => array('jp', 'hk', 'cn', 'trousers', 'more'),
            'moreBrand' => '//feature.yoho.cn/0318/TICKETSBOY/index.html',
            'isApp' => $this->_isApp,
            'isAppLogin' => $isAppLogged,
            'getCouponUrl' => Helpers::url('/cuxiao/girlfour/getnamed', array('uid' => $this->getLoggedUid())),
            'shareTitle' => 'YOHO!BUY有货【春潮新势力】千万元优惠券限时派送中!',
            'shareDesc' => '全球1000+潮牌春季上新,万款新品首发,唤醒潮流尽在有货【春潮新势力】!',
            'shareImg' => '//img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
            'shareLink' => '//feature.yoho.cn/0318/0318APPHOME/index.html',
        ));
    }


    /**
     * 女生节第四波领券活动-女生品牌页面控制器
     */
    public function girlAction()
    {
        // 判断是否是应用访问, 拼接APP需要的URL参数
        $isApp = null !== $this->get('app_version');
        $isAppLogged = true;
        if ($isApp) {
            $isLogged = $this->get('uid') !== null;
            $isAppLogged = $this->checkIsLogin();
        } else {
            $isLogged = $this->getUid();
        }
        $urlKids = Helpers::url('/cuxiao/girlfour/girl');
        $urlEncode = strtr($urlKids, array('/' => '\\/'));

        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticJS' => array(
                'main.js'
            ),
            'jumpUrl' => $isAppLogged ? 'javascript:;' : $urlKids . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $urlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}',
            'pageType' => 'girl',
            'isOnline' =>  $this->getisOnline(),
            'tab' => array('hk', 'yohope', 'jean', 'shoes', 'more'),
            'moreBrand' => '//feature.yoho.cn/0318/TICKETSBOY/index.html',
            'isApp' => $this->_isApp,
            'isAppLogin' => $isAppLogged,
            'getCouponUrl' => Helpers::url('/cuxiao/girlfour/getnamed', array('uid' => $this->getLoggedUid())),
            'shareTitle' => 'YOHO!BUY有货【春潮新势力】千万元优惠券限时派送中!',
            'shareDesc' => '全球1000+潮牌春季上新,万款新品首发,唤醒潮流尽在有货【春潮新势力】!',
            'shareImg' => '//img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
            'shareLink' => '//feature.yoho.cn/0318/0318APPHOME/index.html',
        ));
    }

    /**
     * 女生节第四波领券活动-童品牌页面控制器
     */
    public function kidAction()
    {
        // 判断是否是应用访问, 拼接APP需要的URL参数
        $isApp = null !== $this->get('app_version');
        $isAppLogged = true;
        if ($isApp) {
            $isLogged = $this->get('uid') !== null;
            $isAppLogged = $this->checkIsLogin();
        } else {
            $isLogged = $this->getUid();
        }
        $urlKids = Helpers::url('/cuxiao/girlfour/kid');
        $urlEncode = strtr($urlKids, array('/' => '\\/'));

        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticJS' => array(
                'main.js'
            ),
            'jumpUrl' => $isAppLogged ? 'javascript:;' : $urlKids . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $urlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}',
            'isOnline' => $this->getisOnline(),
            'pageType' => 'kid',
            // 'tab' => array('us', 'bag', 'yohope', 'shoes', 'more'),
            'isApp' => $this->_isApp,
            'isAppLogin' => $isAppLogged,
            'getCouponUrl' => Helpers::url('/cuxiao/girlfour/getnamed', array('uid' => $this->getLoggedUid())),
            'shareTitle' => 'YOHO!BUY有货【春潮新势力】千万元优惠券限时派送中!',
            'shareDesc' => '全球1000+潮牌春季上新,万款新品首发,唤醒潮流尽在有货【春潮新势力】!',
            'shareImg' => '//img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
            'shareLink' => '//feature.yoho.cn/0318/0318APPHOME/index.html',
        ));
    }

    /**
     * 女生节第四波领券活动-创意生活品牌页面控制器
     */
    public function lifestyleAction()
    {
        // 判断是否是应用访问, 拼接APP需要的URL参数
        $isApp = null !== $this->get('app_version');
        $isAppLogged = true;
        if ($isApp) {
            $isLogged = $this->get('uid') !== null;
            $isAppLogged = $this->checkIsLogin();
        } else {
            $isLogged = $this->getUid();
        }
        $urlKids = Helpers::url('/cuxiao/girlfour/lifestyle');
        $urlEncode = strtr($urlKids, array('/' => '\\/'));

        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticJS' => array(
                'main.js'
            ),
            'jumpUrl' => $isAppLogged ? 'javascript:;' : $urlKids . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $urlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}',
            'isOnline' => $this->getisOnline(),
            'pageType' => 'lifestyle',
            'tab' => array('us', 'hot', 'more'),
            'moreBrand' => '//feature.yoho.cn/0318/TICKETSLIFE/index.html',
            'isApp' => $this->_isApp,
            'isAppLogin' => $isAppLogged,
            'getCouponUrl' => Helpers::url('/cuxiao/girlfour/getnamed', array('uid' => $this->getLoggedUid())),
            'shareTitle' => 'YOHO!BUY有货【春潮新势力】千万元优惠券限时派送中!',
            'shareDesc' => '全球1000+潮牌春季上新,万款新品首发,唤醒潮流尽在有货【春潮新势力】!',
            'shareImg' => '//img02.yohoboys.com/staticimg/2016/03/10/10/0298ef8fbbb543144af487fbcd6718041b.png',
            'shareLink' => '//feature.yoho.cn/0318/0318APPHOME/index.html',
        ));
    }

    /**
     * 领取指定的优惠券
     *
     * @param int activityId 活动ID
     * @param int couponId 优惠券ID
     * @return json
     */
    public function getnamedAction()
    {
        $result = array('code' => 401, 'message' => '领取失败', 'data' => '');
        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }

            /* 判断参数是否有效 */
            $couponId = $this->post('couponId');
            $activityId = $this->getActivityId();
            if (!is_numeric($activityId) || !is_numeric($couponId)) {
                break;
            }
            $uid = $this->getLoggedUid();
            if (!$uid) {
                $result['code'] = 400;
                $result['message'] = '请先登录';
                $result['data'] = Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', '/')), 'default');
                break;
            }

            /* 领取指定的优惠券操作 */
            $result = ActivityData::getCouponNamed($uid, $activityId, $couponId);
            if ($uid && isset($result['code']) && intval($result['code'])==200) {
                $couponfour='couponnvshengjiedisibo'.$uid;
                $status = Cache::get($couponfour);
                if(!$status){
                    $this->sendMessage($uid, '【优惠券】您已成功领取春潮新势力-品牌优惠券。', '尊敬的客户:恭喜您成功获得春潮新势力-品牌优惠券 !您可以在个人中心查看优惠券详情。');
                    Cache::set($couponfour,true,3600*24*5);
                }
            }
        } while (false);

        $this->echoJson($result);
    }

    /**
     * 检测登录状态
     *
     */
    private function getLoggedUid()
    {
        if ($this->_isApp) {
            $uid = $this->get('uid');
        } else {
            $uid = $this->getUid();
        }

        return $uid;
    }

    /**
     * 发送站内信
     *
     * @param int $uid 用户ID
     */
    private function sendMessage($uid, $title, $content)
    {
        try {
            ActivityData::message($uid, $title, $content);
        } catch (Exception $e) {
            // do nothing
        }
    }

    /**
     * 检查用户是否登录
     *
     * @return bool (false:表示未登录,true:表示已登录)
     */
    private function checkIsLogin()
    {
        do {
            /* 判断是否有参数 */
            $uid = $this->get('uid');
            if (empty($uid) || !is_numeric($uid)) {
                break;
            }

            /* 判断参数是否有效 */
            $secret = $this->get('client_secret');
            if (!isset($secret)) {
                break;
            }

            $this->setSession(self::SESSION_UID, $uid);

            return true;
        } while (false);

        return false;
    }

    /**
     * 根据环境来获取线上线下
     *
     * @return int
     */
    private function getisOnline()
    {
        // 设置环境变量
        switch (APPLICATION_ENV) {
            case 'production': // 生产
                return 1;
            case 'preview':      // 预览
            case 'testing':      // 测试
            case 'develop':      // 开发
            default:
                return 0;
        }
    }

    /**
     * 根据环境来获取活动ID
     *
     * @return int
     */
    private function getActivityId()
    {
        // 设置环境变量
        switch (APPLICATION_ENV) {
            case 'production': // 生产
                return 558;
            case 'preview':      // 预览
            case 'testing':      // 测试
            case 'develop':      // 开发
            default:
                return 496;
        }
    }

}

?>