Cate.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace Cas\Controller;
  3. use KIF\Core\Request;
  4. use Cas\Dao\LotteryEvents;
  5. use Cas\Module\Lottery;
  6. use KIF\Dao\SqlHelper;
  7. use Cas\Dao\UserInfo;
  8. use Cas\Module\LotteryLog;
  9. use Cas\Dao\LotteryData;
  10. use Cas\Module\User;
  11. use Cas\Dao\LotteryUserExpress;
  12. use Cas\Dao\Category;
  13. use Cas\Dao\ArticleLikeCounter;
  14. /**
  15. * 分类下的活动列表页 - 首页
  16. * lihuanchun
  17. */
  18. class Cate extends EventsController {
  19. /**
  20. * 页面:默认首页
  21. */
  22. public function doDefault() {
  23. $cate = Request::varGetInt('cate', 1);
  24. $objCategory = new Category();
  25. $cateInfo = $objCategory->fetchOne(array
  26. (
  27. 'id' => $cate,
  28. ));
  29. if (!$cateInfo) {
  30. echo '错误的分类信息';die;
  31. }
  32. # 检查是否移动端
  33. $title = '精彩活动-' . $cateInfo['name'];
  34. $this->checkIsFromMobile($title);
  35. $plat_form_id = $this->getPlatFormId();
  36. $thisTime = time();
  37. $objMLottery = new Lottery();
  38. $condition = array(
  39. 'category_id' => $cate,
  40. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  41. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  42. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  43. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  44. );
  45. # 获取登录地址
  46. $url = Request::g('url');
  47. $thisUrl = Request::schemeDomain().'/cate/'.$cate . '/' . $url;
  48. $loginUrl = $this -> getLoginUrl($thisUrl);
  49. $this->setOutput('loginUrl', $loginUrl);
  50. # 判断是否需要登录
  51. $ckLogin = $this->ckLogin();
  52. $this->setOutput('ckLogin', $ckLogin);
  53. # 获取用户信息
  54. $objUserData = new UserInfo();
  55. $uid = $this->getRunTimeUid();
  56. $userData = $objUserData -> get($uid);
  57. $this->setOutput('userData', $userData);
  58. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  59. $offset = 0;
  60. $size = 10;
  61. $order = 'id desc';
  62. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition, "{$offset},{$size}", $order);
  63. # 剩余天数
  64. $TIME = time();
  65. $objArticleLikeCounter = new ArticleLikeCounter();
  66. foreach ($eventsData as $tmpKey => $tmpData) {
  67. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  68. $eventsData[$tmpKey]['rday'] = ceil($rday);
  69. # 参与人数
  70. $objMLotteryLog = new LotteryLog ( null, $tmpData['id'] );
  71. $eventsData[$tmpKey]['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  72. if ($tmpData['type'] == 9) {
  73. # 阅读人数
  74. $eventsData[$tmpKey]['click_num'] = $tmpData['click_num'] + ($tmpData['article_pass_base_num']?$tmpData['click_num'] + $tmpData['article_pass_base_num']:0);
  75. # 点赞人数
  76. $eventsData[$tmpKey]['likes'] = $objArticleLikeCounter->getLikes($tmpData['id']);
  77. $eventsData[$tmpKey]['likes'] = $eventsData[$tmpKey]['likes'] + $tmpData['article_praise'];
  78. }
  79. }
  80. $this->setOutput('cate', $cate);
  81. $this->setOutput('eventsData', $eventsData);
  82. $this->setOutput('title', $title);
  83. $this->setOutput('totals', ceil($totals / $size));
  84. $this->tpl = 'list';
  85. $this->setOutput('plat_form_id', $plat_form_id);
  86. $this->setOutput('url', $url);
  87. $this->setOutput('display', 1);
  88. }
  89. /**
  90. * 事件:ajax翻页
  91. */
  92. public function doAjax() {
  93. $page = Request::varGetInt('page', 1);
  94. $cate = Request::varGetInt('cate', 1);
  95. $thisTime = time();
  96. $objMLottery = new Lottery();
  97. $plat_form_id = Request::g('plat_form_id');
  98. $condition = array(
  99. 'category_id' => $cate,
  100. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  101. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  102. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  103. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  104. );
  105. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  106. $order = 'begin_time desc';
  107. $size = 10;
  108. $offset = ($page - 1) * $size;
  109. $limit = "{$offset},{$size}";
  110. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition,$limit,$order);
  111. # 剩余天数
  112. $TIME = time();
  113. $objArticleLikeCounter = new ArticleLikeCounter();
  114. foreach ($eventsData as $tmpKey => $tmpData) {
  115. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  116. $eventsData[$tmpKey]['rday'] = ceil($rday);
  117. # 参与人数
  118. $objMLotteryLog = new LotteryLog ( null, $tmpData['id'] );
  119. $eventsData[$tmpKey]['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  120. if ($tmpData['type'] == 9) {
  121. # 阅读人数
  122. $eventsData[$tmpKey]['click_num'] = $tmpData['click_num'] + ($tmpData['article_pass_base_num']?$tmpData['click_num'] + $tmpData['article_pass_base_num']:0);
  123. # 点赞人数
  124. $eventsData[$tmpKey]['likes'] = $objArticleLikeCounter->getLikes($tmpData['id']);
  125. $eventsData[$tmpKey]['likes'] = $eventsData[$tmpKey]['likes'] + $tmpData['article_praise'];
  126. }
  127. }
  128. $this->tpl = 'ajax_list';
  129. $data = array_fill(0, 4, 1);
  130. $this->setOutput('eventsData', $eventsData);
  131. $this->ajax_success_exit($this->render(true));
  132. }
  133. public function display() {
  134. $this->setOutput('action', 'index');
  135. return $this->render();
  136. }
  137. }