123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <?php
- namespace Cas\Controller;
- use Cas\Dao\LotteryUserExpress;
- use KIF\Core\Request;
- use KIF\Verify;
- use Cas\Module\LotteryEventsTypeTry;
- use KIF\String\Filter;
- use Cas\Dao\LotteryEventsForms;
- use Cas\Dao\UserInfo;
- use Cas\Module\Count;
- use Cas\Module\Lottery;
- use Cas\Dao\LotteryEvents;
- use Cas\Module\LotteryEventsLimitations;
- use Cas\Module\LotteryLog;
- use KIF\Cookie;
- class EventsSurvey extends EventsController {
-
- public function doDefault() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $thisTime = time();
-
- $events_id = $this->getEventsCreateTimeToId();
- if (!Verify::unsignedInt($events_id)) {
- self::fail_exit('无效id');
- }
-
-
- $objUserData = new UserInfo();
- $uid = $this->getRunTimeUid();
- $userData = $objUserData -> get($uid);
- $this->setOutput('userData', $userData);
-
-
- $objDLotteryEvents = new LotteryEvents();
- $surveyInfo = $objDLotteryEvents -> get($events_id);
-
-
- $title = $surveyInfo['weixinShare']['title'] ? $surveyInfo['weixinShare']['title'] : $surveyInfo['events_name'];
- $this->checkIsFromMobile($title);
-
-
- $url = Request::g('url');
- $plat_form_id = $this->getPlatFormId();
- $objMLottery = new Lottery();
- $thisUrl = $objMLottery -> getEventsUrl($surveyInfo['type'],$surveyInfo['create_time'],$url);
- $loginUrl = $this -> getLoginUrl($thisUrl);
- $this->setOutput('loginUrl', $loginUrl);
-
- $ckLogin = $this->ckLogin();
- $this->setOutput('ckLogin', $ckLogin);
-
-
-
- $authorize =$surveyInfo['authorize'];
- if ($authorize && $loginUrl) {
- if($ckLogin==true){
- self::redirect($loginUrl);
- }
- }
- $this->info($surveyInfo);
-
-
- $objCount = new Count();
- $objCount->setPassLog( $events_id,$plat_form_id);
-
-
-
- $TIME = time();
- $eventsStatus = false;
- $objMLotteryEventsLimitations = new LotteryEventsLimitations();
- if($TIME < $surveyInfo['begin_time'] ){
- $eventsStatus = 'STATUS_NOT_START';
-
- } elseif ($TIME > $surveyInfo['end_time']){
- $eventsStatus = 'STATUS_HAS_END';
-
- } elseif ($surveyInfo['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
-
-
- }elseif (!$objMLotteryEventsLimitations->ckEventRestrictions($uid,Request::ip(), $events_id)) {
- $eventsStatus = 'STATUS_HAS_RESTRTICTIONS';
- }
-
- if (Cookie::get('SURVEY_IS_UNDERWAY') >= 2) {
- Cookie::set('SURVEY_IS_UNDERWAY', 1, null, $_SERVER['HTTP_HOST'], '/');
- $this->setOutput('display', $surveyInfo['list_display']);
- $this->tpl = 'events_survey_underway';
- } else {
- $this->setOutput('display', $surveyInfo['list_display']);
- $this->tpl = 'events_survey';
- }
-
-
- preg_match_all('/<embed\s{1}src=\"([^\"]+)\"[^>]+>/i', $surveyInfo['events_tips'], $matches);
- if ($matches) foreach ($matches[0] as $key => $tmpMatch) {
- $tmp_new_video_html = '<iframe class="video_iframe" height=498 width=510 src="'.$matches[1][$key].'" frameborder=0 allowfullscreen></iframe>';
- $surveyInfo['events_tips'] = str_replace($tmpMatch, $tmp_new_video_html, $surveyInfo['events_tips']);
- }
-
-
- $this->setOutput('eventsStatus', $eventsStatus);
- $this->setOutput('title', $surveyInfo['weixinShare']['title'] ? $surveyInfo['weixinShare']['title'] : $surveyInfo['events_name']);
- $this->setOutput('surveyInfo', $surveyInfo);
- $this->setOutput('forms', $surveyInfo['forms']);
- $this->setOutput('weixinShare', $surveyInfo['weixinShare']);
- }
-
- public function doSubmit() {
- $thisTime = time();
-
-
- $uid = $this->getRunTimeUid();
- if (!Verify::unsignedInt($uid)) {
- self::ajax_fail_exit('无效用户id');
- }
-
- $events_id = Request::g('events_id');
- if (!Verify::unsignedInt($events_id)) {
- self::ajax_fail_exit('无效活动id');
- }
-
- $objMlottery = new Lottery();
- $eventsData = $objMlottery->getOneLotteryEvents($events_id);
-
-
- if($thisTime < $eventsData['begin_time'] || $thisTime > $eventsData['end_time']){
- self::ajax_fail_exit('当前活动未开始');
- }
-
-
- $objMLotteryEventsLimitations = new LotteryEventsLimitations();
- if(!$objMLotteryEventsLimitations->ckEventRestrictions($uid,Request::ip(), $events_id)){
- self::ajax_fail_exit('请勿重复参与');
- }
-
-
-
-
- $forms = $eventsData['forms'];
- $formData = Filter::arrayfilter($_POST, true);
- $objLotteryEventsForms = new LotteryEventsForms();
- $tmpVerifyResult = $objLotteryEventsForms->verifyFormData($forms, $formData);
- if (!$tmpVerifyResult->isSuccess()) {
- self::ajax_fail_exit($tmpVerifyResult->getData());
- }
-
-
- $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id));
- if (!$objLotteryEventsForms->add($info)) {
- self::ajax_fail_exit('数据库操作失败');
- }
-
-
- $objMLotteryEventsLimitations->setUserEventNum($uid, $events_id);
- $objMLotteryEventsLimitations->setIpEventNum(Request::ip(),$events_id);
- $objMLotteryEventsLimitations->setUserParticipationNum($uid, $events_id);
-
- $surveyAnswer = json_decode(Request::g('answer', null), true);
-
- $selectAnswers = '';
- foreach ($surveyAnswer as $tmpKey => $tmpAnswer) {
- $surveyAnswer[$tmpKey] = $tmpAnswer = trim($tmpAnswer, ',');
- }
-
-
- $other = array(
- '选择内容:' => join(' | ', $surveyAnswer),
- '表单内容:' => join(',', $formData),
- );
- $objMLotteryLog = new LotteryLog($uid,$events_id);
- $objMLotteryLog ->addLog(\Cas\Dao\LotteryEventsLog::LOG_TYPE_PARTICIPATION_TRUE, $other);
- $objMLotteryLog->addUserParticipateLog($other);
-
- self::ajax_success_exit();
- }
-
-
-
- public function display() {
- return $this->render();
- }
- }
|