EventsInvitation.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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('display', $info['list_display']);
  76. $this->setOutput('title', $info['weixinShare']['title'] ? $info['weixinShare']['title'] : $info['events_name']);
  77. $this->setOutput('info', $info);
  78. $this->setOutput('forms', $info['forms']);
  79. $this->setOutput('weixinShare', $info['weixinShare']);
  80. $this->setOutput('eventsStatus', $eventsStatus);
  81. }
  82. public function doSub() {
  83. # 1.必要参数验证
  84. $uid = $this->getRunTimeUid();
  85. if (!Verify::unsignedInt($uid)) {
  86. self::ajax_fail_exit('无效用户id');
  87. }
  88. $events_id = Request::g('events_id');
  89. if (!Verify::unsignedInt($events_id)) {
  90. self::ajax_fail_exit('无效活动id');
  91. }
  92. $objLotteryEventsTypeInvitation = new LotteryEventsTypeInvitation($uid, $events_id);
  93. $eventsData = $objLotteryEventsTypeInvitation->getEventsData();
  94. # 获取登录地址
  95. $plat_form_id = $this->getPlatFormId();
  96. $objPlatForm = new Platform();
  97. $form = $objPlatForm -> get($plat_form_id);
  98. $url = $form['url'];
  99. $objMLottery = new Lottery();
  100. $thisUrl = $objMLottery -> getEventsUrl($eventsData['type'],$eventsData['create_time'],$url);
  101. $loginUrl = $this -> getLoginUrl($thisUrl);
  102. # 判断是否登录
  103. $authorize = $eventsData['authorize'];
  104. if ($authorize && $loginUrl) {
  105. $ckLogin = $this->ckLogin();
  106. if($ckLogin==true){
  107. self::ajax_fail_exit(array('url' =>$loginUrl));
  108. }
  109. }
  110. # 3.活动信息&用户行为验证
  111. $tmpData = $objLotteryEventsTypeInvitation -> submitUser();
  112. if (!$tmpData->isSuccess()) {
  113. self::ajax_fail_exit($tmpData->getData());
  114. }
  115. # 4.用户表单验证
  116. $info = $objLotteryEventsTypeInvitation->getEventsData();
  117. $eventData = $info;
  118. $forms = $info['forms'];
  119. $formData = Filter::arrayfilter($_POST, true);
  120. $objLotteryEventsForms = new LotteryEventsForms();
  121. $tmpVerifyResult = $objLotteryEventsForms->verifyFormData($forms, $formData);
  122. if (!$tmpVerifyResult->isSuccess()) {
  123. self::ajax_fail_exit($tmpVerifyResult->getData());
  124. }
  125. # 5.记录用户提交表单
  126. $info = array_merge($formData, array('uid' => $uid, 'events_id' => $events_id));
  127. $formId = $objLotteryEventsForms->add($info);
  128. if (!$formId) {
  129. self::ajax_fail_exit('数据库操作失败');
  130. }
  131. # 6.记录用户“我的奖品”
  132. $objDLotteryData = new LotteryData();
  133. $thisTime = time();
  134. $info = array(
  135. 'events_id' => $events_id,
  136. 'prize_id' => 0,
  137. 'uid' => $uid,
  138. 'winners_time' => $thisTime,
  139. 'winning_time' => $thisTime,
  140. 'run_time_data' => array(
  141. 'events' => $eventData,
  142. 'prize' => array(
  143. 0 => array(
  144. 'events_id' => $this->eventsId,
  145. 'prize_name' =>$eventData['events_name'],
  146. 'img_url' => '/public/static/img/qricon.png',
  147. 'type' => LotteryPrize::TYPE_ENTITY,
  148. )
  149. ),
  150. ),
  151. 'virtual_data' => "/?c=EventsInvitation&a=Qrcode&events_id={$events_id}&formsId={$formId}",
  152. );
  153. $objDLotteryData -> add($info);
  154. # 7.记录用户参与行为
  155. $objLotteryEventsTypeInvitation -> setLimitations();
  156. self::ajax_success_exit($formId);
  157. }
  158. public function doQrcode() {
  159. $App_Path = Config::getInstance()->get('App_Path');
  160. include_once $App_Path . DS . 'include/phpqrcode/phpqrcode.php';
  161. $uploadConfig = Config::getInstance()->get('upload');
  162. $IMG_UPLOAD_PATH = $uploadConfig['path'] . DS . 'qrcode';
  163. $IMG_UPLOAD_URL = $uploadConfig['url'] . DS . 'qrcode';
  164. if (!file_exists($IMG_UPLOAD_PATH)) {
  165. if (!mkdir($IMG_UPLOAD_PATH, 0775, true)) {
  166. self::fail_exit('创建二维码失败,原因:图片目录不存在');
  167. }
  168. }
  169. $TIME = time();
  170. $filename = $TIME . 'png';
  171. $uid = $this->getRunTimeUid();
  172. $events_id = Request::g('events_id');
  173. $formsId = Request::g('formsId');
  174. $objLotteryEventsTypeInvitation = new LotteryEventsTypeInvitation($uid, $events_id);
  175. $token = $objLotteryEventsTypeInvitation->getQrcodeUrlToken();
  176. $data = String::jointUrl(Request::schemeDomain(), array(
  177. 'c' => 'QrcodeData',
  178. 'a' => 'Invitation',
  179. 'uid' => $uid,
  180. 'events_id' => $events_id,
  181. 'formsId' => $formsId,
  182. 'token' => $token,
  183. ));
  184. \QRcode::png($data, $IMG_UPLOAD_PATH . DS . $filename, 3, 6);
  185. $imgUrl = $IMG_UPLOAD_URL . DS . $filename;
  186. $info = $objLotteryEventsTypeInvitation->getEventsData();
  187. # 获取登录地址
  188. $plat_form_id = $this->getPlatFormId();
  189. $objPlatForm = new Platform();
  190. $form = $objPlatForm -> get($plat_form_id);
  191. $url = $form['url'];
  192. # 列表页URL
  193. $this->setOutput('listUrl', Request::schemeDomain().'/list/'.$url);
  194. # 我的礼品URL
  195. $this->setOutput('giftsUrl', Request::schemeDomain().'/list/'.$url.'/member/gifts');
  196. $this->tpl = 'save_qrcode';
  197. $this->setOutput('title', '保存二维码');
  198. $this->setOutput('imgUrl', $imgUrl);
  199. $this->setOutput('info', $info);
  200. }
  201. public function display() {
  202. return $this->render();
  203. }
  204. }