EventsSurvey.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Dao\LotteryUserExpress;
  4. use KIF\Core\Request;
  5. use KIF\Verify;
  6. use Cas\Module\LotteryEventsTypeTry;
  7. use KIF\String\Filter;
  8. use Cas\Dao\LotteryEventsForms;
  9. use Cas\Dao\UserInfo;
  10. use Cas\Module\Count;
  11. use Cas\Module\Lottery;
  12. use Cas\Dao\LotteryEvents;
  13. use Cas\Module\LotteryEventsLimitations;
  14. use Cas\Module\LotteryLog;
  15. use KIF\Cookie;
  16. /**
  17. * 调查问卷
  18. */
  19. class EventsSurvey extends EventsController {
  20. public function doDefault() {
  21. /*
  22. * 零時執行
  23. $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>
  24. <br />
  25. </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";}}}';
  26. $arr = unserialize($str);
  27. unset( $arr['survery_question'][5]['answer'][9] );
  28. unset( $arr['survery_question'][8]['answer'][9] );
  29. unset( $arr['survery_question'][12]['answer'][5] );
  30. $objD = new LotteryEvents();
  31. $objD -> modify($arr,array('id'=>141));
  32. exit('end');
  33. */
  34. $thisTime = time();
  35. $events_id = $this->getEventsCreateTimeToId();
  36. if (!Verify::unsignedInt($events_id)) {
  37. self::fail_exit('无效id');
  38. }
  39. # 获取用户信息
  40. $objUserData = new UserInfo();
  41. $uid = $this->getRunTimeUid();
  42. $userData = $objUserData -> get($uid);
  43. $this->setOutput('userData', $userData);
  44. # 获取试用信息
  45. $objDLotteryEvents = new LotteryEvents();
  46. $surveyInfo = $objDLotteryEvents -> get($events_id);
  47. # 检查是否移动端
  48. $title = $surveyInfo['weixinShare']['title'] ? $surveyInfo['weixinShare']['title'] : $surveyInfo['events_name'];
  49. $this->checkIsFromMobile($title);
  50. # 获取登录地址
  51. $url = Request::g('url');
  52. $plat_form_id = $this->getPlatFormId();
  53. $objMLottery = new Lottery();
  54. $thisUrl = $objMLottery -> getEventsUrl($surveyInfo['type'],$surveyInfo['create_time'],$url);
  55. $loginUrl = $this -> getLoginUrl($thisUrl);
  56. $this->setOutput('loginUrl', $loginUrl);
  57. # 判断是否需要登录
  58. $ckLogin = $this->ckLogin();
  59. $this->setOutput('ckLogin', $ckLogin);
  60. # 检查当前活动是否需要登录
  61. $authorize =$surveyInfo['authorize'];
  62. if ($authorize && $loginUrl) {
  63. if($ckLogin==true){
  64. self::redirect($loginUrl);
  65. }
  66. }
  67. $this->info($surveyInfo);
  68. # 记录PV UV日志 访问
  69. $objCount = new Count();
  70. $objCount->setPassLog( $events_id,$plat_form_id);
  71. # 活动状态
  72. $TIME = time();
  73. $eventsStatus = false;
  74. $objMLotteryEventsLimitations = new LotteryEventsLimitations();
  75. if($TIME < $surveyInfo['begin_time'] ){
  76. $eventsStatus = 'STATUS_NOT_START';
  77. } elseif ($TIME > $surveyInfo['end_time']){
  78. $eventsStatus = 'STATUS_HAS_END';
  79. } elseif ($surveyInfo['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
  80. //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象列表
  81. }elseif (!$objMLotteryEventsLimitations->ckEventRestrictions($uid,Request::ip(), $events_id)) {
  82. $eventsStatus = 'STATUS_HAS_RESTRTICTIONS';
  83. }
  84. if (Cookie::get('SURVEY_IS_UNDERWAY') >= 2) {
  85. Cookie::set('SURVEY_IS_UNDERWAY', 1, null, $_SERVER['HTTP_HOST'], '/');
  86. $this->setOutput('zepto', 1);
  87. $this->setOutput('display', $surveyInfo['list_display']);
  88. $this->tpl = 'events_survey_underway';
  89. } else {
  90. $this->setOutput('display', $surveyInfo['list_display']);
  91. $this->tpl = 'events_survey';
  92. }
  93. # 视频播放
  94. preg_match_all('/<embed\s{1}src=\"([^\"]+)\"[^>]+>/i', $surveyInfo['events_tips'], $matches);
  95. if ($matches) foreach ($matches[0] as $key => $tmpMatch) {
  96. $tmp_new_video_html = '<iframe class="video_iframe" height=498 width=510 src="'.$matches[1][$key].'" frameborder=0 allowfullscreen></iframe>';
  97. $surveyInfo['events_tips'] = str_replace($tmpMatch, $tmp_new_video_html, $surveyInfo['events_tips']);
  98. }
  99. $this->setOutput('eventsStatus', $eventsStatus);
  100. $this->setOutput('title', $surveyInfo['weixinShare']['title'] ? $surveyInfo['weixinShare']['title'] : $surveyInfo['events_name']);
  101. $this->setOutput('surveyInfo', $surveyInfo);
  102. $this->setOutput('forms', $surveyInfo['forms']);
  103. $this->setOutput('weixinShare', $surveyInfo['weixinShare']);
  104. }
  105. public function doSubmit() {
  106. $thisTime = time();
  107. # 1.必要参数验证
  108. $uid = $this->getRunTimeUid();
  109. if (!Verify::unsignedInt($uid)) {
  110. self::ajax_fail_exit('无效用户id');
  111. }
  112. $events_id = Request::g('events_id');
  113. if (!Verify::unsignedInt($events_id)) {
  114. self::ajax_fail_exit('无效活动id');
  115. }
  116. $objMlottery = new Lottery();
  117. $eventsData = $objMlottery->getOneLotteryEvents($events_id);
  118. # 活动是否开始
  119. if($thisTime < $eventsData['begin_time'] || $thisTime > $eventsData['end_time']){
  120. self::ajax_fail_exit('当前活动未开始');
  121. }
  122. # 活动的 用户行为限制
  123. $objMLotteryEventsLimitations = new LotteryEventsLimitations();
  124. if(!$objMLotteryEventsLimitations->ckEventRestrictions($uid,Request::ip(), $events_id)){
  125. self::ajax_fail_exit('请勿重复参与');
  126. }
  127. # 3.用户表单验证
  128. $forms = $eventsData['forms'];
  129. $formData = Filter::arrayfilter($_POST, true);
  130. $objLotteryEventsForms = new LotteryEventsForms();
  131. $tmpVerifyResult = $objLotteryEventsForms->verifyFormData($forms, $formData);
  132. if (!$tmpVerifyResult->isSuccess()) {
  133. self::ajax_fail_exit($tmpVerifyResult->getData());
  134. }
  135. # 4.保存表单内容
  136. $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id));
  137. if (!$objLotteryEventsForms->add($info)) {
  138. self::ajax_fail_exit('数据库操作失败');
  139. }
  140. # 5.增加行为记录
  141. $objMLotteryEventsLimitations->setUserEventNum($uid, $events_id); // 记录用户参与UID(天)
  142. $objMLotteryEventsLimitations->setIpEventNum(Request::ip(),$events_id);// 记录用户参与IP(天)
  143. $objMLotteryEventsLimitations->setUserParticipationNum($uid, $events_id); // 记录用户参与次数
  144. $surveyAnswer = json_decode(Request::g('answer', null), true);
  145. $selectAnswers = '';
  146. foreach ($surveyAnswer as $tmpKey => $tmpAnswer) {
  147. $surveyAnswer[$tmpKey] = $tmpAnswer = trim($tmpAnswer, ',');
  148. }
  149. # 6 记录参与日志
  150. $other = array(
  151. '选择内容:' => join(' | ', $surveyAnswer),
  152. '表单内容:' => join(',', $formData),
  153. );
  154. $objMLotteryLog = new LotteryLog($uid,$events_id);
  155. $objMLotteryLog ->addLog(\Cas\Dao\LotteryEventsLog::LOG_TYPE_PARTICIPATION_TRUE, $other);
  156. $objMLotteryLog->addUserParticipateLog($other);
  157. self::ajax_success_exit();
  158. }
  159. public function display() {
  160. return $this->render();
  161. }
  162. }