webgame.games.brand 中对应的取值。 * 取值与 webgame.games.brand 实际存储一致;如后续新增厂商在此追加即可。 */ private static $brandGroups = [ 'PGSoft' => ['PGSoft'], 'JILI' => ['JILI'], 'PragmaticPlay' => ['PP'], 'IGT' => ['IGT'], 'Hacksaw' => ['Hacksaw'], ]; /** * 个控回报配置列表(可编辑) */ public function index(Request $request) { // 获取游戏ID,默认为0(通用配置) $gameId = (int)$request->input('game_id', 0); // 获取库存模式,默认为1(普通模式) $stockMode = (int)$request->input('stock_mode', 1); if (!in_array($stockMode, [1, 2])) { $stockMode = 1; } // 按品牌分组的开放游戏列表 $groupedGames = $this->getOpenGamesGroupedByBrand(); $games = [0 => '通用配置']; foreach ($groupedGames as $brandGames) { foreach ($brandGames as $game) { $games[$game['id']] = $game['name']; } } if (!array_key_exists($gameId, $games)) { $gameId = 0; } // 查询指定GameID和StockMode的配置 $configs = DB::connection('write') ->table(self::CONFIG_TABLE) ->where('GameID', $gameId) ->where('StockMode', $stockMode) ->orderBy('ZMin', 'asc') ->orderBy('ZMax', 'asc') ->orderBy('MultiMin', 'asc') ->get(); return view('admin.game_some_config.index', compact('configs', 'games', 'groupedGames', 'gameId', 'stockMode')); } /** * 批量更新配置(只更新有变动的数据) */ public function update(Request $request) { $db = DB::connection('write'); try { $configs = $request->input('configs', []); if (empty($configs)) { return apiReturnFail('没有需要更新的数据'); } $db->beginTransaction(); $updatedIds = []; $updatedCount = 0; foreach ($configs as $configId => $data) { // 构建更新数据(只包含提交的字段) $updateData = []; if (isset($data['ZMin'])) { $updateData['ZMin'] = (int)$data['ZMin']; } if (isset($data['ZMax'])) { $updateData['ZMax'] = (int)$data['ZMax']; } if (isset($data['MultiMin'])) { $updateData['MultiMin'] = round((float)$data['MultiMin'], 2); } if (isset($data['MultiMax'])) { $updateData['MultiMax'] = round((float)$data['MultiMax'], 2); } // if (isset($data['MultiAvg'])) { // $updateData['MultiAvg'] = round((float)$data['MultiAvg'], 2); // } if (isset($data['Weight'])) { $updateData['Weight'] = (int)$data['Weight']; } // 个控调节支持配置为空(使用 array_key_exists 以支持空字符串) if (array_key_exists('WeightAdjust', $data)) { $updateData['WeightAdjust'] = (string)($data['WeightAdjust'] ?? ''); } // Status字段不允许修改,已移除 // 只有有数据时才更新 if (!empty($updateData)) { $db->table(self::CONFIG_TABLE) ->where('ConfigID', $configId) ->update($updateData); $updatedIds[] = $configId; $updatedCount++; } } $db->commit(); \Log::info('个控回报配置更新成功', [ 'admin_id' => $request->session()->get('admin')->id ?? 0, 'updated_count' => $updatedCount, 'config_ids' => $updatedIds ]); return apiReturnSuc("配置更新成功,共更新 {$updatedCount} 条数据"); } catch (\Exception $e) { try { $db->rollBack(); } catch (\Exception $rollbackException) { } \Log::error('个控回报配置更新失败', [ 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return apiReturnFail('更新失败: ' . $e->getMessage()); } } /** * 将通用配置复制到选中的开放游戏。 */ public function copyCommon(Request $request) { $db = DB::connection('write'); try { $stockMode = (int)$request->input('stock_mode', 1); if (!in_array($stockMode, [1, 2])) { return apiReturnFail('库存模式参数错误'); } $gameIds = $request->input('game_ids', []); if (!is_array($gameIds)) { $gameIds = explode(',', (string)$gameIds); } $openGameIds = $this->getOpenGameIds(); $targetGameIds = []; foreach ($gameIds as $gameId) { $gameId = (int)$gameId; if ($gameId > 0 && in_array($gameId, $openGameIds)) { $targetGameIds[$gameId] = $gameId; } } $targetGameIds = array_values($targetGameIds); if (empty($targetGameIds)) { return apiReturnFail('请先选择要复制到的游戏'); } $commonConfigs = $db->table(self::CONFIG_TABLE) ->where('GameID', 0) ->where('StockMode', $stockMode) ->orderBy('ZMin', 'asc') ->orderBy('ZMax', 'asc') ->orderBy('MultiMin', 'asc') ->get(); if ($commonConfigs->isEmpty()) { return apiReturnFail('通用配置暂无数据,无法复制'); } $db->beginTransaction(); $insertedCount = 0; foreach ($targetGameIds as $targetGameId) { $db->table(self::CONFIG_TABLE) ->where('GameID', $targetGameId) ->where('StockMode', $stockMode) ->delete(); $rows = []; foreach ($commonConfigs as $config) { $row = (array)$config; unset($row['ConfigID']); $row['GameID'] = $targetGameId; $row['StockMode'] = $stockMode; $rows[] = $row; } if (!empty($rows)) { foreach (array_chunk($rows, 100) as $chunk) { $db->table(self::CONFIG_TABLE)->insert($chunk); } $insertedCount += count($rows); } } $db->commit(); \Log::info('通用个控回报配置复制成功', [ 'admin_id' => $request->session()->get('admin')->id ?? 0, 'stock_mode' => $stockMode, 'target_game_ids' => $targetGameIds, 'inserted_count' => $insertedCount, ]); return apiReturnSuc([ 'affected_games' => count($targetGameIds), 'inserted_count' => $insertedCount, ], '', '复制成功'); } catch (\Exception $e) { try { $db->rollBack(); } catch (\Exception $rollbackException) { } \Log::error('通用个控回报配置复制失败', [ 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); return apiReturnFail('复制失败: ' . $e->getMessage()); } } /** * 获取开放游戏并按品牌分类。 * * 数据来源与 /admin/game_site/builder 游戏卡片编辑一致:直接读取 webgame.games, * 以 state>0 判定为开放游戏,按真实 brand 字段归类。 * GameSomeConfig.GameID 对应 webgame.games.com_gameId(统一内部gameid), * 因此仅纳入 com_gameId>0 的游戏。 */ private function getOpenGamesGroupedByBrand() { // 收集目标品牌的所有 brand 取值,并建立 brand 取值 => 展示名 的映射 $brandValues = []; $brandLabelMap = []; foreach (self::$brandGroups as $label => $values) { foreach ($values as $value) { $brandValues[] = $value; $brandLabelMap[strtolower($value)] = $label; } } $rows = DB::connection('mysql') ->table(self::GAME_TABLE) ->select('com_gameId', 'title', 'brand') ->where('state', '>', 0) ->where('com_gameId', '>', 0) ->whereIn('brand', $brandValues) ->orderBy('brand', 'asc') ->orderBy('title', 'asc') ->get(); $groups = []; $seen = []; foreach ($rows as $row) { $gameId = (int)$row->com_gameId; if ($gameId <= 0 || isset($seen[$gameId])) { continue; } $seen[$gameId] = true; $label = $brandLabelMap[strtolower((string)$row->brand)] ?? (string)$row->brand; if (!isset($groups[$label])) { $groups[$label] = []; } $groups[$label][] = [ 'id' => $gameId, 'name' => ($row->title !== null && $row->title !== '') ? $row->title : ('Game ' . $gameId), ]; } // 按 $brandGroups 定义的厂商顺序输出 $orderedGroups = []; foreach (array_keys(self::$brandGroups) as $label) { if (!empty($groups[$label])) { $orderedGroups[$label] = $groups[$label]; unset($groups[$label]); } } foreach ($groups as $label => $games) { $orderedGroups[$label] = $games; } return $orderedGroups; } /** * 获取所有开放游戏的 GameID 列表(用于复制通用配置时校验目标游戏)。 */ private function getOpenGameIds() { $ids = []; foreach ($this->getOpenGamesGroupedByBrand() as $games) { foreach ($games as $game) { $gameId = (int)$game['id']; if ($gameId > 0) { $ids[$gameId] = $gameId; } } } return array_values($ids); } }