EventsTry.class.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. /**
  14. * 试用
  15. */
  16. class EventsTry extends EventsController {
  17. public function doDefault() {
  18. $thisTime = time();
  19. //$events_id = Request::g('events_id');
  20. $events_id = $this->getEventsCreateTimeToId();
  21. if (!Verify::unsignedInt($events_id)) {
  22. self::fail_exit('无效id');
  23. }
  24. # 获取用户信息
  25. $objUserData = new UserInfo();
  26. $uid = $this->getRunTimeUid();
  27. $userData = $objUserData -> get($uid);
  28. $this->setOutput('userData', $userData);
  29. # 获取试用信息
  30. $objLotteryEventsTypeTry = new LotteryEventsTypeTry($uid, $events_id);
  31. $tryInfo = $objLotteryEventsTypeTry->getEventsData();
  32. # 检查是否移动端
  33. $title = $tryInfo['weixinShare']['title'] ? $tryInfo['weixinShare']['title'] : $tryInfo['events_name'];
  34. $this->checkIsFromMobile($title);
  35. # 获取登录地址
  36. $url = Request::g('url');
  37. $plat_form_id = $this->getPlatFormId();
  38. $objMLottery = new Lottery();
  39. $thisUrl = $objMLottery -> getEventsUrl($tryInfo['type'],$tryInfo['create_time'],$url);
  40. $loginUrl = $this -> getLoginUrl($thisUrl);
  41. $this->setOutput('loginUrl', $loginUrl);
  42. # 判断是否需要登录
  43. $ckLogin = $this->ckLogin();
  44. $this->setOutput('ckLogin', $ckLogin);
  45. # 活动状态
  46. $TIME = time();
  47. $eventsStatus = false;
  48. if($TIME < $tryInfo['begin_time'] ){
  49. $eventsStatus = 'STATUS_NOT_START';
  50. } elseif ($TIME > $tryInfo['end_time']){
  51. $eventsStatus = 'STATUS_HAS_END';
  52. } elseif ($tryInfo['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
  53. //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象列表
  54. }
  55. # 获取用户最新收货地址
  56. $objDLotteryUserExpress = new LotteryUserExpress();
  57. $userExpress = $objDLotteryUserExpress -> getUserExpress($uid);
  58. # 检查当前活动是否需要登录
  59. $authorize =$tryInfo['authorize'];
  60. if ($authorize) {
  61. if($ckLogin==true){
  62. self::redirect($loginUrl);
  63. }
  64. }
  65. # 记录PV UV日志 访问
  66. $objCount = new Count();
  67. $objCount->setPassLog( $events_id,$plat_form_id);
  68. # 视频播放
  69. preg_match_all('/<embed\s{1}src=\"([^\"]+)\"[^>]+>/i', $tryInfo['events_tips'], $matches);
  70. if ($matches) foreach ($matches[0] as $key => $tmpMatch) {
  71. $tmp_new_video_html = '<iframe class="video_iframe" height=498 width=510 src="'.$matches[1][$key].'" frameborder=0 allowfullscreen></iframe>';
  72. $tryInfo['events_tips'] = str_replace($tmpMatch, $tmp_new_video_html, $tryInfo['events_tips']);
  73. }
  74. $this->tpl = 'events_try';
  75. $this->setOutput('display', $tryInfo['list_display']);
  76. $this->setOutput('userExpress', $userExpress);
  77. $this->setOutput('title', $tryInfo['weixinShare']['title'] ? $tryInfo['weixinShare']['title'] : $tryInfo['events_name']);
  78. $this->setOutput('tryInfo', $tryInfo);
  79. $this->setOutput('forms', $tryInfo['forms']);
  80. $this->setOutput('eventsStatus', $eventsStatus);
  81. $this->setOutput('weixinShare', $tryInfo['weixinShare']);
  82. }
  83. public function doApply() {
  84. # 1.必要参数验证
  85. $uid = $this->getRunTimeUid();
  86. if (!Verify::unsignedInt($uid)) {
  87. self::ajax_fail_exit('无效用户id');
  88. }
  89. $events_id = Request::g('events_id');
  90. if (!Verify::unsignedInt($events_id)) {
  91. self::ajax_fail_exit('无效试用id');
  92. }
  93. $objLotteryEventsTypeTry = new LotteryEventsTypeTry($uid, $events_id);
  94. # 2.活动信息&用户行为验证
  95. $tmpData = $objLotteryEventsTypeTry -> userTry() ;
  96. if(!$tmpData->isSuccess()){
  97. print_r($tmpData);die;
  98. self::ajax_fail_exit($tmpData->getData());
  99. }
  100. # 3.用户表单验证
  101. $tryInfo = $objLotteryEventsTypeTry->getEventsData();
  102. $forms = $tryInfo['forms'];
  103. $formData = Filter::arrayfilter($_POST, true);
  104. $objLotteryEventsForms = new LotteryEventsForms();
  105. $tmpVerifyResult = $objLotteryEventsForms->verifyFormData($forms, $formData);
  106. if (!$tmpVerifyResult->isSuccess()) {
  107. self::ajax_fail_exit($tmpVerifyResult->getData());
  108. }
  109. # 4.保存表单内容
  110. $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id));
  111. if (!$objLotteryEventsForms->add($info)) {
  112. self::ajax_fail_exit('数据库操作失败');
  113. }
  114. # 5.增加行为记录
  115. $objLotteryEventsTypeTry->setLimitations();
  116. self::ajax_success_exit();
  117. }
  118. public function doFeedBack() {
  119. # 1.必要参数验证
  120. $uid = $this->getRunTimeUid();
  121. if (!Verify::unsignedInt($uid)) {
  122. self::ajax_fail_exit('无效用户id');
  123. }
  124. $events_id = Request::g('events_id');
  125. if (!Verify::unsignedInt($events_id)) {
  126. self::ajax_fail_exit('无效id');
  127. }
  128. $objMLottery = new Lottery();
  129. $eventData = $objMLottery->getOneLotteryEvents ( $events_id );
  130. if (!$eventData) {
  131. self::ajax_fail_exit('无效id');
  132. }
  133. $type = $eventData['type'];
  134. if (!in_array($type, array(4,6))) {
  135. self::ajax_fail_exit('无效类型');
  136. }
  137. # 以下为数据验证
  138. if ($type == 4) {
  139. # 验证是否有试用权限
  140. $objLotteryEventsTypeTry = new LotteryEventsTypeTry($uid, $events_id);
  141. $tmpData = $objLotteryEventsTypeTry -> userTry() ;
  142. if($tmpData->isSuccess()){
  143. self::ajax_fail_exit('没有申请');
  144. }
  145. }
  146. if ($type == 6) {
  147. # 验证是否有邀请函
  148. }
  149. $objLotteryUserFeedback = new LotteryUserFeedback();
  150. $data = array();
  151. $data['uid'] = $uid;
  152. $data['events_id'] = $events_id;
  153. $data['status'] = 1;
  154. $ids = $objLotteryUserFeedback->findIdsBy ( $data, 1, $order = ' id desc');
  155. $info = $objLotteryUserFeedback->gets ( $ids );
  156. $data['content'] = Request::g('content');
  157. $data['pic'] = Request::g('pic');
  158. if ($info) {
  159. $info = array_pop($info);
  160. $tmpResult = $objLotteryUserFeedback->modify($data, array (
  161. 'id' => $info['id']
  162. ));
  163. } else {
  164. $tmpResult = $objLotteryUserFeedback->add($data);
  165. }
  166. if (!$tmpResult) {
  167. self::ajax_fail_exit('错误的反馈信息');
  168. }
  169. self::ajax_success_exit();
  170. }
  171. public function display() {
  172. return $this->render();
  173. }
  174. }