Cate.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. } else {
  79. if (isset($tmpData['base_num']) && $tmpData['base_num']) {
  80. $eventsData[$tmpKey]['user_total'] += $tmpData['base_num'];
  81. }
  82. }
  83. }
  84. $this->setOutput('cate', $cate);
  85. $this->setOutput('eventsData', $eventsData);
  86. $this->setOutput('title', $title);
  87. $this->setOutput('totals', ceil($totals / $size));
  88. $this->tpl = 'list';
  89. $this->setOutput('plat_form_id', $plat_form_id);
  90. $this->setOutput('url', $url);
  91. $this->setOutput('display', 1);
  92. }
  93. /**
  94. * 事件:ajax翻页
  95. */
  96. public function doAjax() {
  97. $page = Request::varGetInt('page', 1);
  98. $cate = Request::varGetInt('cate', 1);
  99. $thisTime = time();
  100. $objMLottery = new Lottery();
  101. $plat_form_id = Request::g('plat_form_id');
  102. $condition = array(
  103. 'category_id' => $cate,
  104. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  105. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  106. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  107. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  108. );
  109. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  110. $order = 'begin_time desc';
  111. $size = 10;
  112. $offset = ($page - 1) * $size;
  113. $limit = "{$offset},{$size}";
  114. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition,$limit,$order);
  115. # 剩余天数
  116. $TIME = time();
  117. $objArticleLikeCounter = new ArticleLikeCounter();
  118. foreach ($eventsData as $tmpKey => $tmpData) {
  119. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  120. $eventsData[$tmpKey]['rday'] = ceil($rday);
  121. # 参与人数
  122. $objMLotteryLog = new LotteryLog ( null, $tmpData['id'] );
  123. $eventsData[$tmpKey]['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  124. if ($tmpData['type'] == 9) {
  125. # 阅读人数
  126. $eventsData[$tmpKey]['click_num'] = $tmpData['click_num'] + ($tmpData['article_pass_base_num']?$tmpData['click_num'] + $tmpData['article_pass_base_num']:0);
  127. # 点赞人数
  128. $eventsData[$tmpKey]['likes'] = $objArticleLikeCounter->getLikes($tmpData['id']);
  129. $eventsData[$tmpKey]['likes'] = $eventsData[$tmpKey]['likes'] + $tmpData['article_praise'];
  130. } else {
  131. if (isset($tmpData['base_num']) && $tmpData['base_num']) {
  132. $eventsData[$tmpKey]['user_total'] += $tmpData['base_num'];
  133. }
  134. }
  135. }
  136. $this->tpl = 'ajax_list';
  137. $data = array_fill(0, 4, 1);
  138. $this->setOutput('eventsData', $eventsData);
  139. $this->ajax_success_exit($this->render(true));
  140. }
  141. public function display() {
  142. $this->setOutput('action', 'index');
  143. return $this->render();
  144. }
  145. }