EventsLetters.class.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Module\LotteryEventsLimitations;
  4. use Cas\Module\LotteryEventsTypeLetters;
  5. use Cas\Dao\LotteryEvents;
  6. use KIF\Dao\SqlHelper;
  7. use Cas\Module\Lottery;
  8. use Cas\Dao\LotteryUserExpress;
  9. use KIF\Core\Request;
  10. use KIF\Verify;
  11. use Cas\Dao\UserInfo;
  12. use Cas\Module\Count;
  13. use Cas\Dao\Platform;
  14. /**
  15. * 收集字母
  16. * lihuanchun
  17. */
  18. class EventsLetters extends EventsController {
  19. /**
  20. * 页面:默认页面
  21. */
  22. public function doDefault() {
  23. //$events_id = Request::g('events_id');
  24. $events_id = $this->getEventsCreateTimeToId();
  25. if (!Verify::unsignedInt($events_id)) {
  26. self::fail_exit('无效id');
  27. }
  28. # 获取用户信息
  29. $objUserData = new UserInfo();
  30. $uid = $this->getRunTimeUid();
  31. $userData = $objUserData -> get($uid);
  32. $this->setOutput('userData', $userData);
  33. # 获取当前活动的信息 & 字母 & 奖项
  34. $objMLotteryEventsTypeLetters = new LotteryEventsTypeLetters($uid,$events_id);
  35. $lettersData = $objMLotteryEventsTypeLetters -> getEventsData();
  36. # 获取登录地址
  37. $url = Request::g('url');
  38. $plat_form_id = $this->getPlatFormId();
  39. $objMLottery = new Lottery();
  40. $thisUrl = $objMLottery -> getEventsUrl($lettersData['type'],$lettersData['create_time'],$url);
  41. $loginUrl = $this -> getLoginUrl($thisUrl);
  42. $this->setOutput('loginUrl', $loginUrl);
  43. # 判断是否需要登录
  44. $ckLogin = $this->ckLogin();
  45. $this->setOutput('ckLogin', $ckLogin);
  46. # 获取用户当前收集的字母列表
  47. $userLettersData = $objMLotteryEventsTypeLetters -> getUserLetters();
  48. foreach($lettersData['letters'] as $key => $data ){
  49. if(isset($userLettersData['ABC_data'][$key])){
  50. $lettersData['letters'][$key]['thisUser'] = true;
  51. }
  52. }
  53. # 检查当前活动是否需要登录
  54. $authorize = $lettersData['events']['authorize'];
  55. if ($authorize && $loginUrl) {
  56. if($ckLogin==true){
  57. self::redirect($loginUrl);
  58. }
  59. }
  60. $objMLotteryEventsLimitations = new LotteryEventsLimitations();
  61. # 活动状态
  62. $TIME = time();
  63. $eventsStatus = false;
  64. if($TIME < $lettersData['events']['begin_time'] ){
  65. $eventsStatus = 'STATUS_NOT_START';
  66. } elseif ($TIME > $lettersData['events']['end_time']){
  67. $eventsStatus = 'STATUS_HAS_END';
  68. } elseif ($lettersData['events']['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
  69. //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象列表
  70. }elseif (!$objMLotteryEventsLimitations->ckEventRestrictions($uid,Request::ip(), $events_id)) {
  71. $eventsStatus = 'STATUS_HAS_RESTRTICTIONS';
  72. }elseif (count($userLettersData['ABC_data'])==count($lettersData['letters'])) {
  73. $eventsStatus = 'STATUS_HAS_COMPLETE';
  74. }
  75. # 获取其他开始的活动
  76. $objDLottery = new Lottery();
  77. $condition = array(
  78. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW,
  79. 'id' => SqlHelper::addCompareOperator('!=', $events_id),
  80. 'begin_time' => SqlHelper::addCompareOperator('<', $TIME),
  81. 'end_time' => SqlHelper::addCompareOperator('>', $TIME)
  82. );
  83. $otherEventsData = $objDLottery -> getLotteryEventsList($condition, 3, 'id desc');
  84. # 获取用户最新收货地址
  85. $objDLotteryUserExpress = new LotteryUserExpress();
  86. $userExpress = $objDLotteryUserExpress -> getUserExpress($uid);
  87. # 页面ABC Json 增加出现位置
  88. $i = 1;
  89. foreach ($lettersData['letters'] as $key =>$data){
  90. $data['occurrence'] = $i;
  91. $lettersData['letters'][$key] = $data;
  92. $i++;
  93. }
  94. $ABCJsonData = json_encode($lettersData['letters']);
  95. # 记录PV UV日志 访问
  96. $objCount = new Count();
  97. $objCount->setPassLog( $events_id,$plat_form_id);
  98. # 页面数据
  99. $this->tpl = 'events_letters';
  100. $this->setOutput('display', $lettersData['events']['list_display']);
  101. $this->setOutput('title', $lettersData['events']['weixinShare']['title'] ? $lettersData['events']['weixinShare']['title'] : $lettersData['events']['events_name']);
  102. $this->setOutput('ABCJsonData', $ABCJsonData);
  103. $this->setOutput('eventsStatus', $eventsStatus);
  104. $this->setOutput('lettersData', $lettersData);
  105. $this->setOutput('userLettersData', $userLettersData);
  106. $this->setOutput('otherEventsData', $otherEventsData);
  107. $this->setOutput('userExpress', $userExpress);
  108. $this->setOutput('weixinShare', $lettersData['events']['weixinShare']);
  109. }
  110. /**
  111. * 事件:ajax 收集动作
  112. */
  113. public function doSweepstakes() {
  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. # 获取数据
  121. $objLotteryEventsTypeLetters = new LotteryEventsTypeLetters($uid,$events_id);
  122. $lettersData = $objLotteryEventsTypeLetters -> getEventsData();
  123. # 检查当前活动是否需要登录 & 获取登录地址
  124. $plat_form_id = $this->getPlatFormId();
  125. $objPlatForm = new Platform();
  126. $form = $objPlatForm -> get($plat_form_id);
  127. //$thisUrl = Request::schemeDomain().'/EventsLetters/T'.$plat_form_id.'/E'.$events_id;
  128. $thisUrl = Request::schemeDomain().'/'.$form['url'].'/EventsLetters/'.$lettersData['events']['create_time'];
  129. $loginUrl = $this -> getLoginUrl($thisUrl);
  130. $authorize = $lettersData['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. # 前端渲染的字母
  138. $user_letters = array();
  139. $userLettersData = $objLotteryEventsTypeLetters -> getUserLetters();
  140. if($userLettersData){
  141. $user_letters = $userLettersData['ABC_data'];
  142. }
  143. # 开始抽字母 & 奖项
  144. $tmpLotteryData = $objLotteryEventsTypeLetters ->sweepstakes();
  145. if(!$tmpLotteryData -> isSuccess()){
  146. # 失败:返回页面所需要的成功数据
  147. $data = $tmpLotteryData->getData();
  148. if(is_array($data)){
  149. $data['user_letters'] = $user_letters;
  150. }
  151. self::ajax_fail_exit($data);
  152. }
  153. # 成功:返回页面所需要的成功数据
  154. $data = $tmpLotteryData->getData();
  155. if(isset($data['lotteryData'])){
  156. $prize_id = $data['lotteryData']['prize_id'];
  157. $thisPrizeData = array();
  158. $thisPrizeData['prize_name'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['prize_name'];
  159. $thisPrizeData['id'] = $prize_id;
  160. $thisPrizeData['lottery_data_id'] = $data['lotteryData']['id'];
  161. $thisPrizeData['express'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['express'];
  162. $thisPrizeData['img_url'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['img_url'];
  163. $thisPrizeData['express'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['express'];
  164. $thisPrizeData['type'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['type'];
  165. $thisPrizeData['virtual_data'] = isset($data['lotteryData']['virtual_data'])?$data['lotteryData']['virtual_data']:'';
  166. $data['lotteryData'] = $thisPrizeData;
  167. }
  168. $user_letters[$data['lottery_id']] = $data['lottery_id'];
  169. $data['user_letters'] = $user_letters;
  170. self::ajax_success_exit($data);
  171. }
  172. public function display() {
  173. return $this->render();
  174. }
  175. }