JLGameConfigController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Redis;
  6. use Illuminate\Support\Facades\Config;
  7. class JLGameConfigController extends Controller
  8. {
  9. public function index()
  10. {
  11. $games = Config::get('games.gameName');
  12. $pgGames = [];
  13. foreach ($games as $gameId => $gameName) {
  14. if (substr(strval($gameId),0,2)=="91"&&$gameId!="917" ) {
  15. $config = Redis::get("GameConfig_JL_{$gameId}");
  16. $pgGames[] = [
  17. 'gameId' => $gameId,
  18. 'gameName' => $gameName,
  19. 'config' => $config ? json_decode($config, true) : null
  20. ];
  21. }
  22. }
  23. return view('admin.pg_game_config.index_jili', compact('pgGames'));
  24. }
  25. public function update(Request $request)
  26. {
  27. $gameId = $request->input('gameId');
  28. $config = $request->input('config');
  29. \Log::info('JL游戏配置更新请求', [
  30. 'gameId' => $gameId,
  31. 'config' => $config,
  32. 'all_data' => $request->all()
  33. ]);
  34. if (!$gameId || !$config) {
  35. \Log::error('JL游戏配置更新失败:参数错误');
  36. return response()->json(['status' => 'error', 'message' => '参数错误']);
  37. }
  38. try {
  39. $configData = json_decode($config, true);
  40. if (json_last_error() !== JSON_ERROR_NONE) {
  41. \Log::error('JL游戏配置更新失败:JSON格式错误', ['error' => json_last_error_msg()]);
  42. throw new \Exception('JSON格式错误: ' . json_last_error_msg());
  43. }
  44. Redis::set("GameConfig_JL_{$gameId}", $config);
  45. \Log::info('JL游戏配置更新成功', ['gameId' => $gameId]);
  46. return response()->json(['status' => 'success', 'message' => '更新成功']);
  47. } catch (\Exception $e) {
  48. \Log::error('JL游戏配置更新失败:异常', ['message' => $e->getMessage()]);
  49. return response()->json(['status' => 'error', 'message' => $e->getMessage()]);
  50. }
  51. }
  52. public function copyAll(Request $request)
  53. {
  54. $sourceGameId = (int) $request->input('gameId');
  55. $config = $request->input('config');
  56. \Log::info('JL游戏配置复制到所有游戏请求', [
  57. 'sourceGameId' => $sourceGameId,
  58. 'has_config' => $config !== null,
  59. ]);
  60. if (!$sourceGameId) {
  61. return response()->json(['status' => 'error', 'message' => '缺少gameId']);
  62. }
  63. try {
  64. if ($config) {
  65. $configData = json_decode($config, true);
  66. if (json_last_error() !== JSON_ERROR_NONE) {
  67. throw new \Exception('JSON格式错误: ' . json_last_error_msg());
  68. }
  69. } else {
  70. $raw = Redis::get("GameConfig_JL_{$sourceGameId}");
  71. if (!$raw) {
  72. throw new \Exception('源游戏未找到配置');
  73. }
  74. $configData = json_decode($raw, true);
  75. if (json_last_error() !== JSON_ERROR_NONE) {
  76. throw new \Exception('源配置JSON格式错误: ' . json_last_error_msg());
  77. }
  78. }
  79. $games = Config::get('games.gameName');
  80. $affected = 0;
  81. foreach ($games as $gameId => $gameName) {
  82. if ($gameId > 9000 && (int)$gameId !== $sourceGameId) {
  83. Redis::set("GameConfig_JL_{$gameId}", json_encode($configData, JSON_UNESCAPED_UNICODE));
  84. $affected++;
  85. }
  86. }
  87. \Log::info('JL游戏配置复制完成', ['source' => $sourceGameId, 'affected' => $affected]);
  88. return response()->json(['status' => 'success', 'message' => '复制成功', 'affected' => $affected]);
  89. } catch (\Exception $e) {
  90. \Log::error('JL游戏配置复制失败', ['message' => $e->getMessage()]);
  91. return response()->json(['status' => 'error', 'message' => $e->getMessage()]);
  92. }
  93. }
  94. }