download odds

This commit is contained in:
salam committed 2026-10-13 17:33:52 +02:00
1 parent b60e7c2f99
commit 483b5e1abe
5 files changed
+347 -2

No files matched your search

+66 -1
View File
@@ -2,10 +2,12 @@
namespace App\Providers\Filament;
use App\Exports\OddsExporter;
use App\Filament\Exports\BetfairExporter;
use App\Filament\Pages\PlayerProps;
use App\Filament\Pages\Statistic;
use App\Http\Middleware\RecordUserActivity;
use App\Models\Event;
use Awcodes\LightSwitch\Enums\Alignment;
use Awcodes\LightSwitch\LightSwitchPlugin;
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
@@ -28,10 +30,12 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Joaopaulolndev\FilamentEditProfile\FilamentEditProfilePlugin;
use Joaopaulolndev\FilamentEditProfile\Pages\EditProfilePage;
use Maatwebsite\Excel\Facades\Excel;
use Swis\Filament\Backgrounds\FilamentBackgroundsPlugin;
use Swis\Filament\Backgrounds\ImageProviders\MyImages;
@@ -50,13 +54,74 @@ class AdminPanelProvider extends PanelProvider
ExportAction::make('download_betfair')
->columnMapping(false)
->exporter(BetfairExporter::class)
->label('Download Betfair')
->label('Betfair Odds')
->visible(fn (): bool => Auth::user()->hasRole('download_betfair'))
->fileName(fn (Export $export): string => 'betfair-odds-'.date('d.m.Y-H.i')."-{$export->getKey()}")
->modifyQueryUsing(fn (Builder $query) => $query->whereHas('odds_3ways_bf')
->whereHas('odds_totals_bf')
->where('sport_id', 1))
->icon('phosphor-download'),
'export' => Action::make('bookmaker_odds_download')
->label('Bookmakers Odds')
->visible(fn (): bool => Auth::user()->hasRole('download_betfair'))
->icon('phosphor-download')
->color('success')
->action(function () {
$rows = [];
$events = Event::with(['odds_3ways', 'odds_totals', 'competition_group'])->where('starttime', '>', Carbon::now())->where('starttime', '<', Carbon::now()->addDays(15))->orderBy('starttime', 'ASC')->get();
foreach ($events as $event) {
$event->loadMissing(['odds_3ways', 'odds_totals']);
$totals = [];
foreach ($event->odds_totals as $item) {
$bkmid = $item->bookmaker_id;
$totals[$bkmid]['bookid'] = $item->bookmaker_id;
$totals[$bkmid]['book'] = $item->bookmaker->name;
$totals[$bkmid]['over'] = $item->over;
$totals[$bkmid]['under'] = $item->under;
$totals[$bkmid]['total'] = $item->total;
}
foreach ($event->odds_3ways as $item) {
$bkmid = $item->bookmaker_id;
$tmp = [];
$tmp['Match Id'] = $event->id;
$tmp['BetsApi Id'] = $event->betsapi_id;
$tmp['Betradar Id'] = $event->betradar_id;
$tmp['Bet365 Id'] = $event->bet365_id;
$tmp['Starttime'] = $event->starttime;
$tmp['Sport Id'] = $event->sport_id;
$tmp['Group Id'] = $event->competition_group_id;
$tmp['Group'] = $event->competition_group->name;
$tmp['Home Id'] = $event->home_id;
$tmp['Home'] = $event->home->name;
$tmp['Away Id'] = $event->away_id;
$tmp['Away'] = $event->away->name;
$tmp['Book Id'] = $item->bookmaker->name;
$tmp['Book'] = $bkmid;
$tmp['One'] = $item->h3w;
$tmp['X'] = $item->d3w;
$tmp['Two'] = $item->a3w;
if (isset($totals[$bkmid])) {
$tmp['Book Id To'] = $bkmid;
$tmp['Book To'] = $totals[$bkmid]['book'];
$tmp['Over'] = $totals[$bkmid]['over'];
$tmp['Under'] = $totals[$bkmid]['under'];
$tmp['Total'] = $totals[$bkmid]['total'];
}
$rows[] = $tmp;
}
}
// Triggert den direkten Browser-Download der fertigen Excel-Datei
return Excel::download(
new OddsExporter($rows),
'major-markets-'.now()->format('Y-m-d-H-i').'.xlsx'
);
}),
])
->path('')
->login()