EventsTry.class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Dao\LotteryUserExpress;
  4. use KIF\Core\Request;
  5. use KIF\Verify;
  6. use Cas\Module\LotteryEventsTypeTry;
  7. use KIF\String\Filter;
  8. use Cas\Dao\LotteryEventsForms;
  9. use Cas\Dao\UserInfo;
  10. use Cas\Module\Count;
  11. use Cas\Module\Lottery;
  12. use Cas\Dao\LotteryUserFeedback;
  13. use Cas\Module\LotteryLog;
  14. /**
  15. * 试用
  16. */
  17. class EventsTry extends EventsController {
  18. public function doDefault() {
  19. $thisTime = time();
  20. //$events_id = Request::g('events_id');
  21. $events_id = $this->getEventsCreateTimeToId();
  22. if (!Verify::unsignedInt($events_id)) {
  23. self::fail_exit('无效id');
  24. }
  25. # 获取用户信息
  26. $objUserData = new UserInfo();
  27. $uid = $this->getRunTimeUid();
  28. $userData = $objUserData -> get($uid);
  29. $this->setOutput('userData', $userData);
  30. # 获取试用信息
  31. $objLotteryEventsTypeTry = new LotteryEventsTypeTry($uid, $events_id);
  32. $tryInfo = $objLotteryEventsTypeTry->getEventsData();
  33. # 检查是否移动端
  34. $title = $tryInfo['weixinShare']['title'] ? $tryInfo['weixinShare']['title'] : $tryInfo['events_name'];
  35. $this->checkIsFromMobile($title);
  36. # 活动状态
  37. $TIME = time();
  38. $eventsStatus = false;
  39. if($TIME < $tryInfo['begin_time'] ){
  40. $eventsStatus = 'STATUS_NOT_START';
  41. } elseif ($TIME > $tryInfo['end_time']){
  42. $eventsStatus = 'STATUS_HAS_END';
  43. } elseif ($tryInfo['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
  44. //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象列表
  45. }
  46. # 获取用户最新收货地址
  47. $objDLotteryUserExpress = new LotteryUserExpress();
  48. $userExpress = $objDLotteryUserExpress -> getUserExpress($uid);
  49. $this->info($tryInfo);
  50. # 记录PV UV日志 访问
  51. $objCount = new Count();
  52. $objCount->setPassLog( $events_id,$plat_form_id);
  53. # 视频播放
  54. preg_match_all('/<embed\s{1}src=\"([^\"]+)\"[^>]+>/i', $tryInfo['events_tips'], $matches);
  55. if ($matches) foreach ($matches[0] as $key => $tmpMatch) {
  56. $tmp_new_video_html = '<iframe class="video_iframe" height=498 width=510 src="'.$matches[1][$key].'" frameborder=0 allowfullscreen></iframe>';
  57. $tryInfo['events_tips'] = str_replace($tmpMatch, $tmp_new_video_html, $tryInfo['events_tips']);
  58. }
  59. $this->tpl = 'events_try';
  60. $this->setOutput('display', $tryInfo['list_display']);
  61. $this->setOutput('userExpress', $userExpress);
  62. $this->setOutput('title', $tryInfo['weixinShare']['title'] ? $tryInfo['weixinShare']['title'] : $tryInfo['events_name']);
  63. $this->setOutput('tryInfo', $tryInfo);
  64. $this->setOutput('forms', $tryInfo['forms']);
  65. $this->setOutput('eventsStatus', $eventsStatus);
  66. $this->setOutput('weixinShare', $tryInfo['weixinShare']);
  67. }
  68. public function doApply() {
  69. # 1.必要参数验证
  70. $uid = $this->getRunTimeUid();
  71. if (!Verify::unsignedInt($uid)) {
  72. self::ajax_fail_exit('无效用户id');
  73. }
  74. $events_id = Request::g('events_id');
  75. if (!Verify::unsignedInt($events_id)) {
  76. self::ajax_fail_exit('无效试用id');
  77. }
  78. $objLotteryEventsTypeTry = new LotteryEventsTypeTry($uid, $events_id);
  79. # 2.活动信息&用户行为验证
  80. $tmpData = $objLotteryEventsTypeTry -> userTry() ;
  81. if(!$tmpData->isSuccess()){
  82. self::ajax_fail_exit($tmpData->getData());
  83. }
  84. # 3.用户表单验证
  85. $tryInfo = $objLotteryEventsTypeTry->getEventsData();
  86. $forms = $tryInfo['forms'];
  87. $formData = Filter::arrayfilter($_POST, true);
  88. $objLotteryEventsForms = new LotteryEventsForms();
  89. $tmpVerifyResult = $objLotteryEventsForms->verifyFormData($forms, $formData);
  90. if (!$tmpVerifyResult->isSuccess()) {
  91. self::ajax_fail_exit($tmpVerifyResult->getData());
  92. }
  93. # 4.保存表单内容
  94. $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id));
  95. if (!$objLotteryEventsForms->add($info)) {
  96. self::ajax_fail_exit('数据库操作失败');
  97. }
  98. # 5.增加行为记录
  99. $objLotteryEventsTypeTry->setLimitations();
  100. self::ajax_success_exit();
  101. }
  102. public function display() {
  103. return $this->render();
  104. }
  105. }