EventsInvitation.class.php 7.4 KB

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