Layout.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * 一些公用模板控制器
  4. */
  5. namespace app\home\controller;
  6. use app\common\model\ServerInfo;
  7. use app\common\model\GameHome as Game;
  8. use app\common\model\Gift;
  9. use think\Db;
  10. use think\Config;
  11. class Layout extends Home
  12. {
  13. // 游戏类型
  14. protected $_gameType = [
  15. 1 => '角色' ,
  16. 2 => '动作' ,
  17. 3 => '休闲' ,
  18. 4 => '体育' ,
  19. 5 => '策略' ,
  20. 6 => '射击' ,
  21. 8 => '回合' ,
  22. 9 => '卡牌' ,
  23. 10 => '放置' ,
  24. 11 => '竞技' ,
  25. ];
  26. // 游戏题材:1仙侠|2武侠|3魔幻|4三国|5西游|6动漫|7传奇|8女生|9 3D|10战争
  27. protected $_gameSubjct = [
  28. 1 => '仙侠' ,
  29. 2 => '武侠' ,
  30. 3 => '魔幻' ,
  31. 4 => '三国' ,
  32. 5 => '西游' ,
  33. 6 => '动漫' ,
  34. 7 => '传奇' ,
  35. 8 => '女生' ,
  36. 9 => '3D' ,
  37. 10 => '战争' ,
  38. ];
  39. /**
  40. * *开服开测信息
  41. *
  42. */
  43. public function serverinfo() {
  44. $serverInfoModel= new ServerInfo;
  45. $GiftModel = new Gift();
  46. $gameids = []; //游戏ID
  47. // 开服
  48. $serverList = Db::connect(config('database_slave'))->table('cy_serverinfo')->cache(Config::get('QUERY_RESULT_CACHE_TIME'))->alias('s')
  49. ->join('cy_game g', 's.gameid=g.id', 'left')
  50. ->join('cy_sdkgamelist sdk', 'g.id=sdk.gameid and sdk.package_type=0 and sdk.upload_status=1 and sdk.channel_id='.MEMBER_DEFAULT_CHANNEL_ID,'left')
  51. ->field('s.gameid,g.nickname,s.sername,s.sertime,s.sercertype,g.id,g.pinyin,sdk.filename')
  52. ->where(['g.cooperation_status' => ['in','0,1,2'],'g.is_show' => 1,'s.type'=>0,'s.isdelete'=>0])
  53. ->where('s.sertime>'.time().' or s.sertime is null')
  54. ->order('s.sercertype asc,s.sertime asc')->limit(0,13)->select();
  55. foreach ( $serverList as &$game ) {
  56. $game['download'] = getDownload($game);
  57. }
  58. if(!empty($serverList)){
  59. $gameids = arrayColumnByObject($serverList, 'gameid');
  60. }
  61. //开测
  62. $testList = Db::connect(config('database_slave'))->table('cy_serverinfo')->cache(Config::get('QUERY_RESULT_CACHE_TIME'))->alias('s')
  63. ->join('cy_game g', 's.gameid=g.id', 'left')
  64. ->join('cy_sdkgamelist sdk', 'g.id=sdk.gameid and sdk.package_type=0 and sdk.upload_status=1 and sdk.channel_id='.MEMBER_DEFAULT_CHANNEL_ID,'left')
  65. ->field('s.gameid,g.nickname,s.serstatus,s.sertime,g.id,g.pinyin,sdk.filename')
  66. ->where(['g.cooperation_status' => ['in','0,1,2'],'g.is_show' => 1,'s.type'=>1,'s.isdelete'=>0,'s.sertime'=>['>',strtotime("today")]])
  67. ->order('s.sertime asc')->limit(0,12)->select();
  68. foreach ( $testList as &$game ) {
  69. $game['download'] = getDownload($game);
  70. }
  71. if(!empty($testList)){
  72. $testGameids = arrayColumnByObject($testList, 'gameid');
  73. $gameids = array_unique(array_merge($gameids,$testGameids));
  74. }
  75. //有效礼包
  76. $giftList = Db::connect(config('database_slave'))->table('cy_libaoinfo')->cache(Config::get('QUERY_RESULT_CACHE_TIME'))->field('id,gameid')
  77. ->where(['isdelete'=>0,'endtime'=>['>=', NOW_TIMESTAMP],'gameid'=>['in',$gameids]])
  78. ->where('total-used>0')
  79. ->column('id','gameid');
  80. $this->assign('serverList', $serverList);
  81. $this->assign('testList', $testList);
  82. $this->assign('giftList', $giftList);
  83. return view('layout/serverinfo');
  84. }
  85. /**
  86. * *手游排行
  87. *
  88. */
  89. public function gameRankList()
  90. {
  91. $gameModel = new Game;
  92. $gameids = [];
  93. $list = $gameModel->cache(Config::get('QUERY_RESULT_CACHE_TIME'))
  94. ->alias('game')
  95. ->join('cy_gameinfo info', 'game.id=info.game_id','left')
  96. ->join('cy_sdkgamelist sdk', 'game.id=sdk.gameid and sdk.package_type=0 and sdk.upload_status=1 and sdk.channel_id='.MEMBER_DEFAULT_CHANNEL_ID,'left')
  97. ->field('game.id,game.nickname,game.power,game.pinyin,info.mobileicon,game.type,game.subject,sdk.filename')
  98. ->where(['game.cooperation_status' => ['in','1,2'],'game.is_show' => 1])
  99. ->order('game.power desc')
  100. ->limit(0,10)->select();
  101. // var_dump($list);
  102. foreach ( $list as &$game ) {
  103. $game['mobileicon'] = STATIC_DOMAIN.$game['mobileicon'];
  104. $game['download'] = getDownload($game);
  105. }
  106. $this->assign('gameType', $this->_gameType);
  107. $this->assign('gameSubjct', $this->_gameSubjct);
  108. $this->assign('list', $list);
  109. return view('layout/game_rank_list');
  110. }
  111. /**
  112. * 推荐礼包
  113. *
  114. */
  115. public function recommendGiftList()
  116. {
  117. $GiftModel = new Gift();
  118. $giftList = Db::connect(config('database_slave'))->table('cy_libaoinfo')->cache(Config::get('QUERY_RESULT_CACHE_TIME'))->alias('gift')
  119. ->field('gift.id,gift.title,gift.total,gift.used,gift.endtime,info.mobileicon,g.nickname,gift.gameid')
  120. ->join('cy_gameinfo info', 'info.game_id = gift.gameid','left')
  121. ->join('cy_game g', 'gift.gameid=g.id', 'left')
  122. ->where(['gift.is_top'=> 1,'gift.isdelete'=>0,'gift.endtime'=>['>=', NOW_TIMESTAMP],'g.cooperation_status' => ['in','1,2'],'g.is_show' => 1])
  123. ->where('gift.total>gift.used')
  124. ->order('gift.create_time desc')
  125. ->limit(0,6)->select();
  126. if (!empty($giftList)) { // 标识玩家已领取的礼包
  127. foreach ($giftList as &$gift) {
  128. $gift['mobileicon'] = STATIC_DOMAIN.$gift['mobileicon'];
  129. // 剩余可领的数量占比
  130. $gift['percent'] = round(($gift['total'] - $gift['used']) / $gift['total'], 2) * 100;
  131. }
  132. }
  133. $this->assign('giftList', $giftList);
  134. return view('layout/recommend_gift_list');
  135. }
  136. }