EventsTurntable.class.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Module\LotteryEventsTypeTurntable;
  4. use Cas\Dao\LotteryEvents;
  5. use KIF\Dao\SqlHelper;
  6. use Cas\Module\Lottery;
  7. use Cas\Dao\LotteryUserExpress;
  8. use KIF\Core\Request;
  9. use KIF\Verify;
  10. use Cas\Module\LotteryEventsTypeTry;
  11. use Cas\Dao\UserInfo;
  12. use Cas\Module\Count;
  13. use Cas\Dao\Platform;
  14. /**
  15. * 转盘
  16. * lihuanchun
  17. */
  18. class EventsTurntable extends EventsController {
  19. public function doDefault() {
  20. $thisTime = time();
  21. $events_id = $this->getEventsCreateTimeToId();
  22. //$events_id = Request::g('events_id');
  23. if (!Verify::unsignedInt($events_id)) {
  24. self::fail_exit('无效id');
  25. }
  26. # 获取用户信息
  27. $objUserData = new UserInfo();
  28. $uid = $this->getRunTimeUid();
  29. $userData = $objUserData -> get($uid);
  30. $this->setOutput('userData', $userData);
  31. # 获取转盘信息 & 8 个位置的奖品
  32. $objLotteryEventsTypeTurntable = new LotteryEventsTypeTurntable($uid,$events_id);
  33. $turntableData = $objLotteryEventsTypeTurntable -> getEventsData();
  34. # 检查是否移动端
  35. $title = $turntableData['events']['weixinShare']['title'] ? $turntableData['events']['weixinShare']['title'] : $turntableData['events']['events_name'];
  36. //$this->checkIsFromMobile($title);
  37. # 获取试用信息
  38. $objLotteryEventsTypeTry = new LotteryEventsTypeTry($uid, $events_id);
  39. $tryInfo = $objLotteryEventsTypeTry->getEventsData();
  40. # 获取登录地址
  41. $url = Request::g('url');
  42. $plat_form_id = $this->getPlatFormId();
  43. $objMLottery = new Lottery();
  44. $thisUrl = $objMLottery -> getEventsUrl($turntableData['events']['type'],$turntableData['events']['create_time'],$url);
  45. $loginUrl = $this -> getLoginUrl($thisUrl);
  46. $this->setOutput('loginUrl', $loginUrl);
  47. # 判断是否需要登录
  48. $ckLogin = $this->ckLogin();
  49. $this->setOutput('ckLogin', $ckLogin);
  50. # 其他开始活动
  51. $objDLottery = new Lottery();
  52. $condition = array(
  53. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW,
  54. 'id' => SqlHelper::addCompareOperator('!=', $events_id),
  55. 'begin_time' => SqlHelper::addCompareOperator('<', $thisTime),
  56. 'end_time' => SqlHelper::addCompareOperator('>', $thisTime)
  57. );
  58. $otherEventsData = $objDLottery -> getLotteryEventsList($condition, 3, 'id desc');
  59. # 检查当前活动是否需要登录
  60. $authorize = $turntableData['events']['authorize'];
  61. if ($authorize && $loginUrl) {
  62. if($ckLogin==true){
  63. //self::redirect($loginUrl);
  64. }
  65. }
  66. # 活动状态
  67. $TIME = time();
  68. $eventsStatus = false;
  69. if($TIME < $turntableData['events']['begin_time'] ){
  70. $eventsStatus = 'STATUS_NOT_START';
  71. } elseif ($TIME > $turntableData['events']['end_time']){
  72. $eventsStatus = 'STATUS_HAS_END';
  73. } elseif ($turntableData['events']['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
  74. //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象列表
  75. }
  76. # 获取用户最新收货地址
  77. $objDLotteryUserExpress = new LotteryUserExpress();
  78. $userExpress = $objDLotteryUserExpress -> getUserExpress($uid);
  79. # 页面渲染所需JSON
  80. $jsonTurntableData = array();
  81. foreach($turntableData['turntable_prizes'] as $key => $data){
  82. if(is_array($data)){
  83. $jsonTurntableData[$data['id']] = $key;
  84. }else{
  85. $jsonTurntableData['NoPrize'] = $key;
  86. }
  87. }
  88. $this->info($turntableData['events']);
  89. # 记录PV UV日志 访问
  90. $objCount = new Count();
  91. $objCount->setPassLog( $events_id,$plat_form_id);
  92. # 视频播放
  93. preg_match_all('/<embed\s{1}src=\"([^\"]+)\"[^>]+>/i', $turntableData['events']['events_tips'], $matches);
  94. if ($matches) foreach ($matches[0] as $key => $tmpMatch) {
  95. $tmp_new_video_html = '<iframe class="video_iframe" height=498 width=510 src="'.$matches[1][$key].'" frameborder=0 allowfullscreen></iframe>';
  96. $turntableData['events']['events_tips'] = str_replace($tmpMatch, $tmp_new_video_html, $turntableData['events']['events_tips']);
  97. }
  98. $jsonTurntableData = json_encode($jsonTurntableData);
  99. $this->tpl = 'events_turntable';
  100. $this->setOutput('title', $turntableData['events']['weixinShare']['title'] ? $turntableData['events']['weixinShare']['title'] : $turntableData['events']['events_name']);
  101. //print_r($turntableData);die;
  102. $this->setOutput('display', $turntableData['events']['list_display']);
  103. $this->setOutput('jsonTurntableData', $jsonTurntableData);
  104. $this->setOutput('turntableData', $turntableData);
  105. $this->setOutput('otherEventsData', $otherEventsData);
  106. $this->setOutput('eventsStatus', $eventsStatus);
  107. $this->setOutput('weixinShare', $turntableData['events']['weixinShare']);
  108. }
  109. /**
  110. * 转盘动作
  111. */
  112. public function doRotation() {
  113. # 获取转盘信息
  114. $events_id = Request::g('events_id');
  115. if (!Verify::unsignedInt($events_id)) {
  116. self::fail_exit('无效id');
  117. }
  118. $uid = $this->getRunTimeUid();
  119. $objLotteryEventsTypeTurntable = new LotteryEventsTypeTurntable($uid,$events_id);
  120. $turntableData = $objLotteryEventsTypeTurntable -> getEventsData();
  121. # 检查当前活动是否需要登录 & 获取登录地址
  122. $plat_form_id = $this->getPlatFormId();
  123. $objPlatForm = new Platform();
  124. $form = $objPlatForm -> get($plat_form_id);
  125. $url = $form['url'];
  126. $objMLottery = new Lottery();
  127. $thisUrl = $objMLottery -> getEventsUrl($turntableData['events']['type'],$turntableData['events']['create_time'],$url);
  128. $loginUrl = $this -> getLoginUrl($thisUrl);
  129. $authorize = $turntableData['events']['authorize'];
  130. if ($authorize && $loginUrl) {
  131. $ckLogin = $this->ckLogin();
  132. if($ckLogin==true){
  133. self::ajax_fail_exit(array('url' =>$loginUrl));
  134. }
  135. }
  136. $tmpLotteryData = $objLotteryEventsTypeTurntable ->sweepstakes();
  137. if(!$tmpLotteryData -> isSuccess()){
  138. self::ajax_fail_exit($tmpLotteryData->getData());
  139. }
  140. $lotteryData = $tmpLotteryData -> getData();
  141. $prize_id = $lotteryData['prize_id'];
  142. $thisPrizeData = array();
  143. $thisPrizeData['prize_name'] = $turntableData['prize'][$prize_id]['prize_name'];
  144. $thisPrizeData['id'] = $prize_id;
  145. $thisPrizeData['lottery_data_id'] = $lotteryData['id'];
  146. $thisPrizeData['express'] = $turntableData['prize'][$prize_id]['express'];
  147. $thisPrizeData['img_url'] = $turntableData['prize'][$prize_id]['img_url'];
  148. $thisPrizeData['express'] = $turntableData['prize'][$prize_id]['express'];
  149. $thisPrizeData['type'] = $turntableData['prize'][$prize_id]['type'];
  150. $thisPrizeData['virtual_data'] = isset($lotteryData['virtual_data'])?$lotteryData['virtual_data']:'';
  151. self::ajax_success_exit($thisPrizeData);
  152. }
  153. public function display() {
  154. return $this->render();
  155. }
  156. }