EventsTurntable.class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. $plat_form_id = $this->getPlatFormId();
  92. $objCount->setPassLog( $events_id,$plat_form_id);
  93. # 视频播放
  94. preg_match_all('/<embed\s{1}src=\"([^\"]+)\"[^>]+>/i', $turntableData['events']['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. $turntableData['events']['events_tips'] = str_replace($tmpMatch, $tmp_new_video_html, $turntableData['events']['events_tips']);
  98. }
  99. $jsonTurntableData = json_encode($jsonTurntableData);
  100. $this->tpl = 'events_turntable';
  101. $this->setOutput('title', $turntableData['events']['weixinShare']['title'] ? $turntableData['events']['weixinShare']['title'] : $turntableData['events']['events_name']);
  102. //print_r($turntableData);die;
  103. $this->setOutput('display', $turntableData['events']['list_display']);
  104. $this->setOutput('jsonTurntableData', $jsonTurntableData);
  105. $this->setOutput('turntableData', $turntableData);
  106. $this->setOutput('otherEventsData', $otherEventsData);
  107. $this->setOutput('eventsStatus', $eventsStatus);
  108. $this->setOutput('weixinShare', $turntableData['events']['weixinShare']);
  109. }
  110. /**
  111. * 转盘动作
  112. */
  113. public function doRotation() {
  114. # 获取转盘信息
  115. $events_id = Request::g('events_id');
  116. if (!Verify::unsignedInt($events_id)) {
  117. self::fail_exit('无效id');
  118. }
  119. $uid = $this->getRunTimeUid();
  120. $objLotteryEventsTypeTurntable = new LotteryEventsTypeTurntable($uid,$events_id);
  121. $turntableData = $objLotteryEventsTypeTurntable -> getEventsData();
  122. # 检查当前活动是否需要登录 & 获取登录地址
  123. $plat_form_id = $this->getPlatFormId();
  124. $objPlatForm = new Platform();
  125. $form = $objPlatForm -> get($plat_form_id);
  126. $url = $form['url'];
  127. $objMLottery = new Lottery();
  128. $thisUrl = $objMLottery -> getEventsUrl($turntableData['events']['type'],$turntableData['events']['create_time'],$url);
  129. $loginUrl = $this -> getLoginUrl($thisUrl);
  130. $authorize = $turntableData['events']['authorize'];
  131. if ($authorize && $loginUrl) {
  132. $ckLogin = $this->ckLogin();
  133. if($ckLogin==true){
  134. self::ajax_fail_exit(array('url' =>$loginUrl));
  135. }
  136. }
  137. $tmpLotteryData = $objLotteryEventsTypeTurntable ->sweepstakes();
  138. if(!$tmpLotteryData -> isSuccess()){
  139. self::ajax_fail_exit($tmpLotteryData->getData());
  140. }
  141. $lotteryData = $tmpLotteryData -> getData();
  142. $prize_id = $lotteryData['prize_id'];
  143. $thisPrizeData = array();
  144. $thisPrizeData['prize_name'] = $turntableData['prize'][$prize_id]['prize_name'];
  145. $thisPrizeData['id'] = $prize_id;
  146. $thisPrizeData['lottery_data_id'] = $lotteryData['id'];
  147. $thisPrizeData['express'] = $turntableData['prize'][$prize_id]['express'];
  148. $thisPrizeData['img_url'] = $turntableData['prize'][$prize_id]['img_url'];
  149. $thisPrizeData['express'] = $turntableData['prize'][$prize_id]['express'];
  150. $thisPrizeData['type'] = $turntableData['prize'][$prize_id]['type'];
  151. $thisPrizeData['virtual_data'] = isset($lotteryData['virtual_data'])?$lotteryData['virtual_data']:'';
  152. self::ajax_success_exit($thisPrizeData);
  153. }
  154. public function display() {
  155. return $this->render();
  156. }
  157. }