VipInfo.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <?php
  2. /**
  3. * 游戏管理控制器
  4. */
  5. namespace app\admin\controller;
  6. use app\common\library\FileUpload;
  7. use think\Db;
  8. use think\Exception;
  9. class VipInfo extends Admin
  10. {
  11. protected $gameModel;
  12. protected $gameList;
  13. // todo 显示的新闻类型
  14. private $_type
  15. = array(
  16. 6 => '活动' ,
  17. 7 => '更新' ,
  18. 8 => '新闻' ,
  19. 9 => '充值活动'
  20. );
  21. private $_typeList = ['6','7','8','9'];
  22. // 游戏等级
  23. protected $gameLevel = ['S' , 'A1' , 'A2' , 'B1' , 'B2' , 'B3' , 'B4' , 'C' , 'D'];
  24. /**
  25. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  26. */
  27. protected function _initialize()
  28. {
  29. parent::_initialize();
  30. //$this->gameModel = new GameModel;
  31. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  32. }
  33. /**
  34. * 资讯总汇
  35. */
  36. public function index()
  37. {
  38. $gameid = input('gameid' , '' , 'filterAndTrimInput');
  39. $condition = [];
  40. $count = [];
  41. $today = date('Ymd');
  42. $mapStr = '';
  43. if ($gameid) {
  44. $condition['a.gameid'] = $gameid;
  45. $mapStr = "(a.gameid = $gameid and a.type = 0 and a.isdelete=0 and a.sercertype=2)";
  46. }else{
  47. $mapStr = "(a.type = 0 and a.isdelete=0 and a.sercertype=2)";
  48. }
  49. $count = [
  50. 'new' => 0 ,
  51. 'test' => 0 ,
  52. 'vip' => 0 ,
  53. 'news' => 0 ,
  54. ];
  55. //开服列表
  56. $serverNewList = model('ServerInfo')
  57. ->alias('a')
  58. ->join('cy_game b' , 'a.gameid = b.id')
  59. ->where(['a.type' => 0 , 'a.isdelete' => 0 , 'a.sertime' => ['gt' , NOW_TIMESTAMP]])
  60. ->where($condition)
  61. ->whereOr($mapStr)
  62. ->field('a.*,b.name as gameName')
  63. ->order('a.sercertype asc, a.sertime asc')
  64. ->limit(5)
  65. ->select();
  66. if (count($serverNewList) == 5) {
  67. $count['new'] = 5;
  68. }
  69. foreach ($serverNewList as &$newlist) {
  70. if ($newlist['sercertype'] == 1){
  71. if (date('Ymd') == date('Ymd' , $newlist['sertime'])) {
  72. $newlist['color'] = '#ff6600';
  73. $newlist['sertime'] = '今天' . date("H:i" , $newlist['sertime']);
  74. }else {
  75. $newlist['sertime'] = date("Y-m-d H:i:s" , $newlist['sertime']);
  76. }
  77. }elseif ($newlist['sercertype'] == 2) {
  78. $newlist['sertime'] = '长期有效';
  79. }
  80. }
  81. //开测列表
  82. $serverTestList = model('ServerInfo')->alias('a')->join('cy_game b' , 'a.gameid = b.id')
  83. ->where(['a.type' => 1 , 'a.isdelete' => 0 , 'a.sertime' => ['gt' , NOW_TIMESTAMP]])
  84. ->where($condition)
  85. ->field('a.*,b.name as gameName')
  86. ->order('a.sertime asc')
  87. ->limit(5)
  88. ->select();
  89. if (count($serverTestList) == 5) {
  90. $count['test'] = 5;
  91. }
  92. $where['endtime'] = array('gt' , NOW_TIMESTAMP);
  93. $where['total'] = array('gt' , 0);
  94. $where['isdelete'] = 0;
  95. foreach ($serverTestList as &$testlist) {
  96. $where['gameid'] = $testlist['gameid'];
  97. $result = model('Libaoinfo')->where($where)->select();
  98. if ($result) {
  99. foreach ($result as $data) {
  100. if ($data['total'] > $data['used']) {
  101. $testlist['gift'] = 1;
  102. break;
  103. }
  104. }
  105. }
  106. if ($today == date('Ymd' , $testlist['sertime'])) {
  107. $testlist['color'] = '#ff6600';
  108. $testlist['sertime'] = '今天' . date("H:i" , $testlist['sertime']);
  109. } else {
  110. $testlist['sertime'] = date("Y-m-d H:i:s" , $testlist['sertime']);
  111. }
  112. }
  113. //VIP价格列表
  114. $vipPriceList = model('GameVipPrice')->alias('a')->join('cy_game b' , 'a.gameid = b.id')
  115. ->where($condition)->field('a.*,b.name as gameName')
  116. ->order('a.online_time desc')->limit(5)->select();
  117. if (count($vipPriceList) == 5) {
  118. $count['vip'] = 5;
  119. }
  120. //新闻资讯列表
  121. $condition['isdelete'] = 0;
  122. $condition['type'] = ['in' , $this->_typeList];
  123. $newsInfoList = model('Article')->alias('a')->where($condition)->order('a.zhiding desc,a.create_time desc')->limit(5)->select();
  124. foreach ($newsInfoList as &$newslist) {
  125. $newslist['new'] = '';
  126. if ($today == date('Ymd' , $newslist['create_time'])) {
  127. $newslist['new'] = '1';
  128. }
  129. }
  130. if (count($newsInfoList) == 5) {
  131. $count['news'] = 5;
  132. }
  133. // 数据绑定
  134. $this->assign('type_list' , $this->_type);
  135. $this->assign('gamelist' , $this->gameList);
  136. $this->assign('count' , $count);
  137. $this->assign('serverNewList' , $serverNewList);
  138. $this->assign('serverTestList' , $serverTestList);
  139. $this->assign('vipPriceList' , $vipPriceList);
  140. $this->assign('newsInfoList' , $newsInfoList);
  141. return $this->fetch('index');
  142. }
  143. /**
  144. * 开服列表
  145. */
  146. public function servernewlist()
  147. {
  148. $gameid = input('gameid' , '' , 'filterAndTrimInput');
  149. $start = input('start' , strtotime('today') , 'strtotime'); // 默认时间
  150. $end = input('end' , 0 , 'strtotime');
  151. $condition = [];
  152. $mapStr = '';
  153. if ( !empty($gameid)) {
  154. $condition['gameid'] = $gameid;
  155. $mapStr = "(gameid = $gameid and type = 0 and isdelete=0 and sercertype=2)";
  156. }else{
  157. $mapStr = "(type = 0 and isdelete=0 and sercertype=2)";
  158. }
  159. $time_condition = makeTimeCondition(input('start') , input('end'));
  160. if ($time_condition && 0 < count($time_condition)) {
  161. $condition['sertime'] = $time_condition;
  162. }
  163. $end = $end ? $end + 24 * 3600 - 1 : 0; // 查询日期当天
  164. $runable = true;
  165. if ($start && $end) {
  166. $condition['sertime'] = ['BETWEEN' , [$start , $end]];
  167. if ($start > $end){
  168. $runable = false;
  169. }
  170. } else if ($start) {
  171. $condition['sertime'] = ['EGT' , $start];
  172. } else if ($end) {
  173. $condition['sertime'] = ['ELT' , $end];
  174. }
  175. $condition['type'] = 0;
  176. $condition['isdelete'] = 0;
  177. if (!$runable){
  178. $mapStr = '';
  179. }
  180. $list = model('ServerInfo')
  181. ->field('*')
  182. ->where($condition)
  183. ->whereOr($mapStr)
  184. ->order('sercertype asc, sertime asc')
  185. ->paginate(10, false, array('query' => input('get.')))
  186. ->each(function($newlist, $key){
  187. if ($newlist['sercertype'] == 1){
  188. if (date('Ymd') == date('Ymd' , $newlist['sertime'])) {
  189. $newlist['color'] = '#ff6600';
  190. $newlist['sertime'] = '今天' . date("H:i" , $newlist['sertime']);
  191. }else {
  192. $newlist['sertime'] = date("Y-m-d H:i:s" , $newlist['sertime']);
  193. }
  194. }elseif ($newlist['sercertype'] == 2) {
  195. $newlist['sertime'] = '长期有效';
  196. }
  197. return $newlist;
  198. });
  199. $this->assign('page' , $list->render());
  200. $this->assign('gamelist' , $this->gameList);
  201. $this->assign('list' , $list);
  202. // $this->assign('count' , count($listData));
  203. $this->assign('start' , $start ? date('Y-m-d' , $start) : '');
  204. return $this->fetch('serverNewList');
  205. }
  206. /**
  207. * vip价格表
  208. */
  209. public function vipPriceList()
  210. {
  211. $gameid = input('gameid' , '' , 'filterAndTrimInput');
  212. $condition = [];
  213. if ($gameid) {
  214. $condition['gameid'] = $gameid;
  215. }
  216. $time_condition = makeTimeCondition(input('start') , input('end'));
  217. if ($time_condition && 0 < count($time_condition)) {
  218. $condition['online_time'] = $time_condition;
  219. }
  220. $list = model('GameVipPrice')
  221. ->order('online_time desc')->where($condition)
  222. ->paginate(10 , false , ['query' => $condition]);
  223. $this->assign('list' , $list);
  224. $this->assign('gamelist' , $this->gameList);
  225. $this->assign('page' , $list->render());
  226. return $this->fetch('vipPriceList');
  227. }
  228. /**
  229. * 新闻列表
  230. */
  231. public function newsInfo()
  232. {
  233. $condition = [];
  234. $title = input('title' , '' , 'filterAndTrimInput');
  235. $gameid = input('gameid' , '' , 'intval');
  236. $type = input('type' , '' , 'intval');
  237. if ($title) {
  238. $condition['title'] = array('LIKE' , '%' . $title . '%');
  239. }
  240. $time_condition = makeTimeCondition(input('start'), input('end'));
  241. if ( $time_condition && 0 < count($time_condition) ) {
  242. $condition['create_time'] = $time_condition;
  243. }
  244. $condition['isdelete'] = 0;
  245. $condition['type'] = ['in',$this->_typeList];
  246. if($type){
  247. $condition['type'] = $type;
  248. }
  249. if($gameid){
  250. $condition['gameid'] = $gameid;
  251. }
  252. $newsInfoList = model('Article')->table('cy_article a,cy_content c')
  253. ->field('a.*,c.content')
  254. ->where('a.id=c.id')
  255. ->where($condition)->order('zhiding desc,create_time desc')->paginate(20, false, array('query' => input('get.')))
  256. ->each(function($row, $key){
  257. $today = date('Ymd');
  258. //$row['isNew'] = (bool)($row['create_time'] > $today);
  259. $row['content'] = mb_substr(str_replace("  ", '', strip_tags($row['content'])),0,100,'UTF-8') ."...";
  260. if ($today == date('Ymd' , $row['create_time'])) {
  261. $row['new'] = '1';
  262. }else{
  263. $row['new'] = '0';
  264. }
  265. return $row;
  266. });
  267. /*$list = $newsInfoList->toArray();
  268. foreach ($list['data'] as &$row){
  269. $row['isNew'] = (bool)($row['create_time'] > $today);
  270. $row['content'] = mb_substr(str_replace("  ", '', strip_tags($row['content'])),0,100,'UTF-8') ."...";
  271. }*/
  272. $this->assign('page',$newsInfoList->render());
  273. $this->assign('type_list', $this->_type);
  274. $this->assign('gamelist',$this->gameList);
  275. $this->assign('list',$newsInfoList);
  276. // dump($newsInfoList);
  277. return $this->fetch('newsInfo');
  278. }
  279. /**
  280. * 新闻详情页
  281. */
  282. public function detailNews(){
  283. $condition = [];
  284. $id = input('id','','filterAndTrimInput');
  285. $condition['id'] = $id;
  286. $content = model('Content')->where($condition)->value('content');
  287. $condition['isdelete'] = 0;
  288. $data = model('Article')->where($condition)->find();
  289. $data['content'] = $content;
  290. $next = model('Article')->where(['id'=>($id-1),'type'=>['in',$this->_typeList]])->find();
  291. $last = model('Article')->where(['id'=>($id+1),'type'=>['in',$this->_typeList]])->find();
  292. $contact = model('Article')->where(
  293. ['gameid'=>$data['gameid'],
  294. 'type'=>['in',$this->_typeList],
  295. 'id'=>['not in',[$id]
  296. ]])
  297. ->limit(6)->order('create_time desc')->select();
  298. foreach ($contact as &$info){
  299. $info['title2'] = $info['title'];
  300. if(strlen($info['title']) > 20){
  301. $info['title'] = mb_substr(str_replace("  ", '', strip_tags($info['title'])),0,12,'UTF-8') ."...";
  302. }
  303. }
  304. $this->assign('contact',$contact);
  305. $this->assign('data',$data);
  306. $this->assign('last',$last);
  307. $this->assign('next',$next);
  308. $this->assign('content',$content);
  309. return $this->fetch('detailNews');
  310. }
  311. /**
  312. * 开测表
  313. */
  314. public function serverTestList(){
  315. $gameId = input('gameid', '', 'intval');
  316. $start = input('start', strtotime('today'), 'strtotime'); // 默认时间
  317. $end = input('end', 0, 'strtotime');
  318. $condition = [];
  319. if ( !empty($gameId)) {
  320. $condition['gameid'] = $gameId;
  321. }
  322. $condition['type'] = 1; // 开服
  323. $condition['isdelete'] = 0; // 未删除的
  324. $runable = true;
  325. if ($start && $end) {
  326. $condition['sertime'] = ['BETWEEN', [$start, $end]];
  327. if ($start > $end){
  328. $runable = false;
  329. }
  330. } else if ($start) {
  331. $condition['sertime'] = ['EGT', $start];
  332. } else if ($end) {
  333. $condition['sertime'] = ['ELT', $end];
  334. }
  335. if (!$runable){
  336. $mapStr = '';
  337. }
  338. $list = model('ServerInfo')
  339. ->field('*')
  340. ->where($condition)
  341. ->order('sertime ASC')
  342. ->paginate(10, false, array('query' => input('get.')))
  343. ->each(function($item, $key){
  344. $item['sertime'] = $this->_getPrettyTime($item['sertime']);
  345. return $item;
  346. });
  347. $this->assign('list', $list);
  348. $this->assign('page', $list->render());
  349. $this->assign('gamelist' , $this->gameList);
  350. return $this->fetch('serverTest');
  351. }
  352. // 格式化时间
  353. protected function _getPrettyTime($time)
  354. {
  355. $today = strtotime('today');
  356. $tomorrow = strtotime('tomorrow');
  357. $prefix = '';
  358. if ($time >= $today && $time < $tomorrow ) {
  359. $prefix = '今天 ';
  360. } else if ($time >= $tomorrow && $time < $tomorrow + 24 * 3600) {
  361. $prefix = '明天 ';
  362. }
  363. if ($prefix) {
  364. return '<span style="color: rgb(235, 140, 63)">' . $prefix . date('H:i', $time) .'</span>';
  365. }
  366. return date('Y-m-d H:i', $time);
  367. }
  368. }