Version 1.0 #102

Merged
FernandoJVideira merged 163 commits from develop into master 2026-01-03 14:49:00 +00:00
3 changed files with 16 additions and 6 deletions
Showing only changes of commit 9bfa06b1ce - Show all commits
@@ -81,12 +81,15 @@ class StatisticsController extends Controller
$totalGames = Game::count(); $totalGames = Game::count();
$totalBlockedUsers = User::where('blocked', true)->count(); $totalBlockedUsers = User::where('blocked', true)->count();
// 2. Games Breakdown by Type
$gamesByType = Game::select('type', DB::raw('count(*) as total')) $gamesByType = Game::select('type', DB::raw('count(*) as total'))
->groupBy('type') ->groupBy('type')
->get(); ->get();
// 3. Games Per Month (CORRIGIDO PARA SQLITE)
// SQLite usa strftime('%Y-%m', coluna) em vez de DATE_FORMAT
$gamesPerMonth = Game::select( $gamesPerMonth = Game::select(
DB::raw('DATE_FORMAT(began_at, "%Y-%m") as month'), DB::raw("strftime('%Y-%m', began_at) as month"),
DB::raw('count(*) as total') DB::raw('count(*) as total')
) )
->whereNotNull('began_at') ->whereNotNull('began_at')
@@ -95,16 +98,17 @@ class StatisticsController extends Controller
->limit(12) ->limit(12)
->get(); ->get();
// 4. Financial/Coin Stats
$totalCoinsPurchased = CoinTransaction::whereHas('type', function($q) { $totalCoinsPurchased = \App\Models\CoinTransaction::whereHas('type', function($q) {
$q->where('name', 'Coin purchase'); $q->where('name', 'Coin purchase');
}) })
->sum('coins'); ->sum('coins');
$purchasesPerMonth = CoinTransaction::join('coin_transaction_types', 'coin_transactions.coin_transaction_type_id', '=', 'coin_transaction_types.id') // Calculate Purchases Per Month (CORRIGIDO PARA SQLITE)
$purchasesPerMonth = \App\Models\CoinTransaction::join('coin_transaction_types', 'coin_transactions.coin_transaction_type_id', '=', 'coin_transaction_types.id')
->where('coin_transaction_types.name', 'Coin purchase') ->where('coin_transaction_types.name', 'Coin purchase')
->select( ->select(
DB::raw('DATE_FORMAT(coin_transactions.transaction_datetime, "%Y-%m") as month'), DB::raw("strftime('%Y-%m', coin_transactions.transaction_datetime) as month"),
DB::raw('SUM(coin_transactions.coins) as total_coins') DB::raw('SUM(coin_transactions.coins) as total_coins')
) )
->groupBy('month') ->groupBy('month')
@@ -117,7 +121,7 @@ class StatisticsController extends Controller
'total_players' => $totalPlayers, 'total_players' => $totalPlayers,
'total_games' => $totalGames, 'total_games' => $totalGames,
'blocked_users' => $totalBlockedUsers, 'blocked_users' => $totalBlockedUsers,
'total_coins_purchased' => (int) $totalCoinsPurchased, // Cast to int 'total_coins_purchased' => (int) $totalCoinsPurchased,
], ],
'charts' => [ 'charts' => [
'games_by_type' => $gamesByType, 'games_by_type' => $gamesByType,
@@ -225,4 +225,9 @@ class UserController extends Controller
return response()->json($transactions); return response()->json($transactions);
} }
public function getMyTransactions(Request $request)
{
return $this->getTransactions($request, $request->user());
}
} }
+1
View File
@@ -30,6 +30,7 @@ Route::prefix('v1')->group(function () {
'updatePassword', 'updatePassword',
]); ]);
Route::post('/avatar', [ProfileController::class, 'uploadAvatar']); Route::post('/avatar', [ProfileController::class, 'uploadAvatar']);
Route::get('/transactions', [UserController::class, 'getMyTransactions']);
}); });
// User Resources // User Resources