model = new GameGroup(); $this->gameMainLogic = new GameMainLogic(); } /** * 读取数据 * @param $id * @return mixed */ public function read($id): mixed { $data = $this->model->where('id', $id)->find(); $game_list = explode(',', $data['game_list']); $allGameList = Db::connect('db_center')->table('pf_game')->field('id,name')->select()->toArray(); $allGameList = array_column($allGameList, 'name', 'id'); $gameList = []; foreach ($game_list as $game_id) { $gameList[] = '[' . $game_id . ']' . $allGameList[$game_id] ?? ''; } $data['game_list_str'] = $gameList; return $data; } /** * 给游戏分组用的游戏列表 * $where['game_group_id] */ public function getGameListOptionsByGroup($where) { // 获取gameGroupId, 如果存在,则返回的游戏需要加上这个分组的game_list $gameGroupId = $where['game_group_id']; // 游戏分组数据 $data = $this->model->where('1=1')->order('sort', 'desc')->order('id', 'desc')->select()->toArray(); // 已经存在分组的game_list $gameIdList = []; foreach ($data as $item) { // 传入的分组,不加入筛选去除筛选,用于编辑回显示 if($item['id']!=$gameGroupId){ $temGameListArray = explode(',', $item['game_list']); $gameIdList = array_merge($gameIdList, $temGameListArray); } } $groupWhere = []; $groupWhere[] = ['status', '=', 1]; if (!empty($gameIdList)) { $groupWhere[] = [ 'id', 'notin', implode(',', $gameIdList)]; } // 平台游戏 $pfCame = Db::connect('db_center')->table('pf_game')->where($groupWhere)->select()->toArray(); $mainGameMap = $this->gameMainLogic->getMainGameMap(); $groupedGames = []; foreach ($pfCame as $item) { $mainId = $item['main_id']; $groupedGames[$mainId]['id'] = 'main_id_'.$mainId; $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId; $groupedGames[$mainId]['children'][] = [ 'id' => $item['id'], 'name' => '['.$item['id'].']'.$item['name'] ]; } return array_values($groupedGames); } }