Files
nuhodds_fi4/app/Console/Commands/Grapper/TxOdds/Odds.php
T
2025-12-01 21:50:23 +01:00

338 lines
19 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Helper;
use App\Console\Commands\NuhBash;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\Odds3way;
use App\Models\OddsQualify;
use App\Models\OddsTotal;
use App\Utilities\Notice;
use Carbon\Carbon;
class Odds
{
public static function grap()
{
$debug = NuhBash::$options['d'] ?? 0;
if ($debug) {
Notice::note('txodd odd sport: '.NuhBash::$options['sport_id'], 'b');
}
/*************************************************
* SINGLE SOCCER
* https://xml2.txodds.com/feed/odds/xml.php?ident=betaid1&passwd=Dy59vpRC&peid=3118930
* SINGLE OTHER
*************************************************
* https://xml2.txodds.com/feed/odds/xml.php?ident=betaid2&passwd=Dy59vpRC&peid=3118930
*************************************************
* https://xml2.txodds.com/feed/odds_types.php
* BETTYPE IDS
0 3-WAY
1 2-WAY
3 POINTS
4 TOTALS
5 Asian
65536 3-WAY HALF TIME
131072 3 WAY QUARTER TIME
65539 POINTS HALF TIME
131075 POINTS QUARTER TIME
262147 POINTS OVER TIME
65540 TOTALS HALF TIME
131076 TOTALS QUARTER TIME
262148 TOTALS OVER TIME
11534337 GG/NG (both teams to score)
5242880 DOUBLE CHANCE
7340033 TO PROGRESS (to_qualify)
Not used:
65537 2-WAY HALF TIME
327680 3-WAY 2ND HALF
327681 2-WAY 2ND HALF
327683 POINT 2ND HALF
327684 TOTALS 2ND HALF
1048577 GOAL / NO GOAL
2097153 ODD / EVEN
4194304 TOTAL GOALS
6291457 DRAW NO BET
8388608 1X2 EURO HANDCIAP
9437188 TOTAL CORNERS
9502724 TOTAL CORNERS 1ST HALF
20971520 3-WAY CORNERS
28311555 HANDICAP SETS
28311556 TOTAL SETS
*************************************************/
$debug = NuhBash::$options['d'] ?? 0;
switch (NuhBash::$options['sport_id']) {
case 1:
$markets = '0,4,11534337,5242880,7340033';
break;
case 2:
// needs check
$markets = '0,1,3,4,262148,131072,131076';
break;
case 3:
// needs check
$markets = '0,1,3,4,262147,262148,65539,65540,131075,131076';
break;
case 5:
$markets = '1,3,4';
break;
case 8:
$markets = '0,3,4';
break;
default:
Notice::note('sport not defined', 'r', 1);
break;
}
/*************************************************
* URL
*************************************************/
$url = 'https://xml2.txodds.com/feed/odds/xml.php?'.config('nuh.txodds_token_soccer').'&all_odds=2&spid='.NuhBash::$options['sport_id'].'&json=2';
$_calls = [];
if (NuhBash::$options['event_id']) {
$_calls[] = $url."&ot=$markets&peid=".NuhBash::$options['event_id'];
} elseif (NuhBash::$options['a']) {
$res = Event::where('time', '>', Carbon::now()->toDateTimeString())->pluck('txid');
foreach ($res as $id) {
$_calls[] = $url."&ot=$markets&peid=".$id;
}
} elseif (NuhBash::$options['w']) {
$res = Event::where('time', '>', Carbon::now()->toDateTimeString())->where('time', '<', Carbon::now()->addDays(7)->toDateTimeString())->pluck('txid');
foreach ($res as $id) {
$_calls[] = $url."&ot=$markets&peid=".$id;
}
} else {
$_calls[] = $url.'&last='.NuhBash::$options['lastcall'];
}
/*************************************************
* CALL
*************************************************/
foreach ($_calls as $url) {
$json_obj = Curl::load($url);
foreach ($json_obj['match'] as $match) {
$e = [];
foreach ($match as $key => $v) {
// if ($debug) {
// Notice::note($key, 'b');
// }
switch ($key) {
case '@attributes':
$e['id'] = (int) $v['id'];
break;
case 'time':
$starttime = Carbon::createFromDate($v)->toDateTimeString();
break;
case 'group':
$e['sport_id'] = (int) $v['@attributes']['spid'];
$e['country_id'] = (int) $v['@attributes']['cnid'];
$e['group_id'] = (int) $v['@attributes']['id'];
$e['competition_group_id'] = (int) $v['@attributes']['cgid'];
break;
case 'hteam':
$e['home_id'] = $v['@attributes']['id'];
break;
case 'ateam':
$e['away_id'] = $v['@attributes']['id'];
$event = Event::firstOrCreate($e, ['starttime' => $starttime]);
break;
case 'bookmaker':
foreach ($v as $books) {
foreach ($books as $bookkey => $book) {
$bkmid = false;
switch ($bookkey) {
case '@attributes':
if (isset($book['bid'])) {
$bkmid = (int) $book['bid'];
}
case 'offer':
if ($bkmid) {
foreach ($book as $type => $od) {
switch ($type) {
case '@attributes':
$bettypeid = (int) $od['ot'];
$bmoid = (int) $od['bmoid'];
break;
case 'odds':
switch ($bettypeid) {
case '0':
Odds3way::updateOrCreate(
[
'event_id' => $event->id,
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
],
[
'h3w' => (float) $od['o1'],
'd3w' => (float) $od['o2'],
'a3w' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o2'], $od['o3']], 1),
'flag' => 1,
'nuh_check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
EventBookmaker::updateOrCreate([
'event_id' => $event->id,
'bookmaker_id' => $bkmid,
'bmoid' => $bmoid,
], [
'bkm_starttime' => Carbon::createFromDate($od['@attributes']['starting_time'])->toDateTimeString(),
'last_check_at' => Carbon::now()->toDateTimeString(),
]);
break;
case '1':
Odds2way::updateOrCreate(
[
'event_id' => $event->id,
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
],
[
'h2w' => (float) $od['o1'],
'a2w' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o3']], 1),
'flag' => 1,
'nuh_check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '4':
OddsTotal::updateOrCreate(
[
'event_id' => $event->id,
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
'spread' => (float) $od['o3'],
],
[
'over' => (float) $od['o1'],
'under' => (float) $od['o2'],
'margin' => (float) Helper::margin([$od['o1'], $od['o2'], $od['o3']], 1),
'flag' => 1,
'nuh_check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '5242880':
OddsDc::updateOrCreate(
[
'event_id' => $event->id,
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
],
[
'dc1x' => (float) $od['o1'],
'dc12' => (float) $od['o2'],
'dc2x' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o2'], $od['o3']], 1),
'flag' => 1,
'nuh_check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '11534337':
OddsGgng::updateOrCreate(
[
'event_id' => $event->id,
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
],
[
'gg' => (float) $od['o1'],
'ng' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o3']], 1),
'flag' => 1,
'nuh_check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '11534337':
OddsQualify::updateOrCreate(
[
'event_id' => $event->id,
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
],
[
'htq' => (float) $od['o1'],
'atq' => (float) $od['o2'],
'margin' => (float) Helper::margin([$od['o1'], $od['o3']], 1),
'flag' => 1,
'nuh_check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
}
break;
}
}
break;
}
}
}
}
break;
}
}
}
}
}
}