| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- namespace app\admin\controller;
- use app\common\model\ComplexChannelModel;
- use app\common\model\ComplexRoleModel;
- use app\common\model\ComplexServer;
- use think\Db;
- use think\Request;
- class Complex extends Admin
- {
- protected $noCheckAuth = ['getRoleServerList'];
- protected $where = [];
- public function getWhere()
- {
- $where = [];
- $start_time = input('request.start_time');
- $end_time = input('request.end_time');
- $complex_id = input('request.complex_id');
- $game_id = input('request.game_id');
- $server_name = input('request.server_name', '');
- $role_id = input('request.role_id', '');
- $role_name = input('request.role_name', '');
- $mg_username = input('request.mg_username', '');
- $action = Request::instance()->action();
- if ($action == 'rolelist') {
- $this->validateRoleListTimeRange($start_time, $end_time);
- }
-
- //开始时间和结束时间不为空时
- if ($start_time != '' && $end_time != '') {
- $where['create_time'] = [
- ['>=', strtotime($start_time)],
- ['<=', strtotime($end_time . ' 23:59:59')],
- ];
- } //开始时间不为空时
- elseif ($start_time != '') {
- $where['create_time'] = ['>=', strtotime($start_time)];
- } //结束时间不为空时
- elseif ($end_time != '') {
- $where['create_time'] = ['<=', strtotime($end_time . ' 23:59:59')];
- }
-
- // 渠道
- if ($complex_id != '') {
- $where['complex_id'] = $complex_id;
- }
-
- // 游戏
- if ($game_id != '') {
- $where['game_id'] = $game_id;
- }
-
- // 角色ID
- if ($role_id != '') {
- $where['role_id'] = $role_id;
- }
- // 角色名
- if ($role_name != '') {
- $where['role_name'] = ['like', "%".$role_name."%"];
- }
- // ## 特殊处理 - 不同方法参数名区分
- if($action == 'rolelist'){
- $where = addPrefixToKeys($where, 'ncr.');
- // 区服名
- if ($server_name != '') {
- $where['ncr.server_id'] = $server_name;
- }
- }else{
- // 区服名
- if ($server_name != '') {
- $where['id'] = $server_name;
- }
- }
-
- // 账号
- if ($mg_username != '') {
- $where['ncm.mg_username'] = ['like', "%".$mg_username."%"];
- }
- $this->where = $where;
- $this->start_time = $start_time;
- $this->end_time = $end_time;
- }
- /**
- * 校验角色管理页的查询时间。
- */
- private function validateRoleListTimeRange($startTime, $endTime)
- {
- if ($startTime !== '' && $endTime !== '' && strtotime($startTime) > strtotime($endTime)) {
- $this->error('查询时间:开始时间不能大于结束时间');
- }
- $today = strtotime(date('Y-m-d'));
- if ($startTime !== '' && strtotime($startTime) > $today) {
- $this->error('查询时间:开始时间不能大于今天');
- }
- if ($endTime !== '' && strtotime($endTime) > $today) {
- $this->error('查询时间:结束时间不能大于今天');
- }
- }
-
- // 区服管理
- public function serverList(){
- $this->getWhere();
- $param = input('get.');
- $gameList = model('Common/Game')->getAllByCondition('id,name',[],'','self');
- $channelList = (new ComplexChannelModel())->getAllByCondition('id,name', [],'name asc');
- $serverList = Db::table('nw_complex_server')->field('id,server_name as name')->select();
- $gameByIdList = array_column($gameList, 'name', 'id');
- $channelByIdList = array_column($channelList, 'name', 'id');
- $serverByIdList = array_column($serverList, 'name', 'id');
- // 游戏上线状态
- $cooperation_status = $this->request->param('cooperation_status', 0, 'intval'); // 游戏上线状态
- if(!empty($cooperation_status)){
- $game_cooperation_status = $cooperation_status==1?1:2;
- $gameIds = Model('Game')->getNormalByIds($game_cooperation_status);
- $this->where['game_id'] = ['in', $gameIds];
- }
- $list = ComplexServer::where($this->where)->order('id desc')
- ->paginate(20, false, array('query' => $param));
-
- $this->assign('list', $list);
- $this->assign('total', $list->total());
- $this->assign('page', $list->render());
-
- $this->assign('start_time', $this->start_time);
- $this->assign('end_time', $this->end_time);
-
- $this->assign('game_list', $gameList);
- $this->assign('channel_list', $channelList);
- $this->assign('serverList', $serverList);
-
- $this->assign('game_by_id_list', $gameByIdList);
- $this->assign('channel_by_id_list', $channelByIdList);
- $this->assign('serverByIdList', $serverByIdList);
- return $this->fetch();
- }
-
- // 角色管理
- public function roleList(){
- $this->getWhere();
- $gameList = model('Common/Game')->getAllByCondition('id,name',[],'','self');
- $complexList = (new ComplexChannelModel())->getAllByCondition('id,name',['flag'=>4],'name asc');
- $gameId = input('request.game_id', 0, 'intval');
- $complexId = input('request.complex_id', 0, 'intval');
- $serverList = $this->getRoleServerOptions($gameId, $complexId);
- $gameByIdList = array_column($gameList, 'name', 'id');
- $complexByIdList = array_column($complexList, 'name', 'id');
- // 游戏上线状态
- $cooperation_status = $this->request->param('cooperation_status', 0, 'intval'); // 游戏上线状态
- if(!empty($cooperation_status)){
- $game_cooperation_status = $cooperation_status==1?1:2;
- $gameIds = Model('Game')->getNormalByIds($game_cooperation_status);
- $this->where['ncr.game_id'] = ['in', $gameIds];
- }
- $param = input('get.');
- $list = ComplexRoleModel::alias('ncr')->field('ncr.*, ncm.mg_username')
- ->join('nw_complex_members ncm','ncr.member_id=ncm.id', 'left')
- ->where($this->where)->order('ncr.id desc')
- ->paginate(20, false, array('query' => $param));
-
- $roleList = $list->toArray()['data'];
- $serverIds = array_unique(array_column($roleList, 'server_id'));
- $complexServerIdById = [];
- $serverByIdList = [];
- if (!empty($serverIds)) {
- $complexServerList = Db::table('nw_complex_server')
- ->where('id', 'in', $serverIds)
- ->field('id,server_id,server_name')
- ->select();
- $complexServerIdById = array_column($complexServerList, 'server_id', 'id');
- $serverByIdList = array_column($complexServerList, 'server_name', 'id');
- }
- foreach ($roleList as $k => &$v) {
- $v['server_name'] = $serverByIdList[$v['server_id']] ?? '';
- $v['complex_server_id'] = $complexServerIdById[$v['server_id']] ?? '';
- $v['complex_name'] = $complexByIdList[$v['complex_id']] ?? '';
- }
-
- $this->assign('list', $roleList);
- $this->assign('total', $list->total());
- $this->assign('page', $list->render());
-
- $this->assign('start_time', $this->start_time);
- $this->assign('end_time', $this->end_time);
-
- // ## 数据列表
- $this->assign('gameList', $gameList);
- $this->assign('complexList', $complexList);
- $this->assign('serverList', $serverList);
-
- // ## 格式化数据列表
- $this->assign('gameByIdList', $gameByIdList);
- $this->assign('complexByIdList', $complexByIdList);
- return $this->fetch();
- }
- /**
- * 根据渠道和游戏获取角色管理页的区服选项。
- */
- public function getRoleServerList()
- {
- $gameId = input('get.game_id', 0, 'intval');
- $complexId = input('get.complex_id', 0, 'intval');
- $this->success('', '', $this->getRoleServerOptions($gameId, $complexId));
- }
- /**
- * 查询指定渠道、游戏的区服,任一条件未选择时不返回数据。
- */
- private function getRoleServerOptions($gameId, $complexId)
- {
- $gameId = intval($gameId);
- $complexId = intval($complexId);
- if ($gameId <= 0 || $complexId <= 0) {
- return [];
- }
- return Db::table('nw_complex_server')
- ->cache('complexRole:serverList:' . $complexId . ':' . $gameId, 60)
- ->where(['game_id' => $gameId, 'complex_id' => $complexId])
- ->field('id,game_id,server_id,complex_id,server_name as name')
- ->order('id desc')
- ->select();
- }
- }
|