Xinshili.php 2.56 KB
<?php

use Action\HuodongWebAction;
use Cuxiao\XinshiliModel;
use WebPlugin\Helpers;

/**
 * 新势力领券活动
 */
class XinshiliController extends HuodongWebAction
{
    // const STATIC_FILE = '//localhost:2222/1.0.6';
    const STATIC_FILE = '//cdn.yoho.cn/huodong/2016xinshili-web/1.0.6';


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

        return $uid;
    }

    /**
     * 判断是否登录
     */
    private function checkLogin()
    {
        $playUrl = Helpers::url('/cuxiao/xinshili/index');

        $uid = $this->getLoggedUid();
        if (!$uid) {
            $this->go(Helpers::url('/signin.html', array('refer' => $playUrl), 'default'));
        }
    }

    /**
     * 领券活动页面控制器
     */
    public function indexAction()
    {
        $this->checkLogin();

        //获取跳转到个人中心-我的优惠券链接,并调用接口,完成领券操作
        $myCouponUrl = Helpers::url('/home/coupons', null, 'default');

        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticFile' => self::STATIC_FILE,
            'staticJS' => array(
                'home.js'
            ),
            'couponUrl' => $myCouponUrl, // 个人中心优惠券地址
            'banner' => array(
                'img' => '//img02.yohoboys.com/staticimg/2016/03/04/09/021a94b08418c4416785d37a47088aac58.jpg',
                'url' => '//www.yohobuy.com/special_14444_0302PCHOME.html'
            )
        ));
    }

    /**
     * 领券接口
     */
    public function sendCouponAction()
    {
        $result = array('code' => 201);

        do {
            if (!$this->isAjax()) {
                break;
            }

            $activityId = $this->getActivityId();
            $uid = $this->getLoggedUid();
            $result = XinshiliModel::getXinshiliCoupon($uid, $activityId);
        } while (false);

        $this->echoJson($result);
    }

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