download odds
This commit is contained in:
1 parent
b60e7c2f99
commit
483b5e1abe
5 files changed
+347
-2
No files matched your search
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
|
||||
class OddsExporter implements FromArray, WithHeadings
|
||||
{
|
||||
protected array $data;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
// Übergibt die flachen Zeilendaten an Excel
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
// Definiert die Kopfzeile im Excel-Sheet
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Match Id',
|
||||
'BetsApi Id',
|
||||
'Betradar Id',
|
||||
'Bet365 Id',
|
||||
'Starttime',
|
||||
'Sport Id',
|
||||
'Group Id',
|
||||
'Group',
|
||||
'Home Id',
|
||||
'Home',
|
||||
'Away Id',
|
||||
'Away',
|
||||
'Book Id',
|
||||
'Book',
|
||||
'One',
|
||||
'X',
|
||||
'Two',
|
||||
'Book Id To',
|
||||
'Book To',
|
||||
'Over',
|
||||
'Under',
|
||||
'Total',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\Event;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class MainMarketsExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = Event::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ExportColumn::make('id')
|
||||
->label('TxOdds id'),
|
||||
ExportColumn::make('betsapi_id'),
|
||||
ExportColumn::make('betradar_id'),
|
||||
ExportColumn::make('bet365_id'),
|
||||
ExportColumn::make('starttime'),
|
||||
ExportColumn::make('sport_id'),
|
||||
ExportColumn::make('country_id'),
|
||||
ExportColumn::make('country.name'),
|
||||
ExportColumn::make('competition_group_id')
|
||||
->label('Group id'),
|
||||
ExportColumn::make('competition_group.name')
|
||||
->label('Group'),
|
||||
ExportColumn::make('home_id'),
|
||||
ExportColumn::make('home.name'),
|
||||
ExportColumn::make('away_id'),
|
||||
ExportColumn::make('away.name'),
|
||||
ExportColumn::make('odds_3ways.bookmaker_id'),
|
||||
ExportColumn::make('odds_3ways.h3w'),
|
||||
ExportColumn::make('odds_3ways.h3w')
|
||||
->label('1'),
|
||||
ExportColumn::make('odds_3ways.d3w')
|
||||
->label('X'),
|
||||
ExportColumn::make('odds_3ways.a3w')
|
||||
->label('2'),
|
||||
ExportColumn::make('odds_totals.over')
|
||||
->label('Over'),
|
||||
ExportColumn::make('odds_totals.under')
|
||||
->label('Under'),
|
||||
ExportColumn::make('odds_totals.total')
|
||||
->label('Total'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your event export has completed and '.Number::format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
|
||||
|
||||
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||
$body .= ' '.Number::format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user