Girlfour.php 5.15 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/3/18
 * Time: 13:27
 */
use Action\HuodongWebAction;
use WebPlugin\Helpers;
use LibModels\Wap\Cuxiao\ActivityData;
use Plugin\Cache;

class GirlfourController extends HuodongWebAction
{
    /**
     * 女生节第四波领券活动-男生品牌页面控制器
     */
    public function boyAction()
    {
        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticJS' => array(
                'main.js'
            ),
            'pageType' => 'boy',
            'isOnline' =>  $this->getisOnline(),
            'tab' => array('jp', 'hk', 'cn', 'trousers'),
        ));
    }


    /**
     * 女生节第四波领券活动-女生品牌页面控制器
     */
    public function girlAction()
    {
        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticJS' => array(
                'main.js'
            ),
            'pageType' => 'girl',
            'isOnline' =>  $this->getisOnline(),
            'tab' => array('hk', 'yohope', 'jean', 'shoes'),
        ));
    }

    /**
     * 女生节第四波领券活动-童品牌页面控制器
     */
    public function kidAction()
    {
        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticJS' => array(
                'main.js'
            ),
            'isOnline' => $this->getisOnline(),
            'pageType' => 'kid',
        ));
    }

    /**
     * 女生节第四波领券活动-创意生活品牌页面控制器
     */
    public function lifestyleAction()
    {
        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticJS' => array(
                'main.js'
            ),
            'isOnline' => $this->getisOnline(),
            'pageType' => 'lifestyle',
            'tab' => array('us', 'hot'),
        ));
    }


    /**
     * 领取指定的优惠券
     *
     * @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;
            }

            /* 判断参数是否有效 */
            $activityId = $this->getActivityId();
            $couponId = $this->post('couponId');
            if (!is_numeric($activityId) || !is_numeric($couponId)) {
                break;
            }
            $uid = $this->getUid();

            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) {
                $couponuid = 'couponnvshengjiedisibo' . $uid;
                $status = Cache::get($couponuid);
                if (!$status) {
                    $this->sendMessage($uid, '【优惠券】您已成功领取春潮新势力-品牌优惠券。', '尊敬的客户:恭喜您成功获得春潮新势力-品牌优惠券 !您可以在个人中心查看优惠券详情。');
                    Cache::set($couponuid, true, 3600 * 24 * 5);
                }
            }
        } while (false);


        $this->echoJson($result);
    }

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

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

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

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


}
?>