Complex.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\ComplexChannelModel;
  4. use app\common\model\ComplexRoleModel;
  5. use app\common\model\ComplexServer;
  6. use think\Db;
  7. use think\Request;
  8. class Complex extends Admin
  9. {
  10. protected $noCheckAuth = ['getRoleServerList'];
  11. protected $where = [];
  12. public function getWhere()
  13. {
  14. $where = [];
  15. $start_time = input('request.start_time');
  16. $end_time = input('request.end_time');
  17. $complex_id = input('request.complex_id');
  18. $game_id = input('request.game_id');
  19. $server_name = input('request.server_name', '');
  20. $role_id = input('request.role_id', '');
  21. $role_name = input('request.role_name', '');
  22. $mg_username = input('request.mg_username', '');
  23. $action = Request::instance()->action();
  24. if ($action == 'rolelist') {
  25. $this->validateRoleListTimeRange($start_time, $end_time);
  26. }
  27. //开始时间和结束时间不为空时
  28. if ($start_time != '' && $end_time != '') {
  29. $where['create_time'] = [
  30. ['>=', strtotime($start_time)],
  31. ['<=', strtotime($end_time . ' 23:59:59')],
  32. ];
  33. } //开始时间不为空时
  34. elseif ($start_time != '') {
  35. $where['create_time'] = ['>=', strtotime($start_time)];
  36. } //结束时间不为空时
  37. elseif ($end_time != '') {
  38. $where['create_time'] = ['<=', strtotime($end_time . ' 23:59:59')];
  39. }
  40. // 渠道
  41. if ($complex_id != '') {
  42. $where['complex_id'] = $complex_id;
  43. }
  44. // 游戏
  45. if ($game_id != '') {
  46. $where['game_id'] = $game_id;
  47. }
  48. // 角色ID
  49. if ($role_id != '') {
  50. $where['role_id'] = $role_id;
  51. }
  52. // 角色名
  53. if ($role_name != '') {
  54. $where['role_name'] = ['like', "%".$role_name."%"];
  55. }
  56. // ## 特殊处理 - 不同方法参数名区分
  57. if($action == 'rolelist'){
  58. $where = addPrefixToKeys($where, 'ncr.');
  59. // 区服名
  60. if ($server_name != '') {
  61. $where['ncr.server_id'] = $server_name;
  62. }
  63. }else{
  64. // 区服名
  65. if ($server_name != '') {
  66. $where['id'] = $server_name;
  67. }
  68. }
  69. // 账号
  70. if ($mg_username != '') {
  71. $where['ncm.mg_username'] = ['like', "%".$mg_username."%"];
  72. }
  73. $this->where = $where;
  74. $this->start_time = $start_time;
  75. $this->end_time = $end_time;
  76. }
  77. /**
  78. * 校验角色管理页的查询时间。
  79. */
  80. private function validateRoleListTimeRange($startTime, $endTime)
  81. {
  82. if ($startTime !== '' && $endTime !== '' && strtotime($startTime) > strtotime($endTime)) {
  83. $this->error('查询时间:开始时间不能大于结束时间');
  84. }
  85. $today = strtotime(date('Y-m-d'));
  86. if ($startTime !== '' && strtotime($startTime) > $today) {
  87. $this->error('查询时间:开始时间不能大于今天');
  88. }
  89. if ($endTime !== '' && strtotime($endTime) > $today) {
  90. $this->error('查询时间:结束时间不能大于今天');
  91. }
  92. }
  93. // 区服管理
  94. public function serverList(){
  95. $this->getWhere();
  96. $param = input('get.');
  97. $gameList = model('Common/Game')->getAllByCondition('id,name',[],'','self');
  98. $channelList = (new ComplexChannelModel())->getAllByCondition('id,name', [],'name asc');
  99. $serverList = Db::table('nw_complex_server')->field('id,server_name as name')->select();
  100. $gameByIdList = array_column($gameList, 'name', 'id');
  101. $channelByIdList = array_column($channelList, 'name', 'id');
  102. $serverByIdList = array_column($serverList, 'name', 'id');
  103. // 游戏上线状态
  104. $cooperation_status = $this->request->param('cooperation_status', 0, 'intval'); // 游戏上线状态
  105. if(!empty($cooperation_status)){
  106. $game_cooperation_status = $cooperation_status==1?1:2;
  107. $gameIds = Model('Game')->getNormalByIds($game_cooperation_status);
  108. $this->where['game_id'] = ['in', $gameIds];
  109. }
  110. $list = ComplexServer::where($this->where)->order('id desc')
  111. ->paginate(20, false, array('query' => $param));
  112. $this->assign('list', $list);
  113. $this->assign('total', $list->total());
  114. $this->assign('page', $list->render());
  115. $this->assign('start_time', $this->start_time);
  116. $this->assign('end_time', $this->end_time);
  117. $this->assign('game_list', $gameList);
  118. $this->assign('channel_list', $channelList);
  119. $this->assign('serverList', $serverList);
  120. $this->assign('game_by_id_list', $gameByIdList);
  121. $this->assign('channel_by_id_list', $channelByIdList);
  122. $this->assign('serverByIdList', $serverByIdList);
  123. return $this->fetch();
  124. }
  125. // 角色管理
  126. public function roleList(){
  127. $this->getWhere();
  128. $gameList = model('Common/Game')->getAllByCondition('id,name',[],'','self');
  129. $complexList = (new ComplexChannelModel())->getAllByCondition('id,name',['flag'=>4],'name asc');
  130. $gameId = input('request.game_id', 0, 'intval');
  131. $complexId = input('request.complex_id', 0, 'intval');
  132. $serverList = $this->getRoleServerOptions($gameId, $complexId);
  133. $gameByIdList = array_column($gameList, 'name', 'id');
  134. $complexByIdList = array_column($complexList, 'name', 'id');
  135. // 游戏上线状态
  136. $cooperation_status = $this->request->param('cooperation_status', 0, 'intval'); // 游戏上线状态
  137. if(!empty($cooperation_status)){
  138. $game_cooperation_status = $cooperation_status==1?1:2;
  139. $gameIds = Model('Game')->getNormalByIds($game_cooperation_status);
  140. $this->where['ncr.game_id'] = ['in', $gameIds];
  141. }
  142. $param = input('get.');
  143. $list = ComplexRoleModel::alias('ncr')->field('ncr.*, ncm.mg_username')
  144. ->join('nw_complex_members ncm','ncr.member_id=ncm.id', 'left')
  145. ->where($this->where)->order('ncr.id desc')
  146. ->paginate(20, false, array('query' => $param));
  147. $roleList = $list->toArray()['data'];
  148. $serverIds = array_unique(array_column($roleList, 'server_id'));
  149. $complexServerIdById = [];
  150. $serverByIdList = [];
  151. if (!empty($serverIds)) {
  152. $complexServerList = Db::table('nw_complex_server')
  153. ->where('id', 'in', $serverIds)
  154. ->field('id,server_id,server_name')
  155. ->select();
  156. $complexServerIdById = array_column($complexServerList, 'server_id', 'id');
  157. $serverByIdList = array_column($complexServerList, 'server_name', 'id');
  158. }
  159. foreach ($roleList as $k => &$v) {
  160. $v['server_name'] = $serverByIdList[$v['server_id']] ?? '';
  161. $v['complex_server_id'] = $complexServerIdById[$v['server_id']] ?? '';
  162. $v['complex_name'] = $complexByIdList[$v['complex_id']] ?? '';
  163. }
  164. $this->assign('list', $roleList);
  165. $this->assign('total', $list->total());
  166. $this->assign('page', $list->render());
  167. $this->assign('start_time', $this->start_time);
  168. $this->assign('end_time', $this->end_time);
  169. // ## 数据列表
  170. $this->assign('gameList', $gameList);
  171. $this->assign('complexList', $complexList);
  172. $this->assign('serverList', $serverList);
  173. // ## 格式化数据列表
  174. $this->assign('gameByIdList', $gameByIdList);
  175. $this->assign('complexByIdList', $complexByIdList);
  176. return $this->fetch();
  177. }
  178. /**
  179. * 根据渠道和游戏获取角色管理页的区服选项。
  180. */
  181. public function getRoleServerList()
  182. {
  183. $gameId = input('get.game_id', 0, 'intval');
  184. $complexId = input('get.complex_id', 0, 'intval');
  185. $this->success('', '', $this->getRoleServerOptions($gameId, $complexId));
  186. }
  187. /**
  188. * 查询指定渠道、游戏的区服,任一条件未选择时不返回数据。
  189. */
  190. private function getRoleServerOptions($gameId, $complexId)
  191. {
  192. $gameId = intval($gameId);
  193. $complexId = intval($complexId);
  194. if ($gameId <= 0 || $complexId <= 0) {
  195. return [];
  196. }
  197. return Db::table('nw_complex_server')
  198. ->cache('complexRole:serverList:' . $complexId . ':' . $gameId, 60)
  199. ->where(['game_id' => $gameId, 'complex_id' => $complexId])
  200. ->field('id,game_id,server_id,complex_id,server_name as name')
  201. ->order('id desc')
  202. ->select();
  203. }
  204. }