Files
nuhodds_fi4/app/Console/Commands/Grapper/TxOdds/Odds.php
T
2025-12-06 10:18:04 +01:00

457 lines
25 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\Grapper\TxOdds\Odds\_3Way;
use App\Console\Commands\Grapper\TxOdds\Odds\_Dc;
use App\Console\Commands\NuhBash;
use App\Console\Commands\Xml;
use App\Models\CompetitionGroup;
use App\Models\Element;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\Group;
use App\Models\Odds2way;
use App\Models\Odds3way;
use App\Models\OddsDc;
use App\Models\OddsGgng;
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?'.NuhBash::$AUTHTOKEN.'&all_odds=2&spid='.NuhBash::$options['sport_id'];
$_calls = [];
if (NuhBash::$options['event_id']) {
$_calls[] = $url."&ot=$markets&peid=".NuhBash::$options['event_id'];
} elseif (NuhBash::$options['a']) {
$res = Event::where('starttime', '>', Carbon::now()->toDateTimeString())->pluck('txodds_id');
foreach ($res as $id) {
$_calls[] = $url."&ot=$markets&peid=".$id;
}
} elseif (NuhBash::$options['w']) {
$res = Event::where('starttime', '>', Carbon::now()->toDateTimeString())->where('starttime', '<', Carbon::now()->addDays(7)->toDateTimeString())->pluck('txodds_id');
foreach ($res as $id) {
$_calls[] = $url."&ot=$markets&peid=".$id;
}
} else {
$_calls[] = $url.'&last='.NuhBash::$options['lastcall'];
}
/*************************************************
* CALL
*************************************************/
foreach ($_calls as $url) {
$data = Xml::load($url);
foreach ($data as $row) {
$event = [];
$event['txodds_id'] = (int) $row['id'];
$event['starttime'] = Carbon::createFromDate((string) $row->time)->toDateTimeString();
$group_name = (string) $row->group;
$event['group_id'] = (int) $row->group['id'];
$event['sport_id'] = (int) $row->group['spid'];
$event['country_id'] = (int) $row->group['cnid'];
$event['competition_group_id'] = (int) $row->group['cgid'];
$competition_group_name = (string) $row->group['cname'];
$home = (string) $row->hteam;
$event['home_id'] = (int) $row->hteam['id'];
$away = (string) $row->ateam;
$event['away_id'] = (int) $row->ateam['id'];
Group::updateOrCreate([
'txodds_id' => $event['group_id'],
'competition_group_id' => $event['competition_group_id'],
'sport_id' => $event['sport_id'],
'country_id' => $event['country_id'],
], [
'name' => $group_name,
]);
CompetitionGroup::updateOrCreate([
'txodds_id' => $event['competition_group_id'],
'sport_id' => $event['sport_id'],
'country_id' => $event['country_id'],
], [
'name' => $competition_group_name,
]);
Element::firstOrCreate([
'txodds_id' => $event['home_id'],
'name' => $home,
'sport_id' => $event['sport_id'],
]);
Element::firstOrCreate([
'txodds_id' => $event['away_id'],
'name' => $away,
'sport_id' => $event['sport_id'],
]);
NuhBash::$_event = Event::firstOrCreate($event, ['starttime' => $event['starttime']]);
foreach ($row->bookmaker as $book) {
$odds = [];
$odds['bookmaker_id'] = (int) $book['bid'];
NuhBash::$_event_bookmaker = [];
foreach ($book->offer as $offer) {
$bettypeid = 0;
foreach ($offer->attributes() as $attributeName => $attributeValue) {
switch ($attributeName) {
case 'id':
$odds['offer_id'] = (int) $attributeValue;
break;
case 'ot':
$bettypeid = (int) $attributeValue;
break;
case 'bmoid':
$odds['bmoid'] = (int) $attributeValue;
break;
case 'last_updated':
$odds['source_updated_at'] = Carbon::createFromDate((string) $attributeValue)->toDateTimeString();
break;
}
}
Notice::note($bettypeid, 'b');
switch ($bettypeid) {
case 0:
_3Way::grap($odds, $offer);
break;
case 5242880:
_Dc::grap($odds, $offer);
break;
default:
Notice::note('ERROR Bettype ID not set: '.$bettypeid, 'r');
break;
}
}
foreach (NuhBash::$_event_bookmaker as $value) {
if ($debug) {
Notice::note('Event Bookmaker', 'b');
}
EventBookmaker::updateOrCreate([
'event_id' => NuhBash::$_event->id,
'bookmaker_id' => $odds['bookmaker_id'],
], [
'bmoid' => $value['bmoid'],
'provider_id' => 2,
'bkm_starttime' => Carbon::createFromDate($value['starttime'])->toDateTimeString(),
'last_check_at' => Carbon::now()->toDateTimeString(),
]);
}
}
}
// foreach ($json_obj['match'] as $match) {
// self::$event = [];
// foreach ($match as $key => $v) {
// // if ($debug) {
// // Notice::note($key, 'b');
// // }
// switch ($key) {
// case '@attributes':
// self::$event['id'] = (int) $v['id'];
// break;
// case 'time':
// self::$event['starttime'] = Carbon::createFromDate($v)->toDateTimeString();
// break;
// case 'group':
// self::$event['sport_id'] = (int) $v['@attributes']['spid'];
// self::$event['country_id'] = (int) $v['@attributes']['cnid'];
// self::$event['group_id'] = (int) $v['@attributes']['id'];
// self::$event['competition_group_id'] = (int) $v['@attributes']['cgid'];
// break;
// case 'hteam':
// self::$event['home_id'] = $v['@attributes']['id'];
// break;
// case 'ateam':
// self::$event['away_id'] = $v['@attributes']['id'];
// break;
// case 'bookmaker':
// Event::updateOrCreate(self::$event, ['starttime' => self::$event['starttime']]);
// Notice::note(count($v), 'r');
// if (count($v) <= 2) {
// $bkmid = (int) $v['@attributes']['bid'];
// Notice::note($v, 'p');
// } else {
// foreach ($v as $books) {
// Notice::note($books, 'b');
// $bkmid = (int) $books['@attributes']['bid'];
// // foreach ($books['offer'] as $bk => $book) {
// // 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;
// }
// }
// }
// Notice::note('END', 'r', 1);
// }
}
}
}