Girlday.php 2.72 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/3/2
 * Time: 10:48
 */
use Action\HuodongWebAction;
use Cuxiao\GirldayModel;
use WebPlugin\Helpers;
/**
 * 女生节活动领券-第二波
 * @author Administrator
 */
class GirldayController extends HuodongWebAction
{
    // const STATIC_FILE = 'http://localhost:2222/1.0.3';
    const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016xinshili-2-web/1.0.3';
    /**
     * 检测登录状态
     *
     * @return int
     */
    private function getLoggedUid()
    {
        if ($this->_isApp) {
            $uid = $this->get('uid');
        } else {
            $uid = $this->getUid();
        }
        return $uid;
    }

    /**
     * 判断是否登录
     */
    private function checkLogin()
    {
        $url = Helpers::url('/cuxiao/girlday/index');
        $uid = $this->getLoggedUid();
        if (!$uid) {
            $this->go(Helpers::url('/signin.html', array('refer' => $url), 'default'));
        }
    }


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


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

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

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

        $this->echoJson($result);
    }

    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' => 'http://img02.yohoboys.com/staticimg/2016/03/10/10/020ea7cb1f9c2f26b14e08107f778485ff.jpg',
                'url' => 'http://www.yohobuy.com/special_14548_0310PCHOME.html',
            ),
            'selectUrl' => 'http://www.yohobuy.com/home/coupons',
        ));
    }
}