Xinshili.php 3.93 KB
<?php

use Action\HuodongAction;
use Cuxiao\XinshiliModel;
use Plugin\Helpers;

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

    /**
     * 检测登录状态
     *
     */
    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');

        if (!$this->getLoggedUid()) {
            if (!$this->_isApp) {
                $this->go(Helpers::url('/signin.html', array('refer' => $playUrl), 'default'));
            } else {
                $playUrlEncode = strtr($playUrl, array('/' => '\\/'));
                $this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
            }
        }
    }

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

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

        $this->_view->display('index', array(
            'staticTitle' => 'YOHO!BUY有货【春潮新势力】',
            'staticFile' => self::STATIC_FILE,
            'staticJS' => array(
                'home.js'
            ),
            'couponUrl' => $myCouponUrl, // 个人中心优惠券地址
            'isApp' => $this->_isApp,
            'getCouponUrl' => Helpers::url('/cuxiao/xinshili/sendCoupon', array('uid' => $this->getLoggedUid())),
            'banner' => array(
                'img' => '//img01.yohoboys.com/staticimg/2016/03/04/09/019c5b6a514adee6bd2e3af9d8c28cdecb.jpg',
                'url' => '//feature.yoho.cn/0302/0302APPHOME/index.html?openby:yohobuy={"action":"go.h5","params":{"title":"YOHO!BUY有货【春潮新势力】","url":"//feature.yoho.cn/0302/0302APPHOME/index.html?","share":"\/operations\/api\/v5\/webshare\/getShare","shareparam":{"share_id":"386"},"param":{"share_id":"386"}}}'
            ),
            'weixinUrl' => '//mp.weixin.qq.com/s?__biz=MjM5ODI5MDA4MA==&mid=201849402&idx=1&sn=c0089812f9769d82e0075f69d771f6e1#rd', // 微信关注地址
            'appUrl' => '//www.yohoshow.com/about/index/yohobuyqr', // APP 下载地址
            'shareTitle' => 'YOHO!BUY有货【春潮新势力】限时积分翻倍,夯货买1赠1!唤醒潮流,从新开始!',
            'shareDesc' => '350元优惠券限时派送!Wake up!Boys and Girls!',
            'shareImg' => '//img02.yohoboys.com/staticimg/2016/03/03/18/028b014763283d278c6acad955a304c2a3.jpg',
            'shareLink' => Helpers::url('/cuxiao/xinshili/index')
        ));
    }

    /**
     * 领券接口
     */
    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;
        }
    }

}