EventsVote.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Module\LotteryEventsLimitations;
  4. use KIF\Core\Request;
  5. use KIF\Verify;
  6. use Cas\Module\LotteryEventsTypeVote;
  7. use Cas\Dao\UserInfo;
  8. use Cas\Dao\Platform;
  9. use Cas\Module\Count;
  10. use Cas\Module\Lottery;
  11. /**
  12. *
  13. * 投票
  14. */
  15. class EventsVote extends EventsController {
  16. public function doDefault() {
  17. //$events_id = Request::g('events_id');
  18. $events_id = $this->getEventsCreateTimeToId();
  19. if (!Verify::unsignedInt($events_id)) {
  20. self::fail_exit('无效id');
  21. }
  22. $url = Request::g('url');
  23. # 判断是否需要登录
  24. $ckLogin = $this->ckLogin();
  25. $this->setOutput('ckLogin', $ckLogin);
  26. # 获取用户信息
  27. $objUserData = new UserInfo();
  28. $uid = $this->getRunTimeUid();
  29. $userData = $objUserData -> get($uid);
  30. $this->setOutput('userData', $userData);
  31. $objLotteryEventsTypeVote = new LotteryEventsTypeVote($uid, $events_id);
  32. $voteInfo = $objLotteryEventsTypeVote->getEventsData();
  33. # 检查是否移动端
  34. $title = $voteInfo['weixinShare']['title'] ? $voteInfo['weixinShare']['title'] : $voteInfo['events_name'];
  35. $this->checkIsFromMobile($title);
  36. # 获取登录地址
  37. $plat_form_id = $this->getPlatFormId();
  38. $objMLottery = new Lottery();
  39. $thisUrl = $objMLottery -> getEventsUrl($voteInfo['type'],$voteInfo['create_time'],$url);
  40. $loginUrl = $this -> getLoginUrl($thisUrl);
  41. $this->setOutput('loginUrl', $loginUrl);
  42. # 检查当前活动是否需要登录
  43. $authorize = $voteInfo['authorize'];
  44. if ($authorize && $loginUrl) {
  45. if($ckLogin==true){
  46. self::redirect($loginUrl);
  47. }
  48. }
  49. # 活动状态
  50. $TIME = time();
  51. $eventsStatus = false;
  52. if($TIME < $voteInfo['begin_time'] ){
  53. $eventsStatus = 'STATUS_NOT_START';
  54. } elseif ($TIME > $voteInfo['end_time']){
  55. $eventsStatus = 'STATUS_HAS_END';
  56. } elseif ($voteInfo['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
  57. //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象列表
  58. }
  59. # 活动是否已经到达了当前用户上线
  60. $objMLotteryEventsLimitations = new LotteryEventsLimitations();
  61. if(!$objMLotteryEventsLimitations->ckEventRestrictions($uid,Request::ip(), $events_id)){
  62. $eventsStatus = 'STATUS_LIMITATIONS'; //先注释了。此隐藏 之印象列表
  63. }
  64. # 投票项颜色
  65. $cell_colors = array('v_color_1','v_color_2','v_color_3','v_color_4','v_color_5','v_color_6','v_color_7','v_color_8');
  66. shuffle($cell_colors);
  67. $total_vote_num = 0;
  68. foreach ($voteInfo['vote'] as $tmpkey => $tmpvote) {
  69. $total_vote_num += ($tmpvote['num']+$tmpvote['add_num']);
  70. }
  71. $voteInfo['total_vote_num'] = $total_vote_num;
  72. foreach ($voteInfo['vote'] as $tmpkey => $tmpvote) {
  73. $voteInfo['vote'][$tmpkey]['per_num'] = round(($tmpvote['num']+$tmpvote['add_num'])/$total_vote_num*100);
  74. }
  75. $this->info($voteInfo);
  76. # 记录PV UV日志 访问
  77. $objCount = new Count();
  78. $objCount->setPassLog( $events_id,$plat_form_id);
  79. # 视频播放
  80. preg_match_all('/<embed\s{1}src=\"([^\"]+)\"[^>]+>/i', $voteInfo['events_tips'], $matches);
  81. if ($matches) foreach ($matches[0] as $key => $tmpMatch) {
  82. $tmp_new_video_html = '<iframe class="video_iframe" height=498 width=510 src="'.$matches[1][$key].'" frameborder=0 allowfullscreen></iframe>';
  83. $voteInfo['events_tips'] = str_replace($tmpMatch, $tmp_new_video_html, $voteInfo['events_tips']);
  84. }
  85. $this->tpl = 'events_vote';
  86. $this->setOutput('title', $voteInfo['weixinShare']['title'] ? $voteInfo['weixinShare']['title'] : $voteInfo['events_name']);
  87. $this->setOutput('display', $voteInfo['list_display']);
  88. $this->setOutput('vote_type', $voteInfo['vote_type']);
  89. $this->setOutput('voteInfo', $voteInfo);
  90. $this->setOutput('weixinShare', $voteInfo['weixinShare']);
  91. $this->setOutput('eventsStatus', $eventsStatus);
  92. $this->setOutput('cell_colors', json_encode($cell_colors));
  93. }
  94. public function doVote() {
  95. $events_id = Request::g('events_id');
  96. if (!Verify::unsignedInt($events_id)) {
  97. self::ajax_fail_exit('无效id');
  98. }
  99. $vote_id = Request::g('voteid');
  100. if (!Verify::unsignedInt($events_id)) {
  101. self::ajax_fail_exit('无效投票项id');
  102. }
  103. $uid = $this->getRunTimeUid();
  104. $objLotteryEventsTypeVote = new LotteryEventsTypeVote($uid, $events_id);
  105. $voteInfo = $objLotteryEventsTypeVote->getEventsData();
  106. # 检查当前活动是否需要登录 & 获取登录地址
  107. $plat_form_id = $this->getPlatFormId();
  108. $objPlatForm = new Platform();
  109. $form = $objPlatForm -> get($plat_form_id);
  110. $url = $form['url'];
  111. $objMLottery = new Lottery();
  112. $thisUrl = $objMLottery -> getEventsUrl($voteInfo['type'],$voteInfo['create_time'],$url);
  113. $loginUrl = $this -> getLoginUrl($thisUrl);
  114. $authorize =$voteInfo['authorize'];
  115. if ($authorize && $loginUrl) {
  116. $ckLogin = $this->ckLogin();
  117. if($ckLogin==true){
  118. self::ajax_fail_exit(array('url' =>$loginUrl));
  119. }
  120. }
  121. $tmpResult = $objLotteryEventsTypeVote->vote($vote_id);
  122. if (!$tmpResult->isSuccess()) {
  123. self::ajax_fail_exit($tmpResult->getData());
  124. }
  125. self::ajax_success_exit();
  126. }
  127. public function display() {
  128. return $this->render();
  129. }
  130. }