<?php
namespace Cas\Controller;
use KIF\Core\Request;
use KIF\Verify;
use Cas\Module\LotteryEventsTypeTry;
/**
 * 
 * 试用
 */
class TryDetail extends Controller {
	
	public function doDefault() {
		$tryid = Request::g('tryid');
		if (!Verify::unsignedInt($tryid)) {
			self::fail_exit('无效id');
		}
		
		$uid = $this->getRunTimeUid();
		
		$objLotteryEventsTypeTry = new LotteryEventsTypeTry($uid, $tryid);
		$tryInfo = $objLotteryEventsTypeTry->getEventsData();
		
		$checkResult = self::checkLoginStatus($tryInfo['authorize'], Request::url());
		if (!$checkResult->isSuccess()) {
			self::redirect($checkResult->getData());
		}
		
		
		
		$this->tpl = 'tryDetail';
		$this->setOutput('title', '免费试用');
		$this->setOutput('tryInfo', $tryInfo);
	}
	
	public function doApply() {
		$realname = Request::g('realname');
		if (!$realname) {
			self::ajax_fail_exit('请填写姓名');
		}
		$phone = Request::g('phone');
		if (!$phone) {
			self::ajax_fail_exit('请填写有效手机号码');
		}
		$address = Request::g('address');
		if (!$address) {
			self::ajax_fail_exit('请填写收货地址');
		}
		$content = Request::g('content');
		if (!$content) {
			self::ajax_fail_exit('请填写申请宣言');
		}
		
		$uid = $this->getRunTimeUid();
		if (!Verify::unsignedInt($uid)) {
			self::ajax_fail_exit('无效用户id');
		}
		
		$tryid = Request::g('tryid');
		if (!Verify::unsignedInt($tryid)) {
			self::ajax_fail_exit('无效试用id');
		}
		
		$objLotteryEventsTypeTry = new LotteryEventsTypeTry($uid, $tryid);
		$tmpResult = $objLotteryEventsTypeTry->userTry($realname, $phone, $address, $content);
		if (!$tmpResult->isSuccess()) {
			self::ajax_fail_exit($tmpResult->getData());
		}
		
		self::ajax_success_exit();
	}
	
	public function display() {
		return $this->render();
	}
}