Cate.class.php 3.9 KB

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