Subaccount.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * 玩家游戏账号控制器
  4. *
  5. * Created by PhpStorm.
  6. * User: Admin
  7. * Date: 2018/5/10
  8. * Time: 10:27
  9. */
  10. namespace app\admin\controller;
  11. use think\Db;
  12. use app\common\model\Game as GameModel;
  13. use app\common\model\GameInfo;
  14. use app\common\model\Logininfo;
  15. use app\common\model\AndroidSdk;
  16. use app\common\model\AutoPackage;
  17. use app\common\library\ValidateExtend;
  18. class Subaccount extends Admin
  19. {
  20. protected $gameModel;
  21. protected $sdkgamelistModel;
  22. protected $gameList;
  23. protected function _initialize()
  24. {
  25. parent::_initialize();
  26. $this->gameModel = new GameModel;
  27. $this->sdkgamelistModel = $this->cyModel('sdkgamelist');
  28. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  29. $tmpSelfGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
  30. $selfGameList = array();
  31. foreach ($tmpSelfGameList as $game) {
  32. $selfGameList[ $game['id']] = $game;
  33. }
  34. $this->selfGameList = $selfGameList;
  35. }
  36. /**
  37. * 换绑记录列表
  38. * @return mixed
  39. */
  40. public function index()
  41. {
  42. $game_id = input('game_id',0,'intval');
  43. $account = input('account','','trim');
  44. $start_time = input('start_time','','trim');
  45. $end_time = input('end_time','','trim');
  46. $sub_username = input('sub_username','','trim');
  47. $action = input('action','','trim');
  48. // 验证日期格式
  49. if (!empty($start_time) && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $start_time)) {
  50. $start_time = '';
  51. }
  52. if (!empty($end_time) && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $end_time)) {
  53. $end_time = '';
  54. }
  55. // 日期最多选择到今天(包含今天)
  56. if (!empty($start_time) && $start_time > date('Y-m-d')) {
  57. $start_time = date('Y-m-d');
  58. }
  59. if (!empty($end_time) && $end_time > date('Y-m-d')) {
  60. $end_time = date('Y-m-d');
  61. }
  62. // 开始时间不能大于结束时间
  63. if (!empty($start_time) && !empty($end_time) && $start_time > $end_time) {
  64. $start_time = $end_time;
  65. }
  66. // 非搜索(首次进入页面)时,默认查最近一个月的数据
  67. if (empty($action) && empty($start_time) && empty($end_time)) {
  68. $start_time = date('Y-m-d', strtotime('-30 days'));
  69. $end_time = date('Y-m-d');
  70. }
  71. $condition = [];
  72. if(input('account')){
  73. $condition['m.username'] = $account;
  74. }
  75. if(input('sub_username')){
  76. $condition['s.sub_username'] = $sub_username;
  77. }
  78. if(input('game_id') <> ''){
  79. $condition['s.game_id'] = $game_id;
  80. }
  81. // 日期不为空时才处理日期条件
  82. if ($start_time != '' && $end_time != '') {
  83. $condition['s.create_time'] = [
  84. ['>=', strtotime($start_time)],
  85. ['<=', strtotime($end_time . ' 23:59:59')],
  86. ];
  87. } elseif ($start_time != '') {
  88. $condition['s.create_time'] = ['>=', strtotime($start_time)];
  89. } elseif ($end_time != '') {
  90. $condition['s.create_time'] = ['<=', strtotime($end_time . ' 23:59:59')];
  91. }
  92. //查询参数
  93. $param = input('get.');
  94. $subaccountList = model('Subaccount')->alias('s')
  95. ->join('cy_members m', 's.member_id = m.id')
  96. ->join('cy_game g', 's.game_id = g.id')
  97. ->where($condition)
  98. ->field("s.id,s.member_id as userid,m.username,s.sub_username,s.game_id,g.name as game_name,s.create_time as create_time_value,s.auth_type,s.real_name,s.idcard_num,s.last_auth_time as last_auth_time_value,s.auth_pi,s.auth_status")
  99. ->order("id desc")
  100. ->paginate(10, false, ['query' => $param]);
  101. // PDO 可能将时间戳返回为数字字符串,同时兼容历史日期字符串。
  102. $formatTime = function ($value, $format) {
  103. if (empty($value)) {
  104. return '-';
  105. }
  106. $timestamp = is_numeric($value) ? (int) $value : strtotime($value);
  107. return $timestamp ? date($format, $timestamp) : '-';
  108. };
  109. $subaccountList->each(function (&$item) use ($formatTime) {
  110. $item['create_time_text'] = $formatTime($item['create_time_value'], 'Y-m-d H:i:s');
  111. $item['last_auth_date'] = $formatTime($item['last_auth_time_value'], 'Y-m-d');
  112. return $item;
  113. });
  114. // 获取分页显示
  115. $page = $subaccountList->render();
  116. // dump($subaccountList);
  117. $this->assign('game_list', $this->selfGameList);
  118. $this->assign('page', $page);
  119. $this->assign('subaccountList', $subaccountList);
  120. $this->assign('start_time', $start_time);
  121. $this->assign('end_time', $end_time);
  122. return $this->fetch();
  123. }
  124. }