Index.class.php 3.2 KB

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