<?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() { /* * 零時執行 $str = 'a:22:{s:7:"img_url";s:69:"http://opcdn.sg.com.cn/public/upload/image/2015/1104/144152_35190.jpg";s:11:"weixinShare";a:4:{s:6:"imgUrl";s:69:"http://opcdn.sg.com.cn/public/upload/image/2015/1104/144437_37174.jpg";s:5:"title";s:57:"《精品购物指南》双十一互动答问卷送大礼";s:7:"content";s:21:"扫一扫立即参加";s:8:"jump_url";s:0:"";}s:9:"authorize";s:1:"0";s:22:"participation_user_num";s:1:"0";s:20:"participation_ip_num";s:1:"0";s:26:"participation_user_all_num";s:1:"1";s:16:"winning_user_num";b:0;s:6:"cut_fx";b:0;s:9:"music_url";b:0;s:9:"other_url";b:0;s:14:"music_position";b:0;s:16:"loading_bg_color";b:0;s:18:"loading_text_color";b:0;s:11:"setPageType";s:11:"Interactive";s:16:"survery_question";a:14:{i:1;a:4:{s:8:"question";s:45:"1. 您生活在哪个城市?(单选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:5:{i:1;a:1:{s:6:"answer";s:6:"北京";}i:2;a:1:{s:6:"answer";s:6:"上海";}i:3;a:1:{s:6:"answer";s:6:"广州";}i:4;a:1:{s:6:"answer";s:18:"国内其他城市";}i:5;a:1:{s:6:"answer";s:6:"海外";}}}i:2;a:4:{s:8:"question";s:42:"2. 请问您的性别是?(单选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:2:{i:1;a:1:{s:6:"answer";s:6:"男性";}i:2;a:1:{s:6:"answer";s:6:"女性";}}}i:3;a:4:{s:8:"question";s:42:"3. 请问您的年龄是?(单选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:9:{i:1;a:1:{s:6:"answer";s:16:"18 岁及以下 ";}i:2;a:1:{s:6:"answer";s:14:"18 ~ 20 岁 ";}i:3;a:1:{s:6:"answer";s:14:"21 ~ 25 岁 ";}i:4;a:1:{s:6:"answer";s:13:"26 ~ 30 岁";}i:5;a:1:{s:6:"answer";s:13:"31 ~ 35 岁";}i:6;a:1:{s:6:"answer";s:14:"36 ~ 40 岁 ";}i:7;a:1:{s:6:"answer";s:14:"41 ~ 45 岁 ";}i:8;a:1:{s:6:"answer";s:13:"46 ~ 0 岁 ";}i:9;a:1:{s:6:"answer";s:12:"50 岁以上";}}}i:4;a:4:{s:8:"question";s:42:"4. 请问您的学历是?(单选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:4:{i:1;a:1:{s:6:"answer";s:16:"硕士及以上 ";}i:2;a:1:{s:6:"answer";s:13:"大学本科 ";}i:3;a:1:{s:6:"answer";s:12:"大学专科";}i:4;a:1:{s:6:"answer";s:12:"高中以下";}}}i:5;a:4:{s:8:"question";s:42:"5. 请问您的职业是?(单选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:9:{i:1;a:1:{s:6:"answer";s:6:"学生";}i:2;a:1:{s:6:"answer";s:6:"工人";}i:3;a:1:{s:6:"answer";s:6:"白领";}i:4;a:1:{s:6:"answer";s:18:"时尚艺术方面";}i:5;a:1:{s:6:"answer";s:12:"自主经营";}i:6;a:1:{s:6:"answer";s:12:"企业老板";}i:7;a:1:{s:6:"answer";s:12:"全职太太";}i:8;a:1:{s:6:"answer";s:12:"自由职业";}i:9;a:1:{s:6:"answer";s:21:"其他(请写出)";}}}i:6;a:4:{s:8:"question";s:76:" 6. 您在过去一年中,网上购衣的次数大约是?(单选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:9:{i:1;a:1:{s:6:"answer";s:13:"100 元以下";}i:2;a:1:{s:6:"answer";s:24:"101 元~ 300 元左右";}i:3;a:1:{s:6:"answer";s:24:"301 元~ 500 元左右";}i:4;a:1:{s:6:"answer";s:25:"501 元~ -800 元左右";}i:5;a:1:{s:6:"answer";s:25:"801 元~ 2000 元左右";}i:6;a:1:{s:6:"answer";s:26:"2001 元~ 5000 元左右";}i:7;a:1:{s:6:"answer";s:26:"5001 元~ 8000 元左右";}i:8;a:1:{s:6:"answer";s:27:"8001 元~ 10000 元左右";}i:9;a:1:{s:6:"answer";s:15:"10000 元以上";}}}i:7;a:4:{s:8:"question";s:63:"8. 您的购买时机一般是在什么时候?(多选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"1";s:6:"answer";a:5:{i:1;a:1:{s:6:"answer";s:15:"季节交替时";}i:2;a:1:{s:6:"answer";s:21:"商品打折促销时";}i:3;a:1:{s:6:"answer";s:15:"新款上市时";}i:4;a:1:{s:6:"answer";s:6:"节日";}i:5;a:1:{s:6:"answer";s:30:"随意,根据自己的需要";}}}i:8;a:4:{s:8:"question";s:72:"9. 请问您在网上购买最多的是哪一类商品?(多选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"1";s:6:"answer";a:9:{i:1;a:1:{s:6:"answer";s:12:"生活用品";}i:2;a:1:{s:6:"answer";s:12:"家用电器";}i:3;a:1:{s:6:"answer";s:21:"服饰、鞋帽、包";}i:4;a:1:{s:6:"answer";s:15:"数码产品等";}i:5;a:1:{s:6:"answer";s:15:"美容彩妆品";}i:6;a:1:{s:6:"answer";s:6:"食品";}i:7;a:1:{s:6:"answer";s:6:"书籍";}i:8;a:1:{s:6:"answer";s:13:"母婴产品 ";}i:9;a:1:{s:6:"answer";s:21:"其他(请写出)";}}}i:9;a:4:{s:8:"question";s:68:"10. 您每月会花多少钱在护肤彩妆品方面?( 单选题 )";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:4:{i:1;a:1:{s:6:"answer";s:13:"500 元以下";}i:2;a:1:{s:6:"answer";s:19:"500 元~ 1000 元";}i:3;a:1:{s:6:"answer";s:20:"1001 元~ 2000 元";}i:4;a:1:{s:6:"answer";s:14:"3000 元以上";}}}i:10;a:4:{s:8:"question";s:64:"11. 购买新衣服时您最看重哪些方面?(多选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"1";s:6:"answer";a:5:{i:1;a:1:{s:6:"answer";s:6:"款式";}i:2;a:1:{s:6:"answer";s:6:"价钱";}i:3;a:1:{s:6:"answer";s:30:"是否符合我自己的审美";}i:4;a:1:{s:6:"answer";s:6:"质量";}i:5;a:1:{s:6:"answer";s:6:"品牌";}}}i:11;a:4:{s:8:"question";s:58:"12. 您最喜欢的网购促销手段是?(单选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:7:{i:1;a:1:{s:6:"answer";s:6:"打折";}i:2;a:1:{s:6:"answer";s:12:"购物返券";}i:3;a:1:{s:6:"answer";s:6:"积分";}i:4;a:1:{s:6:"answer";s:9:"免运费";}i:5;a:1:{s:6:"answer";s:12:"购物送礼";}i:6;a:1:{s:6:"answer";s:6:"团购";}i:7;a:1:{s:6:"answer";s:12:"专题促销";}}}i:12;a:4:{s:8:"question";s:58:"13. 您最喜欢的支付方式是哪种?(单选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"0";s:6:"answer";a:5:{i:1;a:1:{s:6:"answer";s:9:"支付宝";}i:2;a:1:{s:6:"answer";s:12:"微信支付";}i:3;a:1:{s:6:"answer";s:15:"银行卡转账";}i:4;a:1:{s:6:"answer";s:12:"货到付款";}i:5;a:1:{s:6:"answer";s:21:"其他(请填写)";}}}i:13;a:4:{s:8:"question";s:67:"14. 如果您对网购好的产品不满意,原因可能会是?";s:4:"type";s:3:"txt";s:6:"choice";s:1:"1";s:6:"answer";a:5:{i:1;a:1:{s:6:"answer";s:24:"产品比其他地方贵";}i:2;a:1:{s:6:"answer";s:12:"质量不好";}i:3;a:1:{s:6:"answer";s:15:"配送速度慢";}i:4;a:1:{s:6:"answer";s:18:"包装不够精良";}i:5;a:1:{s:6:"answer";s:18:"没有想象中好";}}}i:14;a:4:{s:8:"question";s:70:"15. 您的购买信息是通过什么途径获取的?(多选题)";s:4:"type";s:3:"txt";s:6:"choice";s:1:"1";s:6:"answer";a:9:{i:1;a:1:{s:6:"answer";s:12:"门户网站";}i:2;a:1:{s:6:"answer";s:12:"购物网站";}i:3;a:1:{s:6:"answer";s:6:"社区";}i:4;a:1:{s:6:"answer";s:6:"微博";}i:5;a:1:{s:6:"answer";s:15:"微信公众号";}i:6;a:1:{s:6:"answer";s:9:"朋友圈";}i:7;a:1:{s:6:"answer";s:12:"实体店铺";}i:8;a:1:{s:6:"answer";s:12:"户外广告";}i:9;a:1:{s:6:"answer";s:6:"报刊";}}}}s:11:"events_tips";s:231:"回馈各位读者的时间到了!进入互动问答页面,只需回答几个问题并留下名字、联系方式(很重要),就有机会得到《精品购物指南》特别为你准备的双十一购物大礼包。<br />";s:14:"events_hd_tips";s:21:"填写问卷赢大礼";s:12:"events_rules";s:16:"<p> <br /> </p>";s:15:"operationt_tips";s:0:"";s:13:"survery_prize";a:2:{i:1;a:4:{s:4:"name";s:24:"高姿世博限量套装";s:7:"img_url";s:69:"http://opcdn.sg.com.cn/public/upload/image/2015/1104/143703_40713.jpg";s:3:"num";s:1:"4";s:9:"unit_name";s:3:"份";}i:2;a:4:{s:4:"name";s:40:"格兰玛弗兰萝西滋润护手霜60ml";s:7:"img_url";s:69:"http://opcdn.sg.com.cn/public/upload/image/2015/1104/143735_25149.jpg";s:3:"num";s:2:"50";s:9:"unit_name";s:3:"份";}}s:8:"delivery";s:1:"1";s:5:"forms";a:3:{i:2;a:3:{s:4:"name";s:6:"姓名";s:4:"type";s:4:"text";s:8:"required";s:1:"1";}i:3;a:4:{s:4:"name";s:9:"手机号";s:4:"type";s:4:"text";s:4:"rule";a:2:{s:9:"regularid";s:1:"1";s:7:"regular";s:49:"/^(1[0-9][0-9]|15[0-9]|18[02-9]|14[57])[0-9]{8}$/";}s:8:"required";s:1:"1";}i:4;a:3:{s:4:"name";s:12:"收货地址";s:4:"type";s:4:"text";s:8:"required";s:1:"1";}}}'; $arr = unserialize($str); unset( $arr['survery_question'][5]['answer'][9] ); unset( $arr['survery_question'][8]['answer'][9] ); unset( $arr['survery_question'][12]['answer'][5] ); $objD = new LotteryEvents(); $objD -> modify($arr,array('id'=>141)); exit('end'); */ $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); # 记录PV UV日志 访问 $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) { //$eventsStatus = 'STATUS_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(); # 1.必要参数验证 $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('请勿重复参与'); } # 3.用户表单验证 $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()); } # 4.保存表单内容 $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id)); if (!$objLotteryEventsForms->add($info)) { self::ajax_fail_exit('数据库操作失败'); } # 5.增加行为记录 $objMLotteryEventsLimitations->setUserEventNum($uid, $events_id); // 记录用户参与UID(天) $objMLotteryEventsLimitations->setIpEventNum(Request::ip(),$events_id);// 记录用户参与IP(天) $objMLotteryEventsLimitations->setUserParticipationNum($uid, $events_id); // 记录用户参与次数 $surveyAnswer = json_decode(Request::g('answer', null), true); $selectAnswers = ''; foreach ($surveyAnswer as $tmpKey => $tmpAnswer) { $surveyAnswer[$tmpKey] = $tmpAnswer = trim($tmpAnswer, ','); } # 6 记录参与日志 $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(); } }