EventsScratch.class.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Dao\LotteryData;
  4. use Cas\Module\Lottery;
  5. use Cas\Module\LotteryEventsLimitations;
  6. use Cas\Module\LotteryEventsTypeScratch;
  7. use KIF\Core\Request;
  8. use KIF\Verify;
  9. use Cas\Dao\UserInfo;
  10. use Cas\Module\Count;
  11. /**
  12. * 刮刮卡
  13. * lihuanchun
  14. */
  15. class EventsScratch extends EventsController {
  16. /**
  17. * 页面:默认刮刮卡首页
  18. */
  19. public function doDefault() {
  20. # 获取活动ID
  21. //$events_id = Request::g('events_id');
  22. $events_id = $this->getEventsCreateTimeToId();
  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. # 获取当前活动数据
  32. $objLotteryEventsTypeScratch = new LotteryEventsTypeScratch($uid, $events_id);
  33. $scratchData = $objLotteryEventsTypeScratch->getEventsData();
  34. # 检查是否移动端
  35. $title = $scratchData['events']['weixinShare']['title'] ? $scratchData['events']['weixinShare']['title'] : $scratchData['events']['events_name'];
  36. $this->checkIsFromMobile($title);
  37. # 获取登录地址
  38. $url = Request::g('url');
  39. $plat_form_id = $this->getPlatFormId();
  40. $objMLottery = new Lottery();
  41. $thisUrl = $objMLottery -> getEventsUrl($scratchData['events']['type'],$scratchData['events']['create_time'],$url);
  42. $loginUrl = $this -> getLoginUrl($thisUrl);
  43. $this->setOutput('loginUrl', $loginUrl);
  44. # 判断是否需要登录
  45. $ckLogin = $this->ckLogin();
  46. $this->setOutput('ckLogin', $ckLogin);
  47. # 检查当前活动是否需要登录
  48. $authorize =$scratchData['events']['authorize'];
  49. if ($authorize && $loginUrl) {
  50. if($ckLogin==true){
  51. self::redirect($loginUrl);
  52. }
  53. }
  54. # 活动状态
  55. $TIME = time();
  56. $eventsStatus = false;
  57. $objMLotteryEventsLimitations = new LotteryEventsLimitations();
  58. if($TIME < $scratchData['events']['begin_time'] ){
  59. $eventsStatus = 'STATUS_NOT_START';
  60. } elseif ($TIME > $scratchData['events']['end_time']){
  61. $eventsStatus = 'STATUS_HAS_END';
  62. } elseif (!$objMLotteryEventsLimitations -> ckEventRestrictions($uid, Request::ip(), $events_id)){
  63. $eventsStatus = 'STATUS_HAS_RESTRTICTIONS';
  64. }
  65. print_r($scratchData);die;
  66. $this->info($scratchData);
  67. # 记录PV UV日志 访问
  68. $objCount = new Count();
  69. $objCount->setPassLog( $events_id,$plat_form_id);
  70. $this->tpl = 'events_scratch';
  71. $this->setOutput('display', $scratchData['events']['list_display']);
  72. $this->setOutput('title', $scratchData['events']['weixinShare']['title'] ? $scratchData['events']['weixinShare']['title'] : $scratchData['events']['events_name']);
  73. $this->setOutput('scratchData', $scratchData);
  74. $this->setOutput('uid', $uid);
  75. $this->setOutput('weixinShare', $scratchData['events']['weixinShare']);
  76. $this->setOutput('eventsStatus', $eventsStatus);
  77. }
  78. /**
  79. * 事件:判断当前用户是否能继续参与
  80. */
  81. public function doCKEventRestrictions(){
  82. $uid = $this->getRunTimeUid();
  83. if (!Verify::unsignedInt($uid)) {
  84. self::ajax_fail_exit('无效uid');
  85. }
  86. $events_id = Request::g('events_id');
  87. if (!Verify::unsignedInt($events_id)) {
  88. self::ajax_fail_exit('无效events_id');
  89. }
  90. $objMLotteryEventsLimitations = new LotteryEventsLimitations();
  91. # 记录用户
  92. $objMLotteryEventsLimitations->setUserEventNum($uid, $events_id); // 记录用户参与UID(天)
  93. $objMLotteryEventsLimitations->setIpEventNum(Request::ip(), $events_id);// 记录用户参与IP(天)
  94. $objMLotteryEventsLimitations->setUserParticipationNum($uid, $events_id); // 记录用户参与次数
  95. $objMLotteryEventsLimitations = new LotteryEventsLimitations();
  96. if(!$objMLotteryEventsLimitations -> ckEventRestrictions($uid, Request::ip(), $events_id)){
  97. self::ajax_fail_exit('达到了上线');
  98. }
  99. self::ajax_success_exit('还可以参与');
  100. }
  101. /**
  102. * 操作:ajax用户领取 礼品
  103. */
  104. public function doUserRestrictions(){
  105. $uid = $this->getRunTimeUid();
  106. if(!$uid){
  107. self::ajax_fail_exit('UID错误');
  108. }
  109. # 获取活动ID
  110. $events_id = Request::g('events_id');
  111. if (!Verify::unsignedInt($events_id)) {
  112. self::ajax_fail_exit('无效id');
  113. }
  114. $lottery_data_id = Request::g('lottery_data_id');
  115. if (!Verify::unsignedInt($events_id)) {
  116. self::ajax_fail_exit('无效lottery_data_id');
  117. }
  118. $objMlottery = new Lottery();
  119. $lotteryData = $objMlottery -> getOneLotteryData($lottery_data_id);
  120. if($lotteryData['uid'] != $uid || $lotteryData['events_id']!=$events_id ){
  121. self::ajax_fail_exit('领取失败');
  122. }
  123. $objLotteryEventsTypeScratch = new LotteryEventsTypeScratch($uid, $events_id);
  124. $objLotteryEventsTypeScratch ->userReceive($lottery_data_id);
  125. # 修改当前获奖记录 标记为 已领取
  126. $info = array(
  127. 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE,
  128. );
  129. $objMlottery->upOneLetteryData($info,array('id' => $lottery_data_id));
  130. self::ajax_success_exit('领取成功') ;
  131. }
  132. /**
  133. * 操作:页面初始化 ajax请求操作
  134. */
  135. public function doScratch() {
  136. # 检查用户UID & 获取用户ID
  137. $events_id = Request::g('events_id');
  138. if (!Verify::unsignedInt($events_id)) {
  139. self::ajax_fail_exit(array(
  140. 'errcode' => 'INVALID_ID',
  141. ));
  142. }
  143. $uid = $this->getRunTimeUid();
  144. # 获取当前活动数据
  145. $objLotteryEventsTypeScratch = new LotteryEventsTypeScratch($uid, $events_id);
  146. $scratchData = $objLotteryEventsTypeScratch->getEventsData();
  147. # 抽奖操作
  148. $winData = array();
  149. $tmpWinData = $objLotteryEventsTypeScratch->userScratch();
  150. if ($tmpWinData->isSuccess()) {
  151. $winData = $tmpWinData->getData();
  152. $lottery_data_id = $winData['id'];
  153. $newWinData = $winData['run_time_data']['prize'][$winData['prize_id']];
  154. $newWinData['lottery_data_id'] = $lottery_data_id;
  155. if(isset($winData['virtual_data']) && !empty($winData['virtual_data'])){
  156. $newWinData['virtual_data'] = $winData['virtual_data'];
  157. }
  158. }
  159. self::ajax_success_exit($newWinData);
  160. }
  161. /**
  162. * 显示
  163. */
  164. public function display() {
  165. return $this->render();
  166. }
  167. }