comparing bookmaker wip

This commit is contained in:
salam committed 2026-01-20 18:48:01 +01:00
1 parent de95867692
commit be80128226
11 files changed
+237 -93

No files matched your search

@@ -79,7 +79,7 @@ class GenerateDefaultSetting
Notice::note('3) comparing bookmaker', 'p'); Notice::note('3) comparing bookmaker', 'p');
} }
$bookmakers = Bookmaker::where('is_active', 1)->pluck('id')->toArray(); $bookmakers = Bookmaker::get();
$res = Client::get(); $res = Client::get();
foreach ($res as $client) { foreach ($res as $client) {
@@ -98,19 +98,32 @@ class GenerateDefaultSetting
break; break;
} }
foreach ($bookmakers as $sorting => $bookmaker_id) { $i = 0;
foreach ($bookmakers as $bookmaker) {
$is_hidden = \in_array($bookmaker_id, $in_table_bookmaker) ? 0 : 1; $i++;
$is_hidden = \in_array($bookmaker->id, $in_table_bookmaker) ? 0 : 1;
foreach ($client_bookmakers as $client_bookmaker_id) { foreach ($client_bookmakers as $client_bookmaker_id) {
if ($client_bookmaker_id != $bookmaker_id) { if ($client_bookmaker_id != $bookmaker->id) {
for ($method_id = 1; $method_id <= 4; $method_id++) { if ($bookmaker->is_active) {
ComparingBookmaker::updateOrCreate( for ($method_id = 1; $method_id <= 4; $method_id++) {
['method_id' => $method_id, 'sport_id' => $sport_id, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id], ComparingBookmaker::updateOrCreate(
['is_hidden' => $is_hidden, 'is_active' => 1, 'sorting' => $sorting] ['method_id' => $method_id, 'sport_id' => $sport_id, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker->id],
); ['is_hidden' => $is_hidden, 'is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => 110, 'sorting' => $i]
);
}
} else {
for ($method_id = 1; $method_id <= 4; $method_id++) {
ComparingBookmaker::where('method_id', $method_id)
->where('sport_id', $sport_id)
->where('bookmaker_id', $bookmaker->id)
->where('client_bookmaker_id', $client_bookmaker_id)
->delete();
}
} }
} }
} }
@@ -220,7 +220,7 @@ class EventsTable
->hiddenLabel() ->hiddenLabel()
->preload() ->preload()
->options(function () { ->options(function () {
return Sport::query()->where('is_active', 1)->pluck('name', 'id'); return Sport::getSportForClient();
}) })
->live() ->live()
->reactive() ->reactive()
@@ -0,0 +1,20 @@
<?php
namespace App\Livewire\ComparingBookmaker;
use App\Models\ComparingBookmaker;
use App\Models\User;
class LoadBookmaker
{
public static function load()
{
$user = User::find(auth()->user()->id);
return ComparingBookmaker::query()
->with('bookmaker')
->where('sport_id', $user->sport_id)
->where('client_bookmaker_id', $user->bookmaker_id)
->orderBy('sorting');
}
}
+129 -34
View File
@@ -3,24 +3,29 @@
namespace App\Livewire; namespace App\Livewire;
use App\Filament\Tables\Columns\BookmakerIcon; use App\Filament\Tables\Columns\BookmakerIcon;
use App\Livewire\ComparingBookmaker\LoadBookmaker;
use App\Models\ComparingBookmaker; use App\Models\ComparingBookmaker;
use Filament\Actions\Action; use Filament\Actions\Action;
use Filament\Actions\BulkAction; use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup; use Filament\Actions\BulkActionGroup;
use Filament\Actions\Concerns\InteractsWithActions; use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions; use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\TextInput; use Filament\Forms\Components\TextInput;
use Filament\Schemas\Concerns\InteractsWithSchemas; use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas; use Filament\Schemas\Contracts\HasSchemas;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn; use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\TextInputColumn;
use Filament\Tables\Columns\ToggleColumn; use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Concerns\InteractsWithTable; use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable; use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Enums\FiltersLayout; use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\Indicator;
use Filament\Tables\Filters\TernaryFilter; use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Livewire\Component; use Livewire\Component;
@@ -30,8 +35,6 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas
use InteractsWithSchemas; use InteractsWithSchemas;
use InteractsWithTable; use InteractsWithTable;
public $active_methode = 1;
protected $listeners = [ protected $listeners = [
'refresh' => '$refresh', 'refresh' => '$refresh',
]; ];
@@ -41,49 +44,74 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas
return $table return $table
->description('') ->description('')
->description('Bookmaker order is priority. Maximum time than can pass since last check or update. If older bookmaker will be ignored') ->description('Bookmaker order is priority. Maximum time than can pass since last check or update. If older bookmaker will be ignored')
->headerActions([
Action::make('top')
->color(fn () => $this->active_methode == 1 ? 'primary' : 'gray')
->icon('phosphor-cell-signal-full')
->action(fn () => $this->active_methode = 1)
->after(fn () => $this->dispatch('refresh')),
Action::make('middle')->action(fn () => $this->active_methode = 2)
->color(fn () => $this->active_methode == 2 ? 'primary' : 'gray')
->icon('phosphor-cell-signal-high')
->after(fn () => $this->dispatch('refresh')),
Action::make('low')->action(fn () => $this->active_methode = 3)
->color(fn () => $this->active_methode == 3 ? 'primary' : 'gray')
->icon('phosphor-cell-signal-medium')
->after(fn () => $this->dispatch('refresh')),
])
->reorderable('sorting') ->reorderable('sorting')
->reorderRecordsTriggerAction(function (Action $action) {
return $action->button();
})
->paginated(false) ->paginated(false)
->striped() ->striped()
->query(ComparingBookmaker::query() ->query(LoadBookmaker::load())
->with('bookmaker')
// ->where('is_hidden', 0)
->where('sport_id', auth()->user()->sport_id)
->where('client_bookmaker_id', auth()->user()->bookmaker_id)
->where('method_id', $this->active_methode)
->orderBy('sorting'))
->columns([ ->columns([
TextColumn::make('Position') TextColumn::make('Position')
->alignCenter() ->alignCenter()
->badge() ->badge()
->rowIndex(), ->rowIndex(),
// IconColumn::make('sport.icon') TextColumn::make('bookmaker_id')->label('Id'),
// ->label('')
// ->icon(fn ($record) => $record->sport->icon)
// ->visibleFrom('lg'),
BookmakerIcon::make('bookmaker.icon')->label('Icon'), BookmakerIcon::make('bookmaker.icon')->label('Icon'),
TextColumn::make('time_lastcheck')->label('Time Passed'), TextInputColumn::make('time_lastcheck')
TextColumn::make('margin_threshold'), ->label('Time Passed')
->prefix('Seconds:')
->rules(['required', 'max:200', 'min:100']),
TextInputColumn::make('margin_threshold')
->label('Maximum Margin')
->prefix('Threshold:')
->rules(['required', 'max:200', 'min:100']),
ToggleColumn::make('is_active'), ToggleColumn::make('is_active'),
]) ])
->filters([ ->filters([
TernaryFilter::make('is_active')->default(1)->label('Show active'), Filter::make('method_id')
->schema([
Radio::make('method_id')
->inline()
->default(1)
->label('League / Tournament Level')
->options([
1 => 'TOP',
2 => 'MIDDLE',
3 => 'LOW',
]),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['method_id'],
fn (Builder $query, $method_id): Builder => $query->where('method_id', $method_id),
);
})->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['method_id'] ?? null) {
switch ($data['method_id']) {
case 1:
$indicators[] = Indicator::make('Method: TOP');
break;
case 2:
$indicators[] = Indicator::make('Method: MIDDLE');
break;
case 3:
$indicators[] = Indicator::make('Method: LOW');
break;
}
}
return $indicators;
})->columnSpan(6),
TernaryFilter::make('is_active')
->columnSpan(2)
->default(1)
->label('Show active'),
], layout: FiltersLayout::AboveContent) ], layout: FiltersLayout::AboveContent)
->filtersFormColumns(8)
->deferFilters(false) ->deferFilters(false)
->toolbarActions([ ->toolbarActions([
BulkActionGroup::make([ BulkActionGroup::make([
@@ -99,7 +127,29 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas
} }
}) })
->form([ ->form([
TextInput::make('time_lastcheck')->hiddenLabel()->prefix('Seconds'),
TextInput::make('time_lastcheck')
->numeric()
->hiddenLabel()
->prefix('Seconds'),
]),
BulkAction::make('margin_threshold')
->label('Maximum height of marging')
->icon('phosphor-timer')
->action(function (Collection $records, array $data): void {
foreach ($records as $record) {
ComparingBookmaker::where('id', '=', $record->id)
->update(
['margin_threshold' => $data['margin_threshold']]
);
}
})
->form([
TextInput::make('margin_threshold')
->hiddenLabel()
->numeric()
->rules(['required', 'max:200', 'min:100'])
->prefix('Threshold'),
]), ]),
BulkAction::make('Switch On') BulkAction::make('Switch On')
->icon('phosphor-play') ->icon('phosphor-play')
@@ -122,6 +172,51 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas
} }
}), }),
]), ]),
])->recordActions([
Action::make('end')
->iconButton()
->icon('phosphor-arrow-fat-line-down')
->tooltip('Move to the end')
->action(function ($record) {
$res = ComparingBookmaker::where('method_id', $record->method_id)
->where('sport_id', $record->sport_id)
->where('client_bookmaker_id', $record->client_bookmaker_id)
->orderBy('sorting')
->pluck('bookmaker_id', 'id');
$sorting = 1;
foreach ($res as $id => $bookmaker_id) {
if ($bookmaker_id == $record->bookmaker_id) {
ComparingBookmaker::where('id', $id)
->update(['sorting' => \count($res)]);
} else {
ComparingBookmaker::where('id', $id)
->update(['sorting' => $sorting]);
$sorting++;
}
}
}),
Action::make('start')
->iconButton()
->icon('phosphor-arrow-fat-line-up')
->tooltip('Move to begining')
->action(function ($record) {
$res = ComparingBookmaker::where('method_id', $record->method_id)
->where('sport_id', $record->sport_id)
->where('client_bookmaker_id', $record->client_bookmaker_id)
->orderBy('sorting')
->pluck('bookmaker_id', 'id');
$sorting = 2;
foreach ($res as $id => $bookmaker_id) {
if ($bookmaker_id == $record->bookmaker_id) {
ComparingBookmaker::where('id', $id)
->update(['sorting' => 1]);
} else {
ComparingBookmaker::where('id', $id)
->update(['sorting' => $sorting]);
$sorting++;
}
}
}),
]); ]);
} }
+3 -1
View File
@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Auth;
class LoadEvents class LoadEvents
{ {
public static function load($search_left) public static function load($search_left, $sport_id)
{ {
if ($search_left) { if ($search_left) {
@@ -24,6 +24,7 @@ class LoadEvents
$query = Event::query() $query = Event::query()
->with('home') ->with('home')
->with('away') ->with('away')
->where('sport_id', $sport_id)
->where('starttime', '>', Carbon::now()) ->where('starttime', '>', Carbon::now())
->where(function ($query) use ($element_ids) { ->where(function ($query) use ($element_ids) {
$query->orWhereIn('home_id', $element_ids)->orWhereIn('away_id', $element_ids); $query->orWhereIn('home_id', $element_ids)->orWhereIn('away_id', $element_ids);
@@ -33,6 +34,7 @@ class LoadEvents
$query = Event::query() $query = Event::query()
->with('home') ->with('home')
->with('away') ->with('away')
->where('sport_id', $sport_id)
->where('betradar_id', 0) ->where('betradar_id', 0)
->where('starttime', '>', Carbon::now()); ->where('starttime', '>', Carbon::now());
} }
+25 -40
View File
@@ -42,6 +42,8 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
public $search_left = false; public $search_left = false;
public $sport_id = 0;
protected $listeners = [ protected $listeners = [
'reload_data_left' => '$refresh', 'reload_data_left' => '$refresh',
]; ];
@@ -65,8 +67,10 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
public function table(Table $table): Table public function table(Table $table): Table
{ {
$this->setSportId();
return $table return $table
->query(LoadEvents::load($this->search_left)) ->query(LoadEvents::load($this->search_left, $this->sport_id))
->columns([ ->columns([
MapperLeftColumn::make('left')->label(''), MapperLeftColumn::make('left')->label(''),
]) ])
@@ -75,44 +79,23 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
->filters([ ->filters([
Filter::make('events') Filter::make('events')
->schema([ ->schema([
Select::make(name: 'sport_id') Select::make('country_id')
->default(auth()->user()->sport_id) ->placeholder('Country')
->prefixIcon(auth()->user()->sport->icon)
->selectablePlaceholder(false)
->hiddenLabel() ->hiddenLabel()
->multiple()
->columnSpan(2) ->columnSpan(2)
->searchable()
->preload() ->preload()
->options(function () { ->options(function () {
return Sport::query()->where('is_active', 1)->pluck('name', 'id'); $res = Event::query()->where('sport_id', $this->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray();
return Country::query()->whereIn('id', $res)->pluck('name', 'id');
}) })
->live() ->live()
->reactive() ->reactive()
->afterStateUpdated(function (callable $set, $livewire) { ->afterStateUpdated(function (callable $set) {
$livewire->dispatch('reload_data_left');
$livewire->dispatch('reload_data_right');
$set('country_id', null);
$set('competition_group_id', null); $set('competition_group_id', null);
}), }),
// Select::make('country_id')
// ->placeholder('Country')
// ->hiddenLabel()
// ->multiple()
// ->columnSpan(2)
// ->searchable()
// ->preload()
// ->options(function (Get $get) {
// $res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray();
// return Country::query()->whereIn('id', $res)->pluck('name', 'id');
// })
// ->live()
// ->reactive()
// ->afterStateUpdated(function (callable $set) {
// $set('competition_group_id', null);
// }),
Select::make('competition_group_id') Select::make('competition_group_id')
->placeholder('League') ->placeholder('League')
->hiddenLabel() ->hiddenLabel()
@@ -121,11 +104,11 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
->multiple() ->multiple()
->searchable() ->searchable()
->options(function (Get $get) { ->options(function (Get $get) {
// if ($get('country_id')) { if ($get('country_id')) {
// $res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->whereIn('country_id', $get('country_id'))->groupBy('competition_group_id')->pluck('competition_group_id')->toArray(); $res = Event::query()->where('sport_id', $this->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->whereIn('country_id', $get('country_id'))->groupBy('competition_group_id')->pluck('competition_group_id')->toArray();
// } else { } else {
// } $res = Event::query()->where('sport_id', $this->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->pluck('competition_group_id')->toArray();
$res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->pluck('competition_group_id')->toArray(); }
$comps = CompetitionGroup::with('country')->whereIn('id', $res)->get(); $comps = CompetitionGroup::with('country')->whereIn('id', $res)->get();
@@ -146,11 +129,8 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
->query(function (Builder $query, array $data): Builder { ->query(function (Builder $query, array $data): Builder {
return $query return $query
->when( ->when(
$data['sport_id'], $data['country_id'],
fn (Builder $query, $sport_id) => $query->where('sport_id', $sport_id) fn (Builder $query, $country_id) => $query->where('country_id', $country_id)
// )->when(
// $data['country_id'],
// fn (Builder $query, $country_id) => $query->where('country_id', $country_id)
)->when( )->when(
$data['competition_group_id'], $data['competition_group_id'],
fn (Builder $query, $competition_group_id) => $query->whereIn('competition_group_id', $competition_group_id) fn (Builder $query, $competition_group_id) => $query->whereIn('competition_group_id', $competition_group_id)
@@ -192,6 +172,11 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
$this->elements_swopped = ! $this->elements_swopped; $this->elements_swopped = ! $this->elements_swopped;
} }
public function setSportId()
{
$this->sport_id = Sport::getSportId();
}
#[On('search_left')] #[On('search_left')]
public function searchLeft($str) public function searchLeft($str)
{ {
+12 -1
View File
@@ -2,6 +2,7 @@
namespace App\Livewire; namespace App\Livewire;
use App\Models\Sport;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Livewire\Component; use Livewire\Component;
@@ -15,14 +16,24 @@ class TopMenuItems extends Component
'reload_data_right' => '$refresh', 'reload_data_right' => '$refresh',
]; ];
protected string $sport = '';
public function mount() public function mount()
{ {
$this->current = Route::currentRouteName(); $this->current = Route::currentRouteName();
}
public function setUser()
{
$user = User::find(auth()->user()->id);
$this->sport = Sport::where('id', $user->sport_id)->value('name');
} }
public function render() public function render()
{ {
return view('livewire.top-menu-items'); return view('livewire.top-menu-items', ['sport' => $this->sport]);
} }
public function swopBookmaker($bookmaker_id) public function swopBookmaker($bookmaker_id)
+18
View File
@@ -27,4 +27,22 @@ class Sport extends Model
} }
} }
} }
public static function getSportForClient()
{
$user = User::find(auth()->user()->id);
$sports = Client::where('id', $user->client_id)->value('sport');
return Sport::query()->whereIn('id', $sports)->pluck('name', 'id');
}
public static function getSportId()
{
$user = User::find(auth()->user()->id);
return $user->sport_id;
}
} }
Generated
+3 -3
View File
@@ -12814,12 +12814,12 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": {}, "stability-flags": [],
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": "^8.3" "php": "^8.3"
}, },
"platform-dev": {}, "platform-dev": [],
"plugin-api-version": "2.9.0" "plugin-api-version": "2.6.0"
} }
@@ -17,8 +17,8 @@ return new class extends Migration
$table->integer('sport_id')->index()->references('id')->on('sports'); $table->integer('sport_id')->index()->references('id')->on('sports');
$table->integer('bookmaker_id')->index()->references('id')->on('bookmakers'); $table->integer('bookmaker_id')->index()->references('id')->on('bookmakers');
$table->integer('client_bookmaker_id')->index()->references('id')->on('bookmakers'); $table->integer('client_bookmaker_id')->index()->references('id')->on('bookmakers');
$table->integer('time_lastcheck'); $table->integer('time_lastcheck')->default(0);
$table->decimal('margin_threshold', 3, 2)->default(0); $table->integer('margin_threshold')->default(0);
$table->boolean('is_active')->default(false); $table->boolean('is_active')->default(false);
$table->boolean('is_hidden')->default(false); $table->boolean('is_hidden')->default(false);
$table->integer('sorting')->nullable()->default(0); $table->integer('sorting')->nullable()->default(0);
@@ -190,13 +190,13 @@
<x-filament::modal slide-over width="4xl" icon="phosphor-sliders" title="Comparing Bookmaker"> <x-filament::modal slide-over width="4xl" icon="phosphor-sliders" title="Comparing Bookmaker">
<x-slot name="trigger"> <x-slot name="trigger">
<x-filament::icon-button icon="phosphor-sliders" color="gray" class="my-auto" <x-filament::icon-button icon="phosphor-sliders" color="gray" class="my-auto" wire:click="setUser"
title="Comparing Bookmaker"> title="Comparing Bookmaker">
</x-filament::icon-button> </x-filament::icon-button>
</x-slot> </x-slot>
<x-slot name="heading"> <x-slot name="heading">
Comparing Bookmaker Comparing Bookmaker {{ $sport }}
</x-slot> </x-slot>
@livewire('comparing-bookmaker-menu') @livewire('comparing-bookmaker-menu')