Index.class.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. } else {
  89. if (isset($tmpData['base_num']) && $tmpData['base_num']) {
  90. $eventsData[$tmpKey]['user_total'] += $tmpData['base_num'];
  91. }
  92. }
  93. }
  94. # 获得福利
  95. $this->prize($eventsData, $plat_form_id, 5);
  96. # 获取分类
  97. $this->objDCategory = new Category ();
  98. $order = 'id desc';
  99. $condition = array ();
  100. $ids = $this->objDCategory->findIdsBy ( $condition, '0,50', $order );
  101. $categoryData = $this->objDCategory->gets ( $ids );
  102. $this->setOutput('categoryData', $categoryData);
  103. $this->setOutput('domain', Request::schemeDomain ());
  104. $this->setOutput('eventsData', $eventsData);
  105. $this->setOutput('title', '精彩活动');
  106. $this->setOutput('totals', ceil($totals / $size));
  107. $this->tpl = 'index';
  108. $this->setOutput('plat_form_id', $plat_form_id);
  109. $this->setOutput('display', 1);
  110. $this->setOutput('url', $url);
  111. }
  112. /**
  113. * 页面:默认首页
  114. *
  115. public function doOldDefault() {
  116. # 检查是否移动端
  117. $title = '精彩活动';
  118. $this->checkIsFromMobile($title);
  119. $plat_form_id = $this->getPlatFormId();
  120. $thisTime = time();
  121. $objMLottery = new Lottery();
  122. $condition = array(
  123. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  124. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  125. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  126. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  127. );
  128. # 获取登录地址
  129. $url = Request::g('url');
  130. $thisUrl = Request::schemeDomain().'/list/'.$url;
  131. $loginUrl = $this -> getLoginUrl($thisUrl);
  132. $this->setOutput('loginUrl', $loginUrl);
  133. # 判断是否需要登录
  134. $ckLogin = $this->ckLogin();
  135. $this->setOutput('ckLogin', $ckLogin);
  136. # 获取用户信息
  137. $objUserData = new UserInfo();
  138. $uid = $this->getRunTimeUid();
  139. $userData = $objUserData -> get($uid);
  140. $this->setOutput('userData', $userData);
  141. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  142. $offset = 0;
  143. $size = 6;
  144. $order = 'id desc';
  145. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition, "{$offset},{$size}", $order);
  146. # 剩余天数
  147. $TIME = time();
  148. foreach ($eventsData as $tmpKey => $tmpData) {
  149. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  150. $eventsData[$tmpKey]['rday'] = ceil($rday);
  151. }
  152. $this->setOutput('eventsData', $eventsData);
  153. $this->setOutput('title', '精彩活动');
  154. $this->setOutput('totals', ceil($totals / $size));
  155. $this->tpl = 'index';
  156. $this->setOutput('plat_form_id', $plat_form_id);
  157. $this->setOutput('url', $url);
  158. }
  159. /**
  160. * 事件:ajax翻页
  161. */
  162. public function doAjax() {
  163. $page = Request::varGetInt('page', 1);
  164. $thisTime = time();
  165. $objMLottery = new Lottery();
  166. $plat_form_id = Request::g('plat_form_id');
  167. $condition = array(
  168. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  169. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  170. 'top_display' => LotteryEvents::TOP_DISPLAY_SHOW, // 是否置顶
  171. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  172. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  173. );
  174. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  175. $order = 'begin_time desc';
  176. $size = 10;
  177. $offset = ($page - 1) * $size;
  178. $limit = "{$offset},{$size}";
  179. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition,$limit,$order);
  180. # 剩余天数
  181. $TIME = time();
  182. foreach ($eventsData as $tmpKey => $tmpData) {
  183. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  184. $eventsData[$tmpKey]['rday'] = ceil($rday);
  185. }
  186. $this->tpl = 'ajax_index';
  187. $data = array_fill(0, 4, 1);
  188. $this->setOutput('eventsData', $eventsData);
  189. $this->ajax_success_exit($this->render(true));
  190. }
  191. public function display() {
  192. $this->setOutput('action', 'index');
  193. return $this->render();
  194. }
  195. }