EventsCutScreen.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Dao\LotteryEvents;
  4. use KIF\Core\Request;
  5. use KIF\Verify;
  6. use Cas\Module\LotteryLog;
  7. use Cas\Dao\UserInfo;
  8. use Cas\Module\Count;
  9. use Cas\Module\Lottery;
  10. use Cas\Dao\LotteryEventsForms;
  11. use KIF\String\Filter;
  12. /**
  13. * "切屏专题" 活动
  14. */
  15. class EventsCutScreen extends EventsController {
  16. public function doDefault() {
  17. $thisTime = time();
  18. //$events_id = Request::g('events_id');
  19. $events_id = $this->getEventsCreateTimeToId();
  20. if (!Verify::unsignedInt($events_id)) {
  21. self::fail_exit('无效id');
  22. }
  23. # 获取"切屏专题"信息
  24. $objDLotteryEvents = new LotteryEvents();
  25. $cutScreenInfo = $objDLotteryEvents -> get($events_id);
  26. # 检查是否移动端
  27. $title = $cutScreenInfo['weixinShare']['title'] ? $cutScreenInfo['weixinShare']['title']: $cutScreenInfo['events_name'];
  28. $this->checkIsFromMobile($title);
  29. # 获取登录地址
  30. $url = Request::g('url');
  31. $plat_form_id = $this->getPlatFormId();
  32. $objMLottery = new Lottery();
  33. $thisUrl = $objMLottery -> getEventsUrl($cutScreenInfo['type'],$cutScreenInfo['create_time'],$url);
  34. $loginUrl = $this -> getLoginUrl($thisUrl);
  35. $this->setOutput('loginUrl', $loginUrl);
  36. # 判断是否需要登录
  37. $ckLogin = $this->ckLogin();
  38. $this->setOutput('ckLogin', $ckLogin);
  39. # 获取用户信息
  40. $objUserData = new UserInfo();
  41. $uid = $this->getRunTimeUid();
  42. $userData = $objUserData -> get($uid);
  43. $this->setOutput('userData', $userData);
  44. # 检查当前活动是否需要登录
  45. $authorize = $cutScreenInfo['authorize'];
  46. if ($authorize && $loginUrl) {
  47. if($ckLogin==true){
  48. self::redirect($loginUrl);
  49. }
  50. }
  51. $objMLotteryLog = new LotteryLog($uid,$events_id);
  52. $other = array(
  53. '访问页面:' => '成功'
  54. );
  55. $objMLotteryLog ->addUserParticipateLog($other);
  56. $this->tpl = 'events_cutscreen';
  57. $this->setOutput('title', $cutScreenInfo['weixinShare']['title'] ? $cutScreenInfo['weixinShare']['title']: $cutScreenInfo['events_name']);
  58. $this->setOutput('cutScreenInfo', $cutScreenInfo);
  59. $pageData = $cutScreenInfo['pageData'];
  60. $waitLoadingImgs = array();
  61. # 构造下页面图片的位置
  62. foreach ($pageData as $tmpkey => $tmpData) {
  63. if ($tmpData['input_page']) {
  64. continue;
  65. }
  66. foreach ($tmpData['layers'] as $key => $tmpLayer) {
  67. $new_layer = $pageData[$tmpkey]['layers'][$key];
  68. if ($new_layer['url']) {
  69. $new_layer['width'] = $tmpLayer['width'] / 2;
  70. $new_layer['height'] = $tmpLayer['height'] / 2;
  71. $waitLoadingImgs[] = $new_layer['url'];
  72. }
  73. if ($new_layer['video_url']) {
  74. $new_layer['width'] = $new_layer['video_width'] = $tmpLayer['video_width'];
  75. $new_layer['height'] = $new_layer['video_height'] = $tmpLayer['video_height'];
  76. }
  77. $style = '';
  78. switch ($tmpLayer['position']) {
  79. case 'center':
  80. $margin_left = $new_layer['width'] / 2;
  81. $margin_top = $new_layer['height'] / 2;
  82. $style = "left:50%;top:50%;margin-left:-{$margin_left}px;margin-top:-{$margin_top}px;";
  83. break;
  84. case 'up';
  85. $margin_left = $new_layer['width'] / 2;
  86. $style = "left:50%;top:0%;margin-left:-{$margin_left}px;";
  87. break;
  88. case 'down':
  89. $margin_left = $new_layer['width'] / 2;
  90. $style = "left:50%;bottom:6%;margin-left:-{$margin_left}px;";
  91. break;
  92. case 'leftup':
  93. $style = "left:0%;top:0%;";
  94. break;
  95. case 'leftdown':
  96. $style = "left:0%;bottom:0%;";
  97. break;
  98. case 'rightup':
  99. $style = "right:0%;top:0%;";
  100. break;
  101. case 'rightdown':
  102. $style = "right:0%;bottom:0%;";
  103. break;
  104. }
  105. $new_layer['style'] = $style;
  106. $pageData[$tmpkey]['layers'][$key] = $new_layer;
  107. }
  108. if ($tmpData['bgimage_url']) {
  109. $waitLoadingImgs[] = $tmpData['bgimage_url'];
  110. }
  111. }
  112. # 记录PV UV日志 访问
  113. $objCount = new Count();
  114. $objCount->setPassLog( $events_id,$plat_form_id);
  115. $this->setOutput('weixinShare', $cutScreenInfo['weixinShare']);
  116. $this->setOutput('pageData', $pageData);
  117. $this->setOutput('waitLoadingImgs', json_encode($waitLoadingImgs));
  118. $this->setOutput('forms', $cutScreenInfo['forms']);
  119. }
  120. /**
  121. * 表单提交
  122. */
  123. public function doSubmitForm() {
  124. $events_id = Request::g('events_id');
  125. if (!Verify::unsignedInt($events_id)) {
  126. self::ajax_fail_exit('无效id');
  127. }
  128. $uid = $this->getRunTimeUid();
  129. $objDLotteryEvents = new LotteryEvents();
  130. $cutScreenInfo = $objDLotteryEvents -> get($events_id);
  131. $forms = $cutScreenInfo['forms'];
  132. $formData = Filter::arrayfilter($_POST, true);
  133. $objLotteryEventsForms = new LotteryEventsForms();
  134. $tmpVerifyResult = $objLotteryEventsForms->verifyFormData($forms, $formData);
  135. if (!$tmpVerifyResult->isSuccess()) {
  136. self::ajax_fail_exit($tmpVerifyResult->getData());
  137. }
  138. $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id));
  139. if (!$objLotteryEventsForms->add($info)) {
  140. self::ajax_fail_exit('数据库操作失败');
  141. }
  142. self::ajax_success_exit();
  143. }
  144. /**
  145. *
  146. */
  147. public function display() {
  148. return $this->render();
  149. }
  150. }