EventsArticle.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace Cas\Controller;
  3. use Cas\Dao\LotteryEvents;
  4. use KIF\Core\Request;
  5. use KIF\Verify;
  6. use Cas\Module\LotteryLog;
  7. use Cas\Dao\UserInfo;
  8. use Cas\Module\Count;
  9. use Cas\Dao\ArticleLikeCounter;
  10. use Cas\Dao\ArticleLike;
  11. use Cas\Module\Lottery;
  12. /**
  13. * "文章"活动
  14. */
  15. class EventsArticle extends EventsController {
  16. public function doDefault() {
  17. $thisTime = time ();
  18. //$events_id = Request::g ( 'events_id' );
  19. $events_id = $this->getEventsCreateTimeToId();
  20. if (! Verify::unsignedInt ( $events_id )) {
  21. self::fail_exit ( '无效id' );
  22. }
  23. // 获取“文章”信息
  24. $objDLotteryEvents = new LotteryEvents ();
  25. $articleInfo = $objDLotteryEvents->get ( $events_id );
  26. # 检查是否移动端
  27. $title = $articleInfo['weixinShare']['title'] ? $articleInfo['weixinShare']['title']: $articleInfo['events_name'];
  28. $this->checkIsFromMobile($title);
  29. # 获取登录地址
  30. $url = Request::g('url');
  31. $plat_form_id = $this->getPlatFormId();
  32. $objMLottery = new Lottery();
  33. $thisUrl = $objMLottery -> getEventsUrl($articleInfo['type'],$articleInfo['create_time'],$url);
  34. $loginUrl = $this -> getLoginUrl($thisUrl);
  35. $this->setOutput('loginUrl', $loginUrl);
  36. # 判断是否需要登录
  37. $ckLogin = $this->ckLogin();
  38. $this->setOutput('ckLogin', $ckLogin);
  39. # 获取用户信息
  40. $objUserData = new UserInfo();
  41. $uid = $this->getRunTimeUid();
  42. $userData = $objUserData -> get($uid);
  43. $this->setOutput('userData', $userData);
  44. # 检查当前活动是否需要登录
  45. $authorize = $articleInfo['authorize'];
  46. if ($authorize && $loginUrl) {
  47. if($ckLogin==true){
  48. self::redirect($loginUrl);
  49. }
  50. }
  51. $objMLotteryLog = new LotteryLog ( $uid, $events_id );
  52. $other = array (
  53. '访问页面:' => '成功'
  54. );
  55. $objMLotteryLog->addUserParticipateLog ( $other );
  56. # 记录PV UV日志 访问
  57. $objCount = new Count();
  58. $objCount->setPassLog( $events_id,$plat_form_id);
  59. # 获取点赞数
  60. $objArticleLikeCounter = new ArticleLikeCounter();
  61. $likes = $objArticleLikeCounter->getLikes($events_id);
  62. $likes = $likes + $articleInfo['article_praise'];
  63. # 是否已经点赞
  64. $objArticleLike = new ArticleLike();
  65. $isHasLikes = $objArticleLike->isHasLike($events_id, $uid);
  66. # 页面点击数
  67. $clickNum = $articleInfo['click_num'] + $articleInfo['article_pass_base_num']?$articleInfo['click_num'] + $articleInfo['article_pass_base_num']:0;
  68. # 当前访问后增加一个点击
  69. $objDLotteryEvents -> modify(array('click_num' => $articleInfo['click_num']+1 ), array('id' => $events_id));
  70. preg_match_all('/<embed\s{1}src=\"([^\"]+)\"[^>]+>/i', $articleInfo['article_text'], $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. $articleInfo['article_text'] = str_replace($tmpMatch, $tmp_new_video_html, $articleInfo['article_text']);
  74. }
  75. $this->tpl = 'events_article';
  76. $this->setOutput('title', $articleInfo['weixinShare']['title'] ? $articleInfo['weixinShare']['title'] : $articleInfo['events_name']);
  77. $this->setOutput('display', $articleInfo['list_display']);
  78. $this->setOutput('article', $articleInfo);
  79. $this->setOutput('weixinShare', $articleInfo['weixinShare']);
  80. $this->setOutput('likes', $likes);
  81. $this->setOutput('isHasLikes', $isHasLikes);
  82. $this->setOutput('clickNum', $clickNum);
  83. }
  84. public function doLikes() {
  85. $type = Request::p('type'); //点赞类型。1点赞、2取消
  86. if (!in_array($type, array(1,2))) {
  87. $this->ajax_fail_exit('操作失败');
  88. }
  89. $events_id = Request::p('events_id');
  90. if (!Verify::unsignedInt($events_id)) {
  91. $this->ajax_fail_exit('操作失败');
  92. }
  93. $uid = $this->getRunTimeUid();
  94. if (!Verify::unsignedInt($uid)) {
  95. $this->ajax_fail_exit('操作失败');
  96. }
  97. $objArticleLike = new ArticleLike();
  98. $objArticleLikeCounter = new ArticleLikeCounter();
  99. if ($type == 1) {
  100. $objArticleLike->like($events_id, $uid);
  101. $objArticleLikeCounter->incrLikes($events_id);
  102. }
  103. if ($type == 2) {
  104. $objArticleLike->cancalLike($events_id, $uid);
  105. $objArticleLikeCounter->decrLikes($events_id);
  106. }
  107. $this->ajax_success_exit();
  108. }
  109. /**
  110. *
  111. */
  112. public function display() {
  113. return $this->render ();
  114. }
  115. }