Index.class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 Index extends EventsController {
  19. public function doSetUser() {
  20. $objUserData = new User();
  21. $objUserData->setAvatar();
  22. echo 'yes';
  23. }
  24. /**
  25. * 页面:默认新版首页
  26. */
  27. public function doDefault() {
  28. # 检查是否移动端
  29. $title = '精彩活动';
  30. $this->checkIsFromMobile($title);
  31. $plat_form_id = $this->getPlatFormId();
  32. $thisTime = time();
  33. $this->objMLottery = new Lottery();
  34. # 获取登录地址
  35. $url = Request::g('url');
  36. $thisUrl = Request::schemeDomain().'/list/'.$url;
  37. $loginUrl = $this -> getLoginUrl($thisUrl);
  38. $this->setOutput('loginUrl', $loginUrl);
  39. $this->setOutput('url', $url);
  40. # 判断是否需要登录
  41. $ckLogin = $this->ckLogin();
  42. $this->setOutput('ckLogin', $ckLogin);
  43. # 获取用户信息
  44. $objUserData = new UserInfo();
  45. $uid = $this->getRunTimeUid();
  46. $userData = $objUserData -> get($uid);
  47. $this->setOutput('userData', $userData);
  48. # 获取焦点图
  49. $order = 'begin_time desc';
  50. $focusCondition = array(
  51. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  52. 'focus_display' => LotteryEvents::FOCUS_DISPLAY_SHOW,//焦点图
  53. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  54. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  55. );
  56. $focusData = $this->objMLottery -> getLotteryEventsList($focusCondition, "0,5", 'id desc');
  57. $this->setOutput('focusData', $focusData);
  58. # 热门活动
  59. $condition = array(
  60. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  61. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  62. 'top_display' => LotteryEvents::TOP_DISPLAY_SHOW, // 是否置顶
  63. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  64. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  65. );
  66. $totals = $this->objMLottery -> getLotteryEventsListNum($condition);
  67. $offset = 0;
  68. $size = 100;
  69. # 开始时间排序
  70. $order = 'begin_time desc';
  71. # 热门活动
  72. $eventsData = $this->objMLottery -> getLotteryEventsList($condition, "{$offset},{$size}", $order);
  73. $TIME = time();
  74. $objArticleLikeCounter = new ArticleLikeCounter();
  75. foreach ($eventsData as $tmpKey => $tmpData) {
  76. # 剩余天数
  77. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  78. $eventsData[$tmpKey]['rday'] = ceil($rday);
  79. # 参与人数
  80. $objMLotteryLog = new LotteryLog ( null, $tmpData['id'] );
  81. $eventsData[$tmpKey]['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  82. if ($tmpData['type'] == 9) {
  83. # 阅读人数
  84. $eventsData[$tmpKey]['click_num'] = $tmpData['click_num'] + ($tmpData['article_pass_base_num']?$tmpData['click_num'] + $tmpData['article_pass_base_num']:0);
  85. # 点赞人数
  86. $eventsData[$tmpKey]['likes'] = $objArticleLikeCounter->getLikes($tmpData['id']);
  87. $eventsData[$tmpKey]['likes'] = $eventsData[$tmpKey]['likes'] + $tmpData['article_praise'];
  88. }
  89. }
  90. # 获得福利
  91. $this->prize($eventsData, $plat_form_id, 5);
  92. # 获取分类
  93. $this->objDCategory = new Category ();
  94. $order = 'id desc';
  95. $condition = array ();
  96. $ids = $this->objDCategory->findIdsBy ( $condition, '0,50', $order );
  97. $categoryData = $this->objDCategory->gets ( $ids );
  98. $this->setOutput('categoryData', $categoryData);
  99. $this->setOutput('domain', Request::schemeDomain ());
  100. $this->setOutput('eventsData', $eventsData);
  101. $this->setOutput('title', '精彩活动');
  102. $this->setOutput('totals', ceil($totals / $size));
  103. $this->tpl = 'index';
  104. $this->setOutput('plat_form_id', $plat_form_id);
  105. $this->setOutput('display', 1);
  106. $this->setOutput('url', $url);
  107. }
  108. /**
  109. * 页面:默认首页
  110. *
  111. public function doOldDefault() {
  112. # 检查是否移动端
  113. $title = '精彩活动';
  114. $this->checkIsFromMobile($title);
  115. $plat_form_id = $this->getPlatFormId();
  116. $thisTime = time();
  117. $objMLottery = new Lottery();
  118. $condition = array(
  119. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  120. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  121. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  122. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  123. );
  124. # 获取登录地址
  125. $url = Request::g('url');
  126. $thisUrl = Request::schemeDomain().'/list/'.$url;
  127. $loginUrl = $this -> getLoginUrl($thisUrl);
  128. $this->setOutput('loginUrl', $loginUrl);
  129. # 判断是否需要登录
  130. $ckLogin = $this->ckLogin();
  131. $this->setOutput('ckLogin', $ckLogin);
  132. # 获取用户信息
  133. $objUserData = new UserInfo();
  134. $uid = $this->getRunTimeUid();
  135. $userData = $objUserData -> get($uid);
  136. $this->setOutput('userData', $userData);
  137. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  138. $offset = 0;
  139. $size = 6;
  140. $order = 'id desc';
  141. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition, "{$offset},{$size}", $order);
  142. # 剩余天数
  143. $TIME = time();
  144. foreach ($eventsData as $tmpKey => $tmpData) {
  145. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  146. $eventsData[$tmpKey]['rday'] = ceil($rday);
  147. }
  148. $this->setOutput('eventsData', $eventsData);
  149. $this->setOutput('title', '精彩活动');
  150. $this->setOutput('totals', ceil($totals / $size));
  151. $this->tpl = 'index';
  152. $this->setOutput('plat_form_id', $plat_form_id);
  153. $this->setOutput('url', $url);
  154. }
  155. /**
  156. * 事件:ajax翻页
  157. */
  158. public function doAjax() {
  159. $page = Request::varGetInt('page', 1);
  160. $thisTime = time();
  161. $objMLottery = new Lottery();
  162. $plat_form_id = Request::g('plat_form_id');
  163. $condition = array(
  164. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  165. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  166. 'top_display' => LotteryEvents::TOP_DISPLAY_SHOW, // 是否置顶
  167. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  168. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  169. );
  170. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  171. $order = 'begin_time desc';
  172. $size = 10;
  173. $offset = ($page - 1) * $size;
  174. $limit = "{$offset},{$size}";
  175. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition,$limit,$order);
  176. # 剩余天数
  177. $TIME = time();
  178. foreach ($eventsData as $tmpKey => $tmpData) {
  179. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  180. $eventsData[$tmpKey]['rday'] = ceil($rday);
  181. }
  182. $this->tpl = 'ajax_index';
  183. $data = array_fill(0, 4, 1);
  184. $this->setOutput('eventsData', $eventsData);
  185. $this->ajax_success_exit($this->render(true));
  186. }
  187. public function display() {
  188. $this->setOutput('action', 'index');
  189. return $this->render();
  190. }
  191. }