toDateTimeString())->delete(); if ($debug) { Notice::note("Deleted: $info"); } $txodds_markets_columns = [ 1 => 'soccer', 2 => 'ice_hockey', 3 => 'basketball', 5 => 'tennis', ]; $res = TxoddsMarket::where($txodds_markets_columns[Nuh::$options['sport_id']], 1)->pluck('market_id', 'id')->toArray(); /************************************************* * use_lastcall *************************************************/ $markets = '&ot='.implode(',', $res); /************************************************* * URL *************************************************/ if (Nuh::$options['sport_id'] == 1) { $url = 'https://xml2.txodds.com/feed/odds/xml.php?'.config('env.txodds_betaid1').'&all_odds=2'; } else { $url = 'https://xml2.txodds.com/feed/odds/xml.php?'.config('env.txodds_betaid2').'&all_odds=2'; } $_calls = []; $sport = '&spid='.Nuh::$options['sport_id']; if (Nuh::$options['provider_id'] == 8) { /************************************************* * TXODDS MARKET LASTCALL *************************************************/ if ($debug) { Notice::note('TXOdds MARKET Lastcall', 'p'); } $market = '&ot='.Nuh::$options['txodds_market_id']; $lastcall = Nuh::$options['lastcall'] > time() - 600 ? '&last='.Nuh::$options['lastcall'] : '&last='.time() - 600; $_calls[] = $url.$sport.$market.$lastcall; } elseif (Nuh::$options['id']) { /************************************************* * BY ID *************************************************/ if ($debug) { Notice::note("BY ID \nsport_id: ".Nuh::$options['sport_id'], 'p'); } $id = '&peid='.Nuh::$options['id']; $_calls[] = $url.$markets.$id; } elseif (Nuh::$options['g']) { /************************************************* * BY GROUP ID *************************************************/ if ($debug) { Notice::note("GROUP_ID \nsport_id: ".Nuh::$options['sport_id'], 'p'); } $from_to = '&days='.Nuh::$options['days_from'].','.Nuh::$options['days_to']; $groupids = Event::where('starttime', '>', Carbon::now()->toDateTimeString())->groupBy('group_id')->pluck('group_id'); foreach ($groupids as $groupid) { $_calls[] = $url.$markets.$from_to.'&pgid='.$groupid; } } elseif (Nuh::$options['t']) { /************************************************* * TODAY by ID *************************************************/ if ($debug) { Notice::note("TODAY \nsport_id: ".Nuh::$options['sport_id'], 'p'); } $from = Carbon::now()->toDateTimeString(); $to = Carbon::now()->addDays(1)->toDateTimeString(); $res = Event::where('sport_id', Nuh::$options['sport_id'])->where('starttime', '>=', $from)->where('starttime', '<', $to)->pluck('id'); foreach ($res as $id) { $_calls[] = $url.$sport.$markets.'&peid='.$id; } } elseif (Nuh::$options['w']) { /************************************************* * ONE WEEK FROM NOW *************************************************/ if ($debug) { Notice::note("ONE WEEK FROM NOW \nsport_id: ".Nuh::$options['sport_id'], 'p'); } $res = Event::where('sport_id', Nuh::$options['sport_id'])->where('starttime', '>', Carbon::now()->toDateTimeString())->where('starttime', '<', Carbon::now()->addDays(7)->toDateTimeString())->pluck('id'); foreach ($res as $id) { $_calls[] = $url.$sport.$markets.'&peid='.$id; } } elseif (Nuh::$options['a']) { /************************************************* * ALL BY ID (reload) *************************************************/ if ($debug) { Notice::note("ALL \nsport_id: ".Nuh::$options['sport_id'], 'p'); } $res = Event::where('sport_id', Nuh::$options['sport_id'])->where('starttime', '>', Carbon::now()->toDateTimeString())->pluck('id'); foreach ($res as $id) { $_calls[] = $url.$sport.$markets.'&peid='.$id; } } else { Notice::note('BASH PARAMETER MISSING [--t, --w, --g, --a, --id=]', 'r', 1); } /************************************************* * CALL *************************************************/ $counter = 0; foreach ($_calls as $url) { $counter++; $data = Xml::load($url); if (Nuh::$options['provider_id'] == 8) { Supervisor::where('id', Nuh::$options['supervisor_id'])->update(['lastcall' => (int) $data['timestamp']]); } if ($debug) { Notice::note('counter: '.count($_calls).'/'.$counter, 'g'); } foreach ($data as $row) { $event_id = (int) $row['id']; $sport_id = (int) $row->group['spid']; $event = [ 'provider_id' => (int) Nuh::$options['provider_id'], 'starttime' => $row->time, 'sport_id' => $sport_id, 'home_id' => (int) $row->hteam['id'], 'away_id' => (int) $row->ateam['id'], 'country_id' => (int) $row->group['cnid'], 'group_id' => (int) $row->group['id'], 'competition_group_id' => (int) $row->group['cgid'], ]; Event::firstOrCreate(['id' => (int) $row['id']], $event); $group = [ 'competition_group_id' => (string) $row->group['cgid'], 'sport_id' => $sport_id, 'country_id' => (int) $row->group['cnid'], 'name' => (string) $row->group, ]; Group::updateOrCreate(['id' => (int) $row->group['id']], $group); $compgroup = [ 'sport_id' => $sport_id, 'country_id' => $event['country_id'], 'name' => (string) $row->group['cname'], ]; CompetitionGroup::updateOrCreate(['id' => (int) $row->group['cgid']], $compgroup); $element = [ 'name' => (string) $row->hteam, 'sport_id' => $sport_id, 'country_id' => (int) $row->group['cnid'], ]; Element::updateOrCreate(['id' => (int) $row->hteam['id']], $element); $element_group = [ 'competition_group_id' => (int) $row->group['cgid'], ]; ElementGroup::updateOrCreate(['element_id' => (int) $row->hteam['id'], 'group_id' => (int) $row->group['id']], $element_group); $element = [ 'name' => (string) $row->ateam, 'sport_id' => $sport_id, 'country_id' => (int) $row->group['cnid'], ]; Element::updateOrCreate(['id' => (int) $row->ateam['id']], $element); $element_group = [ 'competition_group_id' => (int) $row->group['cgid'], ]; ElementGroup::updateOrCreate(['element_id' => (int) $row->ateam['id'], 'group_id' => (int) $row->group['id']], $element_group); Nuh::$collector = []; foreach ($row->bookmaker as $book) { $bookmaker_id = (int) $book['bid']; $odds = []; $odds['event_id'] = $event_id; $odds['bookmaker_id'] = $bookmaker_id; $odds['sport_id'] = $sport_id; $odds['provider_id'] = Nuh::$options['provider_id']; 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'] = (string) $attributeValue; break; case 'flags': $odds['flags'] = (string) $attributeValue; break; } } switch ($bettypeid) { case 0: foreach ($offer->odds->attributes() as $attributeName => $attributeValue) { switch ($attributeName) { case 'starting_time': EventBookmaker::updateOrInsert([ 'event_id' => $event_id, 'bookmaker_id' => $bookmaker_id, ], ['starttime' => $attributeValue]); break; } } _3Way::grap($odds, $offer); break; // case 1: // foreach ($offer->odds->attributes() as $attributeName => $attributeValue) { // switch ($attributeName) { // case 'starting_time': // EventBookmaker::updateOrInsert([ // 'event_id' => Nuh::$id, // 'bookmaker_id' => Nuh::$bookmaker_id, // ], ['starttime' => $attributeValue]); // break; // } // } // _2Way::grap($odds, $offer); // break; // case 3: // foreach ($offer->odds->attributes() as $attributeName => $attributeValue) { // switch ($attributeName) { // case 'starting_time': // EventBookmaker::updateOrInsert([ // 'event_id' => Nuh::$id, // 'bookmaker_id' => Nuh::$bookmaker_id, // ], ['starttime' => $attributeValue]); // break; // } // } // _Points::grap($odds, $offer); // break; // case 4: // _Totals::grap($odds, $offer); // break; // case 131073: // _2WayS1::grap($odds, $offer); // break; // case 65536: // _3WayHt::grap($odds, $offer); // break; // case 65540: // _TotalsHt::grap($odds, $offer); // break; // case 65539: // _PointsHt::grap($odds, $offer); // break; // case 131075: // _PointsQ1::grap($odds, $offer); // break; // case 131076: // _TotalsQ1::grap($odds, $offer); // break; // case 5242880: // _Dc::grap($odds, $offer); // break; // case 6291457: // _Dnb::grap($odds, $offer); // break; // case 11534337: // _Ggng::grap($odds, $offer); // break; // case 7340033: // _Tq::grap($odds, $offer); // break; default: Notice::note('switch bettype ID not found: '.$bettypeid, 'r'); break; } } } ActiveSpread::set(); } } if ($debug) { Notice::note('DONE - EVENTS: '.$counter, 'g'); } } }