Files
nuhodds_fi4/app/Console/Commands/Grapper/TxOdds/Odds.php
T
2025-12-01 07:42:54 +01:00

329 lines
18 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\Odds3way;
use App\Models\OddsQualify;
use App\Models\OddsTotal;
use App\Utilities\Notice;
use Carbon\Carbon;
class Odds
{
public static function grap()
{
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, $debug);
$e = [];
foreach ($json_obj['match'] as $key => $v) {
Notice::note($key, 'b');
switch ($key) {
case '@attributes':
$e['id'] = (int) $v['id'];
break;
case 'time':
$e['time'] = $v;
break;
case 'group':
$e['liga'] = $v['@attributes']['cname'];
$e['liid'] = $v['@attributes']['id'];
$e['cgid'] = $v['@attributes']['cgid'];
$e['spid'] = $v['@attributes']['spid'];
$e['mgid'] = $v['@attributes']['mgid'];
$e['cnid'] = $v['@attributes']['cnid'];
break;
case 'hteam':
$e['hoid'] = $v['@attributes']['id'];
$e['home'] = $v['@text'];
break;
case 'ateam':
$e['awid'] = $v['@attributes']['id'];
$e['away'] = $v['@text'];
break;
case 'bookmaker':
foreach ($v as $books) {
foreach ($books as $bkey => $book) {
switch ($bkey) {
case '@attributes':
$bname = $book['name'];
$bkmid = (int) $book['bid'];
$e['odds'][$bkmid]['name'] = $bname;
break;
case 'offer':
foreach ($book as $offer) {
foreach ($offer as $type => $od) {
switch ($type) {
case '@attributes':
$bettypeid = (int) $od['ot'];
dd('add to event bookmaker missing');
// 'book_startime' => $od['@attributes']['starting_time'],
$bmoid = $od['bmoid'];
break;
case 'odds':
switch ($bettypeid) {
case '0':
Odds3way::updateOrCreate(
[
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
'bmoid' => $bmoid,
],
[
'start' => $od['@attributes']['starting_time'],
'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,
'check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '1':
Odds2way::updateOrCreate(
[
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
'bmoid' => $bmoid,
],
[
'start' => $od['@attributes']['starting_time'],
'h2w' => (float) $od['o1'],
'a2w' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o3']], 1),
'flag' => 1,
'check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '4':
OddsTotal::updateOrCreate(
[
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
'bmoid' => $bmoid,
'spread' => (float) $od['o3'],
],
[
'start' => $od['@attributes']['starting_time'],
'over' => (float) $od['o1'],
'under' => (float) $od['o2'],
'margin' => (float) Helper::margin([$od['o1'], $od['o2'], $od['o3']], 1),
'flag' => 1,
'check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '5242880':
OddsDc::updateOrCreate(
[
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
'bmoid' => $bmoid,
],
[
'start' => $od['@attributes']['starting_time'],
'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,
'check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '11534337':
OddsGgng::updateOrCreate(
[
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
'bmoid' => $bmoid,
],
[
'start' => $od['@attributes']['starting_time'],
'gg' => (float) $od['o1'],
'ng' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o3']], 1),
'flag' => 1,
'check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
case '11534337':
OddsQualify::updateOrCreate(
[
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'sport_id' => NuhBash::$options['sport_id'],
'bmoid' => $bmoid,
],
[
'start' => $od['@attributes']['starting_time'],
'htq' => (float) $od['o1'],
'atq' => (float) $od['o2'],
'margin' => (float) Helper::margin([$od['o1'], $od['o3']], 1),
'flag' => 1,
'check' => 0,
'source_updated_at' => $od['@attributes']['time'],
'last_check_at' => Carbon::now()->toDateTimeString(),
]
);
break;
}
break;
}
}
}
break;
}
}
}
break;
}
}
}
}
}