// ========================================================================= // PLAY GAME // ========================================================================= public function playGame(Request $request) { $user = auth()->user(); if ($user->status_game == 0) { return back()->with('error', 'Mohon maaf akun anda terkunci untuk mengakses permainan. Silahkan hubungi CS.'); } $providerCode = $request->query('gg'); $gameCode = $request->query('gs'); $type = $request->query('gc'); $gameTypes = ['slot', 'SL']; if ($type === 'casino') { $gameTypes = ['casino', 'livecasino', 'LC', 'live']; } elseif ($type === 'others') { $gameTypes = ['other', 'others', 'OT', 'lottery', 'lotterys', 'LK', 'CB', 'ES']; } elseif ($type === 'sportbook') { $gameTypes = ['sportbook', 'sportbooks', 'SB', 'SPORT']; } elseif ($type === 'lottery') { $gameTypes = ['lottery', 'lotterys', 'LK']; } elseif ($type === 'poker') { $gameTypes = ['poker', 'pokers', 'PK']; } elseif ($type === 'hot') { $gameTypes = ['hot', 'hots', 'HOT']; } elseif ($type === 'fishing') { $gameTypes = ['fishing', 'fish', 'FH']; } $cekProvider = DB::table('provider_lists') ->where('provider_code', $providerCode) ->whereIn('game_type', $gameTypes) ->first(); if (!$cekProvider) { return back()->with('error', 'Provider tidak ditemukan!'); } $server = $cekProvider->product_code; $nodePlayApi = new NodePlayController(); $sgxApi = new SgxController(); // ── SERVER NXS → NodePlay ───────────────────────────────────────────── if ($server == 'nxs') { // Pindahkan saldo dari SGX ke NodePlay jika ada $sgxSaldo = $sgxApi->money_info_user($user->extplayer); $saldoSgx = (isset($sgxSaldo['status']) && $sgxSaldo['status'] == 200) ? ($sgxSaldo['data']['balance'] ?? 0) : 0; if ($saldoSgx > 0) { $sgxWithdraw = $sgxApi->user_withdraw($user->extplayer, (int) $saldoSgx); if (isset($sgxWithdraw['status']) && $sgxWithdraw['status'] == 200) { $nxsDeposit = $nodePlayApi->user_deposit($user->extplayer, (int) $saldoSgx); if (($nxsDeposit['status'] ?? '') !== 'success') { Log::critical("SALDO NYANGKUT: Extplayer {$user->extplayer} gagal deposit ke NodePlay sebesar {$saldoSgx} setelah withdraw dari SGX."); return back()->with('error', 'Terjadi kesalahan sistem saat memindahkan saldo. Saldo Anda aman, mohon hubungi CS.'); } } } // 1. Cek saldo NXS saat ini $nowBalance = $nodePlayApi->money_info_user($user->extplayer); // AUTO-CREATE jika user belum ada di NodePlay sebelum proses sinkronisasi deposit if (isset($nowBalance['status']) && $nowBalance['status'] !== 'success' && $this->isMemberNotFound($nowBalance)) { Log::warning("[GameController] MEMBER_NOT_FOUND untuk {$user->extplayer}, mencoba auto-create..."); $created = $this->ensureNodePlayUser($nodePlayApi, $user); if (!$created) { return back()->with('error', 'Gagal membuat akun game Anda. Silahkan hubungi CS.'); } // Ambil saldo ulang setelah akun berhasil dibuat & didepositkan otomatis oleh helper $nowBalance = $nodePlayApi->money_info_user($user->extplayer); } $saldoNxs = (isset($nowBalance['status']) && $nowBalance['status'] === 'success') ? (int)($nowBalance['data']['balance'] ?? 0) : 0; // 2. PENYELESAIAN BUG: Auto-Transfer sisa deposit web yang belum dipush ke game $untransferred = $user->balance - $saldoNxs; if ($untransferred > 0) { // Ada saldo deposit di lokal yang belum masuk ke dalam NodePlay $nxsDeposit = $nodePlayApi->user_deposit($user->extplayer, (int) $untransferred); if (isset($nxsDeposit['status']) && $nxsDeposit['status'] === 'success') { $saldoNxs += $untransferred; // Tambahkan saldo NXS lokal dengan deposit baru Log::info("[GameController] Auto-deposit sisa saldo deposit web ke NXS: {$untransferred}"); } else { return back()->with('error', 'Gagal memproses saldo deposit Anda ke dalam game.'); } } // 3. Sinkronisasi balance terbaru ke database (sekarang aman, tidak akan menimpa deposit baru) $user->update(['balance' => $saldoNxs]); // 4. Launch game $gameType = $this->mapGameType($type); $launchGame = $nodePlayApi->game_launch( $user->extplayer, $providerCode, $gameCode, $gameType ); Log::info("[GameController] game_launch response: " . json_encode($launchGame)); if (isset($launchGame['status']) && $launchGame['status'] == 1 && !empty($launchGame['launch_url'])) { return redirect($launchGame['launch_url']); } return back()->with('error', $launchGame['msg'] ?? 'Gagal meluncurkan game NodePlay.'); // ── SERVER SGX ──────────────────────────────────────────────────────── } elseif ($server == 'sgx') { // Pindahkan saldo dari NodePlay ke SGX jika ada $nxsSaldo = $nodePlayApi->money_info_user($user->extplayer); $saldoNxs = (isset($nxsSaldo['status']) && $nxsSaldo['status'] === 'success') ? ($nxsSaldo['data']['balance'] ?? 0) : 0; if ($saldoNxs > 0) { $nxsWithdraw = $nodePlayApi->user_withdraw($user->extplayer, (int) $saldoNxs); if (($nxsWithdraw['status'] ?? '') === 'success') { $sgxDeposit = $sgxApi->user_deposit($user->extplayer, (int) $saldoNxs); if (!isset($sgxDeposit['status']) || $sgxDeposit['status'] != 200) { Log::critical("SALDO NYANGKUT: Extplayer {$user->extplayer} gagal deposit ke SGX sebesar {$saldoNxs} setelah withdraw dari NodePlay."); return back()->with('error', 'Terjadi kesalahan sistem saat memindahkan saldo. Saldo Anda aman, mohon hubungi CS.'); } } } $nowBalance = $sgxApi->money_info_user($user->extplayer); $saldoSgx = (isset($nowBalance['status']) && $nowBalance['status'] == 200) ? (int)($nowBalance['data']['balance'] ?? 0) : 0; // PENYELESAIAN BUG: Auto-deposit web balance ke SGX $untransferred = $user->balance - $saldoSgx; if ($untransferred > 0) { $sgxDeposit = $sgxApi->user_deposit($user->extplayer, (int) $untransferred); if (isset($sgxDeposit['status']) && $sgxDeposit['status'] == 200) { $saldoSgx += $untransferred; Log::info("[GameController] Auto-deposit sisa saldo deposit web ke SGX: {$untransferred}"); } else { return back()->with('error', 'Gagal memproses saldo deposit Anda ke dalam game SGX.'); } } $user->update(['balance' => $saldoSgx]); $launchGame = $sgxApi->game_launch($user->extplayer, $providerCode, (int) $gameCode); if (isset($launchGame['status']) && $launchGame['status'] == 200 && !empty($launchGame['launch_url'])) { return redirect($launchGame['launch_url']); } return back()->with('error', $launchGame['message'] ?? 'Gagal meluncurkan game SGX.'); } else { return back()->with('error', 'Server tidak valid.'); } }// ========================================================================= // PLAY GAME // ========================================================================= public function playGame(Request $request) { $user = auth()->user(); if ($user->status_game == 0) { return back()->with('error', 'Mohon maaf akun anda terkunci untuk mengakses permainan. Silahkan hubungi CS.'); } $providerCode = $request->query('gg'); $gameCode = $request->query('gs'); $type = $request->query('gc'); $gameTypes = ['slot', 'SL']; if ($type === 'casino') { $gameTypes = ['casino', 'livecasino', 'LC', 'live']; } elseif ($type === 'others') { $gameTypes = ['other', 'others', 'OT', 'lottery', 'lotterys', 'LK', 'CB', 'ES']; } elseif ($type === 'sportbook') { $gameTypes = ['sportbook', 'sportbooks', 'SB', 'SPORT']; } elseif ($type === 'lottery') { $gameTypes = ['lottery', 'lotterys', 'LK']; } elseif ($type === 'poker') { $gameTypes = ['poker', 'pokers', 'PK']; } elseif ($type === 'hot') { $gameTypes = ['hot', 'hots', 'HOT']; } elseif ($type === 'fishing') { $gameTypes = ['fishing', 'fish', 'FH']; } $cekProvider = DB::table('provider_lists') ->where('provider_code', $providerCode) ->whereIn('game_type', $gameTypes) ->first(); if (!$cekProvider) { return back()->with('error', 'Provider tidak ditemukan!'); } $server = $cekProvider->product_code; $nodePlayApi = new NodePlayController(); $sgxApi = new SgxController(); // ── SERVER NXS → NodePlay ───────────────────────────────────────────── if ($server == 'nxs') { // Pindahkan saldo dari SGX ke NodePlay jika ada $sgxSaldo = $sgxApi->money_info_user($user->extplayer); $saldoSgx = (isset($sgxSaldo['status']) && $sgxSaldo['status'] == 200) ? ($sgxSaldo['data']['balance'] ?? 0) : 0; if ($saldoSgx > 0) { $sgxWithdraw = $sgxApi->user_withdraw($user->extplayer, (int) $saldoSgx); if (isset($sgxWithdraw['status']) && $sgxWithdraw['status'] == 200) { $nxsDeposit = $nodePlayApi->user_deposit($user->extplayer, (int) $saldoSgx); if (($nxsDeposit['status'] ?? '') !== 'success') { Log::critical("SALDO NYANGKUT: Extplayer {$user->extplayer} gagal deposit ke NodePlay sebesar {$saldoSgx} setelah withdraw dari SGX."); return back()->with('error', 'Terjadi kesalahan sistem saat memindahkan saldo. Saldo Anda aman, mohon hubungi CS.'); } } } // 1. Cek saldo NXS saat ini $nowBalance = $nodePlayApi->money_info_user($user->extplayer); // AUTO-CREATE jika user belum ada di NodePlay sebelum proses sinkronisasi deposit if (isset($nowBalance['status']) && $nowBalance['status'] !== 'success' && $this->isMemberNotFound($nowBalance)) { Log::warning("[GameController] MEMBER_NOT_FOUND untuk {$user->extplayer}, mencoba auto-create..."); $created = $this->ensureNodePlayUser($nodePlayApi, $user); if (!$created) { return back()->with('error', 'Gagal membuat akun game Anda. Silahkan hubungi CS.'); } // Ambil saldo ulang setelah akun berhasil dibuat & didepositkan otomatis oleh helper $nowBalance = $nodePlayApi->money_info_user($user->extplayer); } $saldoNxs = (isset($nowBalance['status']) && $nowBalance['status'] === 'success') ? (int)($nowBalance['data']['balance'] ?? 0) : 0; // 2. PENYELESAIAN BUG: Auto-Transfer sisa deposit web yang belum dipush ke game $untransferred = $user->balance - $saldoNxs; if ($untransferred > 0) { // Ada saldo deposit di lokal yang belum masuk ke dalam NodePlay $nxsDeposit = $nodePlayApi->user_deposit($user->extplayer, (int) $untransferred); if (isset($nxsDeposit['status']) && $nxsDeposit['status'] === 'success') { $saldoNxs += $untransferred; // Tambahkan saldo NXS lokal dengan deposit baru Log::info("[GameController] Auto-deposit sisa saldo deposit web ke NXS: {$untransferred}"); } else { return back()->with('error', 'Gagal memproses saldo deposit Anda ke dalam game.'); } } // 3. Sinkronisasi balance terbaru ke database (sekarang aman, tidak akan menimpa deposit baru) $user->update(['balance' => $saldoNxs]); // 4. Launch game $gameType = $this->mapGameType($type); $launchGame = $nodePlayApi->game_launch( $user->extplayer, $providerCode, $gameCode, $gameType ); Log::info("[GameController] game_launch response: " . json_encode($launchGame)); if (isset($launchGame['status']) && $launchGame['status'] == 1 && !empty($launchGame['launch_url'])) { return redirect($launchGame['launch_url']); } return back()->with('error', $launchGame['msg'] ?? 'Gagal meluncurkan game NodePlay.'); // ── SERVER SGX ──────────────────────────────────────────────────────── } elseif ($server == 'sgx') { // Pindahkan saldo dari NodePlay ke SGX jika ada $nxsSaldo = $nodePlayApi->money_info_user($user->extplayer); $saldoNxs = (isset($nxsSaldo['status']) && $nxsSaldo['status'] === 'success') ? ($nxsSaldo['data']['balance'] ?? 0) : 0; if ($saldoNxs > 0) { $nxsWithdraw = $nodePlayApi->user_withdraw($user->extplayer, (int) $saldoNxs); if (($nxsWithdraw['status'] ?? '') === 'success') { $sgxDeposit = $sgxApi->user_deposit($user->extplayer, (int) $saldoNxs); if (!isset($sgxDeposit['status']) || $sgxDeposit['status'] != 200) { Log::critical("SALDO NYANGKUT: Extplayer {$user->extplayer} gagal deposit ke SGX sebesar {$saldoNxs} setelah withdraw dari NodePlay."); return back()->with('error', 'Terjadi kesalahan sistem saat memindahkan saldo. Saldo Anda aman, mohon hubungi CS.'); } } } $nowBalance = $sgxApi->money_info_user($user->extplayer); $saldoSgx = (isset($nowBalance['status']) && $nowBalance['status'] == 200) ? (int)($nowBalance['data']['balance'] ?? 0) : 0; // PENYELESAIAN BUG: Auto-deposit web balance ke SGX $untransferred = $user->balance - $saldoSgx; if ($untransferred > 0) { $sgxDeposit = $sgxApi->user_deposit($user->extplayer, (int) $untransferred); if (isset($sgxDeposit['status']) && $sgxDeposit['status'] == 200) { $saldoSgx += $untransferred; Log::info("[GameController] Auto-deposit sisa saldo deposit web ke SGX: {$untransferred}"); } else { return back()->with('error', 'Gagal memproses saldo deposit Anda ke dalam game SGX.'); } } $user->update(['balance' => $saldoSgx]); $launchGame = $sgxApi->game_launch($user->extplayer, $providerCode, (int) $gameCode); if (isset($launchGame['status']) && $launchGame['status'] == 200 && !empty($launchGame['launch_url'])) { return redirect($launchGame['launch_url']); } return back()->with('error', $launchGame['message'] ?? 'Gagal meluncurkan game SGX.'); } else { return back()->with('error', 'Server tidak valid.'); } } Cannot modify header information - headers already sent by (output started at /home/xzeafixv/mantra.cuan783.xyz/app/Http/Controllers/Frontend/GameController.php:1)