grapper wip

This commit is contained in:
salam committed 2026-01-18 14:35:30 +01:00
1 parent 562c65f331
commit 4184acdb8a
60 files changed
+28840 -398

No files matched your search

+127 -45
View File
@@ -5,6 +5,7 @@ namespace App\Console\Commands\Grapper\Betsapi;
use App\Console\Commands\Curl;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\Odds3way;
use App\Models\Odds3wayHt;
use App\Models\OddsDc;
@@ -64,9 +65,16 @@ class Bet365
if (isset($data['results'][0]['main'])) {
EventBookmaker::updateOrCreate([
'event_id' => $event->id,
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], ['starttime' => $event->starttime, 'in_feed' => 1, 'bmoid' => $event->bet365_id]);
$offer = $data['results'][0]['main']['sp'];
$base = [];
$base['event_id'] = $event->id;
$base['bookmaker_id'] = $bookmaker_id;
$base['sport_id'] = $event->sport_id;
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event->bet365_id;
@@ -77,15 +85,28 @@ class Bet365
*/
if (isset($offer['full_time_result'])) {
$odds = [];
$odds['h3w'] = $offer['full_time_result']['odds'][0]['odds'] ?? 1;
$odds['d3w'] = $offer['full_time_result']['odds'][1]['odds'] ?? 1;
$odds['a3w'] = $offer['full_time_result']['odds'][2]['odds'] ?? 1;
$odds['h3w'] = number_format($offer['full_time_result']['odds'][0]['odds'], 2) ?? 1;
$odds['d3w'] = number_format($offer['full_time_result']['odds'][1]['odds'], 2) ?? 1;
$odds['a3w'] = number_format($offer['full_time_result']['odds'][2]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
Odds3way::updateOrCreate([
'event_id' => $event->id,
'bookmaker_id' => $bookmaker_id,
], $base + $odds);
$odds = array_merge($odds, $base);
$res = Odds3way::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
Odds3way::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->a3w = $odds['d3w'];
$res->d3w = $odds['a3w'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
/**
@@ -93,15 +114,28 @@ class Bet365
*/
if (isset($offer['double_chance'])) {
$odds = [];
$odds['dc1x'] = $offer['double_chance']['odds'][0]['odds'] ?? 1;
$odds['dc12'] = $offer['double_chance']['odds'][1]['odds'] ?? 1;
$odds['dcx2'] = $offer['double_chance']['odds'][2]['odds'] ?? 1;
$odds['dc1x'] = number_format($offer['double_chance']['odds'][0]['odds'], 2) ?? 1;
$odds['dc12'] = number_format($offer['double_chance']['odds'][1]['odds'], 2) ?? 1;
$odds['dcx2'] = number_format($offer['double_chance']['odds'][2]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
OddsDc::updateOrCreate([
'event_id' => $event->id,
'bookmaker_id' => $bookmaker_id,
], $base + $odds);
$odds = array_merge($odds, $base);
$res = OddsDc::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
OddsDc::create($odds);
} else {
$res->dc1x = $odds['dc1x'];
$res->dc12 = $odds['dc12'];
$res->dcx2 = $odds['dcx2'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
/**
@@ -110,19 +144,35 @@ class Bet365
if (isset($offer['goals_over_under'])) {
$odds = [];
$odds['over'] = $offer['goals_over_under']['odds'][0]['odds'] ?? 1;
$odds['under'] = $offer['goals_over_under']['odds'][1]['odds'] ?? 1;
$odds['over'] = number_format($offer['goals_over_under']['odds'][0]['odds'], 2) ?? 1;
$odds['under'] = number_format($offer['goals_over_under']['odds'][1]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
if ($base['sport_id'] == 1) {
$odds['active_spread'] = 1;
}
$odds = array_merge($odds, $base);
if ($offer['goals_over_under']['odds'][1]['name'] == '2.5') {
OddsTotal::updateOrCreate([
'event_id' => $event->id,
'bookmaker_id' => $bookmaker_id,
'total' => 2.5,
], $base + $odds);
$odds['total'] = 2.5;
$res = OddsTotal::where('event_id', $event->id)
->where('bookmaker_id', $bookmaker_id)
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotal::create($odds);
} else {
$res->over = $odds['over'];
$res->under = $odds['under'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->difference = abs(1 / $odds['over'] - 1 / $odds['under']);
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
}
@@ -131,14 +181,26 @@ class Bet365
*/
if (isset($offer['both_teams_to_score'])) {
$odds = [];
$odds['gg'] = $offer['both_teams_to_score']['odds'][0]['odds'] ?? 1;
$odds['ng'] = $offer['both_teams_to_score']['odds'][1]['odds'] ?? 1;
$odds['gg'] = number_format($offer['both_teams_to_score']['odds'][0]['odds'], 2) ?? 1;
$odds['ng'] = number_format($offer['both_teams_to_score']['odds'][1]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
OddsGgng::updateOrCreate([
'event_id' => $event->id,
'bookmaker_id' => $bookmaker_id,
], $base + $odds);
$odds = array_merge($odds, $base);
$res = OddsGgng::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
OddsGgng::create($odds);
} else {
$res->gg = $odds['gg'];
$res->ng = $odds['ng'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
/**
@@ -146,35 +208,55 @@ class Bet365
*/
if (isset($offer['draw_no_bet'])) {
$odds = [];
$odds['dnb1'] = $offer['draw_no_bet']['odds'][0]['odds'] ?? 1;
$odds['dnb2'] = $offer['draw_no_bet']['odds'][1]['odds'] ?? 1;
$odds['dnb1'] = number_format($offer['draw_no_bet']['odds'][0]['odds'], 2) ?? 1;
$odds['dnb2'] = number_format($offer['draw_no_bet']['odds'][1]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
OddsDnb::updateOrCreate([
'event_id' => $event->id,
'bookmaker_id' => $bookmaker_id,
], $base + $odds);
}
$res = OddsDnb::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
/**
* HALFTIME
*/
$offer = $data['results'][0]['half']['sp'] ?? '';
$odds = array_merge($odds, $base);
if (! $res) {
OddsDnb::create($odds);
} else {
$res->dnb1 = $odds['dnb1'];
$res->dnb2 = $odds['dnb2'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
/**
* 1X2 HT
*/
if (isset($offer['half_time_result'])) {
$odds = [];
$odds['h3w'] = $offer['half_time_result']['odds'][0]['odds'] ?? 1;
$odds['d3w'] = $offer['half_time_result']['odds'][1]['odds'] ?? 1;
$odds['a3w'] = $offer['half_time_result']['odds'][2]['odds'] ?? 1;
$odds['h3w'] = number_format($offer['half_time_result']['odds'][0]['odds'], 2) ?? 1;
$odds['d3w'] = number_format($offer['half_time_result']['odds'][1]['odds'], 2) ?? 1;
$odds['a3w'] = number_format($offer['half_time_result']['odds'][2]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
Odds3wayHt::updateOrCreate([
'event_id' => $event->id,
'bookmaker_id' => $bookmaker_id,
], $base + $odds);
$odds = array_merge($odds, $base);
$res = Odds3wayHt::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
Odds3wayHt::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->d3w = $odds['d3w'];
$res->d3w = $odds['a3w'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
}
}