model = new GameGroup(); } /** * 读取列表 */ public function getList($query): mixed { $page = request()->input('page') ? request()->input('page') : 1; $limit = request()->input('limit') ? request()->input('limit') : 10; $list = $this->model->order('sort', 'desc')->paginate($limit, false, ['page' => $page])->toArray(); $gameList = Db::connect('db_center')->table('pf_game')->column('name', 'id'); foreach ($gameList as $id => &$name) { $name = '[' . $id . ']' . $name; } foreach ($list['data'] as $key => $value) { $gameIds = explode(',', $value['game_list']); foreach ($gameIds as $i => $gameId) { $list['data'][$key]['children'][] = [ 'hideOperation'=>true, 'name' => $gameList[$gameId], ]; } } $total = $this->model->count(); $last_page = ceil($total/$limit); $startIndex = ($page - 1) * $limit; $pageData = array_slice($list['data'], $startIndex, $limit); return [ 'data' => $pageData, 'current_page' => $page, 'per_page' => $limit, 'last_page' => $last_page, 'total' => $total, ]; // return $this->model->order('sort', 'desc')->paginate($limit, false, ['page' => $page])->toArray(); } /** * 读取数据 * @param $id * @return mixed */ public function read($id): mixed { $data = $this->model->where('id', $id)->find(); $gameIds = explode(',', $data['game_list']); $gameList = Db::connect('db_center')->table('pf_game')->where("id", 'in', $gameIds)->column('name', 'id'); foreach ($gameList as $id => &$name) { $name = '[' . $id . ']' . $name; } $data['game_list_str'] = $gameList; return $data; } /** * 给游戏分组用的游戏列表,主要作用,返回可选或者可编辑的游戏列表 * $where['game_group_id] */ public function getGameListOptionsByGroup($where): array { // Todo 获取非自己的已选中 $gameGroupId = $where['game_group_id']; $data = $this->model->where('id', '<>', $gameGroupId)->column("game_list"); $gameIdList = []; foreach ($data as $gameIds) { $gameIds = explode(',', $gameIds); $gameIdList = array_merge($gameIdList, $gameIds); } // Todo 获取游戏分组 $groupWhere = [ 'status'=>1 ]; if (!empty($gameIdList)) { $groupWhere[] = [ 'id', 'notin', implode(',', $gameIdList)]; } // 平台游戏 $pfCame = Db::connect('db_center')->table('pf_game')->where($groupWhere)->select()->toArray(); return (new GameLogic())->gameMainTree($pfCame); } /** * 获取游戏根据部门ID, 返回根据分组后的游戏列表 */ public function getGameListOptionsByDeptId($where): array { $deptId = $where['dept_id']; // 1. 根据部门ID获取游戏列表 $deptGameList = Db::connect('db_system') ->table('sa_system_dept') ->field('game_list') ->where('id', $deptId) ->select()->toArray(); $deptGameList = $deptGameList[0]['game_list']; // 2. 所有游戏信息列表 $pfGameList = Db::connect('db_center') ->table('pf_game') ->field('id,name') ->select()->toArray(); $pfGameList = array_column($pfGameList, null, 'id'); // 3. 分组列表 $groupList = Db::connect('db_center') ->table('game_group') ->select()->toArray(); if(!empty($deptGameList)){ // 返回分组所有游戏 if($deptGameList == '*'){ foreach($groupList as &$group){ $group['id'] = 'group_'.$group['id']; $gameList = explode(',', $group['game_list']); foreach($gameList as $gameId){ $group['children'][] = [ 'id' => $pfGameList[$gameId]['id'], 'name' => '['.$pfGameList[$gameId]['id'].']'.$pfGameList[$gameId]['name'] ]; } } $gameList = $groupList; }else{ // 根据权限 4,5,7 // $deptGameList = 4,5,7 // $group['game_list'] 取交集 $deptGameList = explode(',', $deptGameList); foreach($groupList as &$group){ $group['id'] = 'group_'.$group['id']; $gameList = explode(',', $group['game_list']); $group['game_list'] = array_intersect($deptGameList, $gameList); foreach($group['game_list'] as $gameId){ $group['children'][] = [ 'id' => $pfGameList[$gameId]['id'], 'name' => '['.$pfGameList[$gameId]['id'].']'.$pfGameList[$gameId]['name'] ]; } } $groupList = array_filter($groupList, function($group){ return !empty($group['game_list']); }); $gameList = $groupList; } }else{ $gameList = []; } return $gameList; } }