Gift.php 2.58 KB
<?php

use Action\WebAction;
use WebPlugin\Helpers;
use Home\UserModel;
use LibModels\Web\Home\UserData;
use Passport\PassportModel;
use Home\CurrencyModel;

/**
 * 个人中心 礼品卡兑换
 */
class GiftController extends WebAction
{

    /**
     * 礼品卡页面
     */
    public function indexAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();

        //头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        //面包屑-左侧导航
        $path = UserModel::getCenterCrumb('兑换礼品卡');
        $leftNav = UserModel::getCenterLeftNav('兑换礼品卡', $uid);
        $type = $this->get('type', '');

        $data = array(
            'path' => $path,
            'userThumb' => UserModel::getUserHeadImg($uid),
            'homeNav' => $leftNav,
        );

        if ($type) {
            //yohocoin信息
            $yohoCoinInfo = CurrencyModel::currencyTotal($uid);
            $yohoCoin = isset($yohoCoinInfo['data']['yohocoin_num']) ? $yohoCoinInfo['data']['yohocoin_num'] : 0;
            $success = ($type == 1) ? true : false;
            $data['resultInfo'] = array('success' => $success, 'yohoCoin' => $yohoCoin);
        }
        else {
            $data['resultInfo'] = false;
        }

        $this->_view->display('gift', array(
            'gift' => $data,
            'meGiftPage' => true
        ));
    }

    /**
     * 个人中心-兑换礼品卡提交返回信息
     */
    public function exchangeAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');

        do {

            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }

            $uid = $this->auditJumpLogin();

            $giftCardCode1 = trim($this->post('giftCardCode1', ''));
            $giftCardCode2 = trim($this->post('giftCardCode2', ''));
            $giftCardCode3 = trim($this->post('giftCardCode3', ''));
            $captchaCode = strtolower(trim($this->post('verifyCode', '')));

            if (!PassportModel::verifyCode($captchaCode)) {
                $data['code'] = 400;
                $data['message'] = '图形验证码不正确';
                break;
            }

            $data = UserData::exchangeGift($uid, $giftCardCode1, $giftCardCode2, $giftCardCode3, $captchaCode);
            if (!isset($data['code'])) {
                break;
            }
        }
        while (false);

        $this->echoJson($data);
    }

}