EventsCode.class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Module\LotteryEventsTypeCode;
  4. use KIF\Core\Request;
  5. use KIF\Verify;
  6. use KIF\String\Filter;
  7. use Cas\Dao\LotteryEventsForms;
  8. use Cas\Dao\UserInfo;
  9. use Cas\Module\Count;
  10. use Cas\Dao\Platform;
  11. use Cas\Module\Lottery;
  12. /**
  13. * 领取 “码”
  14. */
  15. class EventsCode extends EventsController {
  16. public function doDefault() {
  17. //$events_id = Request::g('events_id');
  18. $events_id = $this->getEventsCreateTimeToId();
  19. if (!Verify::unsignedInt($events_id)) {
  20. self::fail_exit('无效id');
  21. }
  22. # 获取用户信息
  23. $objUserData = new UserInfo();
  24. $uid = $this->getRunTimeUid();
  25. $userData = $objUserData -> get($uid);
  26. $this->setOutput('userData', $userData);
  27. # 获取试用信息
  28. $objLotteryEventsTypeCode = new LotteryEventsTypeCode($uid, $events_id);
  29. $codeInfo = $objLotteryEventsTypeCode->getEventsData();
  30. # 检查是否移动端
  31. $title = $codeInfo['weixinShare']['title'] ? $codeInfo['weixinShare']['title']: $codeInfo['events_name'];
  32. $this->checkIsFromMobile($title);
  33. # 获取登录地址
  34. $url = Request::g('url');
  35. $plat_form_id = $this->getPlatFormId();
  36. $objMLottery = new Lottery();
  37. $thisUrl = $objMLottery -> getEventsUrl($codeInfo['type'],$codeInfo['create_time'],$url);
  38. $loginUrl = $this -> getLoginUrl($thisUrl);
  39. $this->setOutput('loginUrl', $loginUrl);
  40. # 判断是否需要登录
  41. $ckLogin = $this->ckLogin();
  42. $this->setOutput('ckLogin', $ckLogin);
  43. # 检查当前活动是否需要登录
  44. $authorize = $codeInfo['authorize'];
  45. if ($authorize && $loginUrl) {
  46. if($ckLogin==true){
  47. self::redirect($loginUrl);
  48. }
  49. }
  50. # 活动状态
  51. $TIME = time();
  52. $eventsStatus = false;
  53. if($TIME < $codeInfo['begin_time'] ){
  54. $eventsStatus = 'STATUS_NOT_START';
  55. } elseif ($TIME > $codeInfo['end_time']){
  56. $eventsStatus = 'STATUS_HAS_END';
  57. } elseif ($codeInfo['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
  58. //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象
  59. }
  60. $this->info($codeInfo);
  61. # 记录PV UV日志 访问
  62. $objCount = new Count();
  63. $objCount->setPassLog( $events_id,$plat_form_id);
  64. $this->tpl = 'events_code';
  65. $this->setOutput('display', $codeInfo['list_display']);
  66. $this->setOutput('title', $title);
  67. $this->setOutput('codeInfo', $codeInfo);
  68. $this->setOutput('forms', $codeInfo['forms']);
  69. $this->setOutput('eventsStatus', $eventsStatus);
  70. $this->setOutput('weixinShare', $codeInfo['weixinShare']);
  71. }
  72. /**
  73. * 领取优惠
  74. */
  75. public function doApply() {
  76. # 1.必要参数验证
  77. $uid = $this->getRunTimeUid();
  78. if (!Verify::unsignedInt($uid)) {
  79. self::ajax_fail_exit('无效用户id');
  80. }
  81. $events_id = Request::g('events_id');
  82. if (!Verify::unsignedInt($events_id)) {
  83. self::ajax_fail_exit('无效活动id');
  84. }
  85. $objLotteryEventsTypeCode = new LotteryEventsTypeCode($uid, $events_id);
  86. $codeData = $objLotteryEventsTypeCode->getEventsData();
  87. # 检查当前活动是否需要登录 & 获取登录地址
  88. $plat_form_id = $this->getPlatFormId();
  89. $objPlatForm = new Platform();
  90. $form = $objPlatForm -> get($plat_form_id);
  91. $url = $form['url'];
  92. $objMLottery = new Lottery();
  93. $thisUrl = $objMLottery -> getEventsUrl($codeData['type'],$codeData['create_time'],$url);
  94. $loginUrl = $this -> getLoginUrl($thisUrl);
  95. $authorize = $codeData['authorize'];
  96. if ($authorize && $loginUrl) {
  97. $ckLogin = $this->ckLogin();
  98. if($ckLogin==true){
  99. self::ajax_fail_exit(array('url' =>$loginUrl));
  100. }
  101. }
  102. # 3.验证活动&用户行为
  103. $tmpData = $objLotteryEventsTypeCode ->ckUserEventsCode();
  104. if(!$tmpData->isSuccess()){
  105. self::ajax_fail_exit($tmpData->getData());
  106. }
  107. # 4.验证表单
  108. $forms = $codeData['forms'];
  109. $formData = Filter::arrayfilter($_POST, true);
  110. $objLotteryEventsForms = new LotteryEventsForms();
  111. $tmpVerifyResult = $objLotteryEventsForms->verifyFormData($forms, $formData);
  112. if (!$tmpVerifyResult->isSuccess()) {
  113. self::ajax_fail_exit($tmpVerifyResult->getData());
  114. }
  115. # 5.发“码”
  116. $userMsg = $formData;
  117. $tmpResult = $objLotteryEventsTypeCode->userCode($userMsg);
  118. if (!$tmpResult->isSuccess()) {
  119. self::ajax_fail_exit($tmpResult->getData());
  120. }
  121. # 6.保存表单
  122. $returnData = $tmpResult->getData();
  123. $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id,'code_data'=>$returnData['codeData']));
  124. if (!$objLotteryEventsForms->add($info)) {
  125. self::ajax_fail_exit('数据库操作失败');
  126. }
  127. # 7.增加行为记录
  128. $objLotteryEventsTypeCode->setLimitations($returnData['codeData']['data']);
  129. self::ajax_success_exit($tmpResult->getData());
  130. }
  131. public function display() {
  132. return $this->render();
  133. }
  134. }