removed comments
This commit is contained in:
@@ -70,7 +70,7 @@ class MatchController extends Controller
|
||||
|
||||
$stakeType = CoinTransactionType::firstOrCreate(
|
||||
["name" => "Match stake"],
|
||||
["type" => "D"], // Debit
|
||||
["type" => "D"],
|
||||
);
|
||||
|
||||
$match = MatchGame::create([
|
||||
@@ -213,7 +213,7 @@ class MatchController extends Controller
|
||||
) {
|
||||
$payoutType = CoinTransactionType::firstOrCreate(
|
||||
["name" => "Match payout"],
|
||||
["type" => "C"], // Credit
|
||||
["type" => "C"],
|
||||
);
|
||||
|
||||
$totalPrize = $match->stake * 2;
|
||||
@@ -273,7 +273,7 @@ class MatchController extends Controller
|
||||
|
||||
$stakeType = CoinTransactionType::firstOrCreate(
|
||||
["name" => "Match stake"],
|
||||
["type" => "D"], // Debit
|
||||
["type" => "D"],
|
||||
);
|
||||
|
||||
$match = MatchGame::create([
|
||||
@@ -307,7 +307,7 @@ class MatchController extends Controller
|
||||
$query = MatchGame::where('status', 'Pending')
|
||||
->where(function($q) {
|
||||
$q->whereNull('player2_user_id')
|
||||
->orWhere('player2_user_id', 1); // 1 = Ghost ID
|
||||
->orWhere('player2_user_id', 1);
|
||||
});
|
||||
|
||||
if ($request->has('type')) {
|
||||
@@ -321,7 +321,6 @@ class MatchController extends Controller
|
||||
return response()->json($matches);
|
||||
}
|
||||
|
||||
// --- FIX: Safely Delete Match by removing dependencies first ---
|
||||
public function destroy(MatchGame $match)
|
||||
{
|
||||
$user = request()->user();
|
||||
@@ -335,13 +334,10 @@ class MatchController extends Controller
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($match, $user) {
|
||||
// 1. Delete associated Games first (The FK constraint cause)
|
||||
DB::table('games')->where('match_id', $match->id)->delete();
|
||||
|
||||
// 2. Unlink existing Coin Transactions (Set match_id to NULL)
|
||||
CoinTransaction::where('match_id', $match->id)->update(['match_id' => null]);
|
||||
|
||||
// 3. Process Refund
|
||||
if ($match->stake > 0) {
|
||||
$user->increment('coins_balance', $match->stake);
|
||||
|
||||
@@ -350,10 +346,9 @@ class MatchController extends Controller
|
||||
['type' => 'C']
|
||||
);
|
||||
|
||||
// Create Refund Transaction with NO LINK to the deleted match
|
||||
CoinTransaction::create([
|
||||
'user_id' => $user->id,
|
||||
'match_id' => null, // IMPORTANT: Must be null
|
||||
'match_id' => null,
|
||||
'coin_transaction_type_id' => $refundType->id,
|
||||
'transaction_datetime' => now(),
|
||||
'coins' => $match->stake,
|
||||
@@ -361,7 +356,6 @@ class MatchController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
// 4. Finally delete the match
|
||||
$match->delete();
|
||||
|
||||
return response()->json([
|
||||
|
||||
Reference in New Issue
Block a user