Index.class.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 Index extends EventsController {
  18. /**
  19. * 页面:默认新版首页
  20. */
  21. public function doDefault() {
  22. # 检查是否移动端
  23. $title = '精彩活动';
  24. $this->checkIsFromMobile($title);
  25. $plat_form_id = $this->getPlatFormId();
  26. $thisTime = time();
  27. $objMLottery = new Lottery();
  28. # 获取登录地址
  29. $url = Request::g('url');
  30. $thisUrl = Request::schemeDomain().'/list/'.$url;
  31. $loginUrl = $this -> getLoginUrl($thisUrl);
  32. $this->setOutput('loginUrl', $loginUrl);
  33. # 判断是否需要登录
  34. $ckLogin = $this->ckLogin();
  35. $this->setOutput('ckLogin', $ckLogin);
  36. # 获取用户信息
  37. $objUserData = new UserInfo();
  38. $uid = $this->getRunTimeUid();
  39. $userData = $objUserData -> get($uid);
  40. $this->setOutput('userData', $userData);
  41. # 获取焦点图
  42. $order = 'begin_time desc';
  43. $focusCondition = array(
  44. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  45. 'focus_display' => LotteryEvents::FOCUS_DISPLAY_SHOW,//焦点图
  46. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  47. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  48. );
  49. $focusData = $objMLottery -> getLotteryEventsList($focusCondition, "0,5", 'id desc');
  50. # 热门活动
  51. $condition = array(
  52. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  53. //'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  54. 'top_display' => LotteryEvents::TOP_DISPLAY_SHOW, // 是否置顶
  55. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  56. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  57. );
  58. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  59. $offset = 0;
  60. $size = 10;
  61. # 开始时间排序
  62. $order = 'begin_time desc';
  63. # 热门活动
  64. $eventsData = $objMLottery -> getLotteryEventsList($condition, "{$offset},{$size}", $order);
  65. $TIME = time();
  66. foreach ($eventsData as $tmpKey => $tmpData) {
  67. # 剩余天数
  68. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  69. $eventsData[$tmpKey]['rday'] = ceil($rday);
  70. # 参与人数
  71. $objMLotteryLog = new LotteryLog ( null, $tmpData['id'] );
  72. $eventsData[$tmpKey]['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  73. }
  74. # 获得福利
  75. $condition = array('platform_id' => SqlHelper::addCompareOperator('&', $plat_form_id), 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE);
  76. $totals = $objMLottery -> getLotteryDataListNum($condition);
  77. $offset = 0;
  78. $size = 6;
  79. $order = 'update_time desc';
  80. $data = $objMLottery->getLotteryDataList($condition, "{$offset},{$size}", $order);
  81. if ($data) {
  82. $uids = array();
  83. foreach ($data as $k => $v) {
  84. $uids[] = $v['uid'];
  85. }
  86. # 通过UIDs 获取用户信息
  87. $objMUser = new User();
  88. $users = $objMUser -> gets($uids);
  89. $objLotteryUserExpress = new LotteryUserExpress();
  90. $condition = array(
  91. 'uid' => $uids
  92. );
  93. $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition);
  94. $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds);
  95. $newUserExpData = array();
  96. foreach($userExpData as $k => $v){
  97. $newUserExpData[$v['uid']] = $v;
  98. }
  99. $this->setOutput('newUserExpData', $newUserExpData);
  100. //138****1234 的用户 2018.4.20 15:10 获得 某某某某活动 奖品。
  101. foreach ($data as $k => $v) {
  102. $data[$k]['user'] = array();
  103. $data[$k]['user']['cdate'] = $v['winners_time'];
  104. $data[$k]['user']['events'] = $eventsData[$v['events_id']]['events_name'];
  105. if (isset($users[$v['uid']]['headimgurl']) && $users[$v['uid']]['headimgurl']) {
  106. $data[$k]['user']['headimgurl'] = $users[$v['uid']]['headimgurl'];
  107. } else {
  108. $data[$k]['user']['headimgurl'] = 'http://news.mydrivers.com/Img/20110518/04481549.png';
  109. }
  110. if (isset($v['express']['phone']) && $v['express']['phone']) {
  111. $data[$k]['user']['mobile'] = substr_replace($v['express']['phone'],'****',3,4);
  112. } elseif (isset($newUserExpData[$v['uid']]['phone']) && $newUserExpData[$v['uid']]['phone']) {
  113. $data[$k]['user']['mobile'] = substr_replace($newUserExpData[$v['uid']]['phone'],'****',3,4);
  114. } else {
  115. unset($data[$k]);
  116. }
  117. }
  118. $this->setOutput('userData', $data);
  119. }
  120. # 获取分类
  121. $this->objDCategory = new Category ();
  122. $order = 'id desc';
  123. $condition = array ();
  124. $ids = $this->objDCategory->findIdsBy ( $condition, '0,5', $order );
  125. $categoryData = $this->objDCategory->gets ( $ids );
  126. $this->setOutput('categoryData', $categoryData);
  127. $this->setOutput('eventsData', $eventsData);
  128. $this->setOutput('title', '精彩活动');
  129. $this->setOutput('totals', ceil($totals / $size));
  130. $this->tpl = 'mrhi/index';
  131. $this->setOutput('plat_form_id', $plat_form_id);
  132. $this->setOutput('url', $url);
  133. }
  134. /**
  135. * 页面:默认首页
  136. *
  137. public function doOldDefault() {
  138. # 检查是否移动端
  139. $title = '精彩活动';
  140. $this->checkIsFromMobile($title);
  141. $plat_form_id = $this->getPlatFormId();
  142. $thisTime = time();
  143. $objMLottery = new Lottery();
  144. $condition = array(
  145. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  146. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  147. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  148. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  149. );
  150. # 获取登录地址
  151. $url = Request::g('url');
  152. $thisUrl = Request::schemeDomain().'/list/'.$url;
  153. $loginUrl = $this -> getLoginUrl($thisUrl);
  154. $this->setOutput('loginUrl', $loginUrl);
  155. # 判断是否需要登录
  156. $ckLogin = $this->ckLogin();
  157. $this->setOutput('ckLogin', $ckLogin);
  158. # 获取用户信息
  159. $objUserData = new UserInfo();
  160. $uid = $this->getRunTimeUid();
  161. $userData = $objUserData -> get($uid);
  162. $this->setOutput('userData', $userData);
  163. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  164. $offset = 0;
  165. $size = 6;
  166. $order = 'id desc';
  167. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition, "{$offset},{$size}", $order);
  168. # 剩余天数
  169. $TIME = time();
  170. foreach ($eventsData as $tmpKey => $tmpData) {
  171. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  172. $eventsData[$tmpKey]['rday'] = ceil($rday);
  173. }
  174. $this->setOutput('eventsData', $eventsData);
  175. $this->setOutput('title', '精彩活动');
  176. $this->setOutput('totals', ceil($totals / $size));
  177. $this->tpl = 'index';
  178. $this->setOutput('plat_form_id', $plat_form_id);
  179. $this->setOutput('url', $url);
  180. }
  181. /**
  182. * 事件:ajax翻页
  183. */
  184. public function doAjax() {
  185. $page = Request::varGetInt('page', 1);
  186. $thisTime = time();
  187. $objMLottery = new Lottery();
  188. $plat_form_id = Request::g('plat_form_id');
  189. $condition = array(
  190. 'display' => LotteryEvents::EVENT_DISPLAY_SHOW, // 已发布的
  191. 'list_display' => LotteryEvents::LIST_DISPLAY_SHOW, // 列表中是否显示
  192. 'top_display' => LotteryEvents::TOP_DISPLAY_SHOW, // 是否置顶
  193. 'begin_time' => SqlHelper::addCompareOperator('<=', time()),
  194. 'platform_ids' => SqlHelper::addCompareOperator('&', $plat_form_id),
  195. );
  196. $totals = $objMLottery -> getLotteryEventsListNum($condition);
  197. $order = 'begin_time desc';
  198. $size = 10;
  199. $offset = ($page - 1) * $size;
  200. $limit = "{$offset},{$size}";
  201. $eventsData = $allLotteryEventsIds = $objMLottery -> getLotteryEventsList($condition,$limit,$order);
  202. # 剩余天数
  203. $TIME = time();
  204. foreach ($eventsData as $tmpKey => $tmpData) {
  205. $rday = ($tmpData['end_time'] - $TIME) / (24 * 60 * 60);
  206. $eventsData[$tmpKey]['rday'] = ceil($rday);
  207. }
  208. $this->tpl = 'ajax_index';
  209. $data = array_fill(0, 4, 1);
  210. $this->setOutput('eventsData', $eventsData);
  211. $this->ajax_success_exit($this->render(true));
  212. }
  213. public function display() {
  214. $this->setOutput('action', 'index');
  215. return $this->render();
  216. }
  217. }