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; } /** * 给游戏分组用的游戏列表 */ public function getGameListOptionsByGroup() { $data = $this->model->where('1=1')->order('sort', 'desc')->order('id', 'desc')->select()->toArray(); // 已经存在分组的game_list $gameIdList = []; foreach ($data as $item) { $temGameListArray = explode(',', $item['game_list']); $gameIdList = array_merge($gameIdList, $temGameListArray); } $where = []; $where[] = ['status', 1]; if (!empty($gameIdList)) { $where[] = ['id', 'notin', implode(',', $gameIdList)]; } $game = Db::connect('db_center')->table('pf_game')->where($where)->select()->toArray(); $mainGameMap = $this->gameMainLogic->getMainGameMap(); $groupedGames = []; foreach ($game 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); } }