EventsInvitation.class.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Dao\LotteryData;
  4. use Cas\Dao\LotteryPrize;
  5. use KIF\Core\Request;
  6. use KIF\Verify;
  7. use Cas\Module\LotteryEventsTypeInvitation;
  8. use KIF\Core\Config;
  9. use KIF\String\String;
  10. use KIF\String\Filter;
  11. use Cas\Dao\LotteryEventsForms;
  12. use Cas\Dao\UserInfo;
  13. use Cas\Module\Count;
  14. use Cas\Dao\Platform;
  15. use Cas\Module\Lottery;
  16. /**
  17. *
  18. * 邀请函
  19. */
  20. class EventsInvitation extends EventsController {
  21. public function doDefault() {
  22. //$events_id = Request::g('events_id');
  23. $events_id = $this->getEventsCreateTimeToId();
  24. if (!Verify::unsignedInt($events_id)) {
  25. self::fail_exit('无效id');
  26. }
  27. # 获取用户信息
  28. $objUserData = new UserInfo();
  29. $uid = $this->getRunTimeUid();
  30. $userData = $objUserData -> get($uid);
  31. $this->setOutput('userData', $userData);
  32. # 获取邀请函信息
  33. $objLotteryEventsTypeInvitation = new LotteryEventsTypeInvitation($uid, $events_id);
  34. $info = $objLotteryEventsTypeInvitation->getEventsData();
  35. # 检查是否移动端
  36. $title = $info['weixinShare']['title'] ? $info['weixinShare']['title']: $info['events_name'];
  37. $this->checkIsFromMobile($title);
  38. # 获取登录地址
  39. $url = Request::g('url');
  40. $plat_form_id = $this->getPlatFormId();
  41. $objMLottery = new Lottery();
  42. $thisUrl = $objMLottery -> getEventsUrl($info['type'],$info['create_time'],$url);
  43. $loginUrl = $this -> getLoginUrl($thisUrl);
  44. $this->setOutput('loginUrl', $loginUrl);
  45. # 判断是否需要登录
  46. $ckLogin = $this->ckLogin();
  47. $this->setOutput('ckLogin', $ckLogin);
  48. # 检查当前活动是否需要登录
  49. $authorize = $info['authorize'];
  50. if ($authorize && $loginUrl) {
  51. if($ckLogin==true){
  52. self::redirect($loginUrl);
  53. }
  54. }
  55. # 活动状态
  56. $TIME = time();
  57. $eventsStatus = false;
  58. if($TIME < $info['begin_time'] ){
  59. $eventsStatus = 'STATUS_NOT_START';
  60. } elseif ($TIME > $info['end_time']){
  61. $eventsStatus = 'STATUS_HAS_END';
  62. } elseif ($info['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
  63. //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象列表
  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', $info['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. $info['events_tips'] = str_replace($tmpMatch, $tmp_new_video_html, $info['events_tips']);
  73. }
  74. $this->tpl = 'events_invitation';
  75. $this->setOutput('title', $info['weixinShare']['title'] ? $info['weixinShare']['title'] : $info['events_name']);
  76. $this->setOutput('info', $info);
  77. $this->setOutput('forms', $info['forms']);
  78. $this->setOutput('weixinShare', $info['weixinShare']);
  79. $this->setOutput('eventsStatus', $eventsStatus);
  80. }
  81. public function doSub() {
  82. # 1.必要参数验证
  83. $uid = $this->getRunTimeUid();
  84. if (!Verify::unsignedInt($uid)) {
  85. self::ajax_fail_exit('无效用户id');
  86. }
  87. $events_id = Request::g('events_id');
  88. if (!Verify::unsignedInt($events_id)) {
  89. self::ajax_fail_exit('无效活动id');
  90. }
  91. $objLotteryEventsTypeInvitation = new LotteryEventsTypeInvitation($uid, $events_id);
  92. $eventsData = $objLotteryEventsTypeInvitation->getEventsData();
  93. # 获取登录地址
  94. $plat_form_id = $this->getPlatFormId();
  95. $objPlatForm = new Platform();
  96. $form = $objPlatForm -> get($plat_form_id);
  97. $url = $form['url'];
  98. $objMLottery = new Lottery();
  99. $thisUrl = $objMLottery -> getEventsUrl($eventsData['type'],$eventsData['create_time'],$url);
  100. $loginUrl = $this -> getLoginUrl($thisUrl);
  101. # 判断是否登录
  102. $authorize = $eventsData['authorize'];
  103. if ($authorize && $loginUrl) {
  104. $ckLogin = $this->ckLogin();
  105. if($ckLogin==true){
  106. self::ajax_fail_exit(array('url' =>$loginUrl));
  107. }
  108. }
  109. # 3.活动信息&用户行为验证
  110. $tmpData = $objLotteryEventsTypeInvitation -> submitUser();
  111. if (!$tmpData->isSuccess()) {
  112. self::ajax_fail_exit($tmpData->getData());
  113. }
  114. # 4.用户表单验证
  115. $info = $objLotteryEventsTypeInvitation->getEventsData();
  116. $eventData = $info;
  117. $forms = $info['forms'];
  118. $formData = Filter::arrayfilter($_POST, true);
  119. $objLotteryEventsForms = new LotteryEventsForms();
  120. $tmpVerifyResult = $objLotteryEventsForms->verifyFormData($forms, $formData);
  121. if (!$tmpVerifyResult->isSuccess()) {
  122. self::ajax_fail_exit($tmpVerifyResult->getData());
  123. }
  124. # 5.记录用户提交表单
  125. $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id));
  126. $formId = $objLotteryEventsForms->add($info);
  127. if (!$formId) {
  128. self::ajax_fail_exit('数据库操作失败');
  129. }
  130. # 6.记录用户“我的奖品”
  131. $objDLotteryData = new LotteryData();
  132. $thisTime = time();
  133. $info = array(
  134. 'events_id' => $events_id,
  135. 'prize_id' => 0,
  136. 'uid' => $uid,
  137. 'winners_time' => $thisTime,
  138. 'winning_time' => $thisTime,
  139. 'run_time_data' => array(
  140. 'events' => $eventData,
  141. 'prize' => array(
  142. 0 => array(
  143. 'events_id' => $this->eventsId,
  144. 'prize_name' =>$eventData['events_name'],
  145. 'img_url' => '/public/static/img/qricon.png',
  146. 'type' => LotteryPrize::TYPE_ENTITY,
  147. )
  148. ),
  149. ),
  150. 'virtual_data' => "/?c=EventsInvitation&a=Qrcode&events_id={$events_id}&formsId={$formId}",
  151. );
  152. $objDLotteryData -> add($info);
  153. # 7.记录用户参与行为
  154. $objLotteryEventsTypeInvitation -> setLimitations();
  155. self::ajax_success_exit($formId);
  156. }
  157. public function doQrcode() {
  158. $App_Path = Config::getInstance()->get('App_Path');
  159. include_once $App_Path . DS . 'include/phpqrcode/phpqrcode.php';
  160. $uploadConfig = Config::getInstance()->get('upload');
  161. $IMG_UPLOAD_PATH = $uploadConfig['path'] . DS . 'qrcode';
  162. $IMG_UPLOAD_URL = $uploadConfig['url'] . DS . 'qrcode';
  163. if (!file_exists($IMG_UPLOAD_PATH)) {
  164. if (!mkdir($IMG_UPLOAD_PATH, 0775, true)) {
  165. self::fail_exit('创建二维码失败,原因:图片目录不存在');
  166. }
  167. }
  168. $TIME = time();
  169. $filename = $TIME . 'png';
  170. $uid = $this->getRunTimeUid();
  171. $events_id = Request::g('events_id');
  172. $formsId = Request::g('formsId');
  173. $objLotteryEventsTypeInvitation = new LotteryEventsTypeInvitation($uid, $events_id);
  174. $token = $objLotteryEventsTypeInvitation->getQrcodeUrlToken();
  175. $data = String::jointUrl(Request::schemeDomain(), array(
  176. 'c' => 'QrcodeData',
  177. 'a' => 'Invitation',
  178. 'uid' => $uid,
  179. 'events_id' => $events_id,
  180. 'formsId' => $formsId,
  181. 'token' => $token,
  182. ));
  183. \QRcode::png($data, $IMG_UPLOAD_PATH . DS . $filename, 3, 6);
  184. $imgUrl = $IMG_UPLOAD_URL . DS . $filename;
  185. $info = $objLotteryEventsTypeInvitation->getEventsData();
  186. # 获取登录地址
  187. $plat_form_id = $this->getPlatFormId();
  188. $objPlatForm = new Platform();
  189. $form = $objPlatForm -> get($plat_form_id);
  190. $url = $form['url'];
  191. # 列表页URL
  192. $this->setOutput('listUrl', Request::schemeDomain().'/list/'.$url);
  193. # 我的礼品URL
  194. $this->setOutput('giftsUrl', Request::schemeDomain().'/list/'.$url.'/member/gifts');
  195. $this->tpl = 'save_qrcode';
  196. $this->setOutput('title', '保存二维码');
  197. $this->setOutput('imgUrl', $imgUrl);
  198. $this->setOutput('info', $info);
  199. }
  200. public function display() {
  201. return $this->render();
  202. }
  203. }