diff --git a/app/Console/Commands/Grapper/Fixtures/FindFixture.php b/app/Console/Commands/Grapper/Fixtures/FindFixture.php index e5252ac5..9e74f2db 100644 --- a/app/Console/Commands/Grapper/Fixtures/FindFixture.php +++ b/app/Console/Commands/Grapper/Fixtures/FindFixture.php @@ -66,7 +66,7 @@ class FindFixture } } - if ($match) { + if ($match ?? null) { $update_array = []; diff --git a/app/Console/Commands/Grapper/Goldbet.php b/app/Console/Commands/Grapper/Goldbet.php index 8bc3809c..f176c4f7 100644 --- a/app/Console/Commands/Grapper/Goldbet.php +++ b/app/Console/Commands/Grapper/Goldbet.php @@ -2,25 +2,146 @@ namespace App\Console\Commands\Grapper; -use App\Console\Commands\Grapper\Magloo\Fixtures; -use App\Console\Commands\Grapper\Magloo\Odds; +use App\Console\Commands\Grapper\Fixtures\FindFixture; use App\Console\Commands\Nuh; +use App\Models\Odds3way; +use App\Models\OddsDc; +use App\Models\OddsGgng; +use App\Models\OddsTotal; +use App\Utilities\Margin; use App\Utilities\Notice; +use Illuminate\Support\Carbon; class Goldbet { public static function switch() { - switch (Nuh::$options['name']) { - case 'Fixtures': - Fixtures::grap(); - break; - case 'Odds': - Odds::grap(); - break; - default: - Notice::note('prosses name does not exist', 'r', 1); - break; + $debug = Nuh::$options['d'] ?? 0; + $save = Nuh::$options['s'] ?? 0; + $read = Nuh::$options['r'] ?? 0; + + $filename = app_path().'/Console/Commands/TestFiles/goldbet.json'; + + if ($debug) { + Notice::note(Nuh::$options['provider'], 'g'); + } + + if ($read) { + if ($debug) { + Notice::note('data read localy', 'g'); + } + + $file = file_get_contents($filename); + + $data = json_decode($file, true); + } else { + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://gb.nuhodds.com'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Proxy-Auth: jjW2jVVezcMURUBuhzf6VDXXsMhN5JWKEeQ5pYusg7b29G', + 'Proxy-Target-URL: '.Nuh::$options['base_url'], + // 'Proxy-Debug: 1' + ]); + + $file = curl_exec($ch); + } + + if ($save) { + file_put_contents($filename, $file); + + Notice::note('file saved localy', 'g'); + } + + $data = json_decode($file, true); + + // https://api.b365api.com/v1/sbobet/event?token=36152-aeTRNnZxSPUwGe&event_id=10399052 + // https://api.b365api.com/v1/sbobet/inplay?sport_id=1&token=36152-aeTRNnZxSPUwGe + + foreach ($data as $row) { + if ($row['liga'] != 'Fantasy Matches') { + + /** + * sportid is same like txoods + */ + $event = [ + 'event_id' => (int) $row['matchid'], + 'sport_id' => (int) $row['sport'], + 'provider_id' => (int) Nuh::$options['provider_id'], + 'starttime' => (string) Carbon::createFromTimestamp((string) $row['starttime'])->toDateTimeString(), + 'country' => $row['country'] ?? 0, + 'country_id' => (int) $row['countryid'] ?? 0, + 'home' => $row['e1'] ?? '', + 'home_id' => (int) $row['e2id'], + 'away' => $row['e2'] ?? '', + 'away_id' => (int) $row['e2id'], + 'group' => $row['liga'] ?? '', + 'group_id' => (int) $row['lid'] ?? 0, + ]; + + FindFixture::find($event); + + if (isset($event['id'])) { + + $base = []; + $base['sport_id'] = (int) Nuh::$options['sport_id']; + $base['provider_id'] = Nuh::$options['provider_id']; + $base['bmoid'] = (int) $row['match_id']; + $base['flag'] = 1; + + if (isset($row['1x2'])) { + $odds = []; + $odds['h3w'] = $row['1x2']['one']; + $odds['d3w'] = $row['1x2']['x']; + $odds['a3w'] = $row['1x2']['two']; + $odds['margin'] = (float) Margin::calculate($odds, 1); + $odds['starttime'] = (string) $row['start_time']; + + Odds3way::updateOrCreate([ + 'event_id' => $event['id'], + 'bookmaker_id' => Nuh::$options['bookmaker_id'], + ], $base + $odds); + } + if (isset($row['ou'])) { + $odds = []; + $odds['over'] = $row['ou']['over']; + $odds['under'] = $row['ou']['under']; + $odds['margin'] = (float) Margin::calculate($odds, 1); + $odds['total'] = 2.5; + + OddsTotal::updateOrCreate([ + 'event_id' => $event['id'], + 'bookmaker_id' => Nuh::$options['bookmaker_id'], + ], $base + $odds); + } + if (isset($row['dc'])) { + $odds = []; + $odds['dc1x'] = $row['dc']['dc1x']; + $odds['dc12'] = $row['dc']['dc12']; + $odds['dcx2'] = $row['dc']['dcx2']; + $odds['margin'] = (float) Margin::calculate($odds, 1); + $odds['starttime'] = (string) $row['start_time']; + + OddsDc::updateOrCreate([ + 'event_id' => $event['id'], + 'bookmaker_id' => Nuh::$options['bookmaker_id'], + ], $base + $odds); + } + if (isset($row['gg_ng'])) { + $odds = []; + $odds['gg'] = $row['gg_ng']['gg']; + $odds['ng'] = $row['gg_ng']['ng']; + $odds['margin'] = (float) Margin::calculate($odds, 1); + $odds['starttime'] = (string) $row['start_time']; + + OddsGgng::updateOrCreate([ + 'event_id' => $event['id'], + 'bookmaker_id' => Nuh::$options['bookmaker_id'], + ], $base + $odds); + } + } + } } } } diff --git a/app/Console/Commands/Services/Services.php b/app/Console/Commands/Services/Services.php index 25c0bec6..57f6f68f 100644 --- a/app/Console/Commands/Services/Services.php +++ b/app/Console/Commands/Services/Services.php @@ -4,6 +4,7 @@ namespace App\Console\Commands\Services; use App\Console\Commands\Nuh; use App\Console\Commands\Services\Tasks\CallTxoddsMarkets; +use App\Console\Commands\Services\Tasks\DBMapper; class Services { @@ -13,8 +14,8 @@ class Services case 'Txodds Markets': CallTxoddsMarkets::call(); break; - case 'Mapper': - Mapper::run(); + case 'DB Mapper': + DBMapper::run(); break; } } diff --git a/app/Console/Commands/Services/Tasks/DBMapper.php b/app/Console/Commands/Services/Tasks/DBMapper.php new file mode 100644 index 00000000..04ff3138 --- /dev/null +++ b/app/Console/Commands/Services/Tasks/DBMapper.php @@ -0,0 +1,66 @@ +toArray(); + + $i = 0; + foreach ($events as $event) { + + Notice::note($i); + + FindElement::run($event); + + FindGroup::run($event); + + FindCountry::run($event); + + // print_r($event); + + if ($event['txodds_home_id'] && $event['txodds_away_id'] && $event['txodds_group_id']) { + $from = Carbon::createFromDate($event['starttime'])->subDay(); + + $to = Carbon::createFromDate($event['starttime'])->addDay(); + + // DB::enableQueryLog(); + + $query = Event::where('starttime', '>', $from->toDateTimeString()) + ->where('starttime', '<', $to->toDateTimeString()) + ->whereIn('home_id', $event['txodds_home_id']) + ->whereIn('home_id', $event['txodds_away_id']) + ->whereIn('competition_group_id', $event['txodds_group_id']) + ->get(); + + // Notice::db(DB::getQueryLog()); + + Notice::db($query); + } + + $i++; + if ($i > 100) { + exit; + } + } + + } +} diff --git a/app/Console/Commands/Services/Tasks/Helper/ExplodeElement.php b/app/Console/Commands/Services/Tasks/Helper/ExplodeString.php similarity index 94% rename from app/Console/Commands/Services/Tasks/Helper/ExplodeElement.php rename to app/Console/Commands/Services/Tasks/Helper/ExplodeString.php index a4e13984..d7fc5b5a 100644 --- a/app/Console/Commands/Services/Tasks/Helper/ExplodeElement.php +++ b/app/Console/Commands/Services/Tasks/Helper/ExplodeString.php @@ -2,7 +2,7 @@ namespace App\Console\Commands\Services\Tasks\Helper; -class ExplodeElement +class ExplodeString { public static function grap($str) { @@ -22,7 +22,7 @@ class ExplodeElement $_return = []; foreach ($elements as $value) { - if (\strlen($value) > 2) { + if (\strlen($value) > 3) { $_return[] = $value; } } diff --git a/app/Console/Commands/Services/Tasks/Helper/FindCountry.php b/app/Console/Commands/Services/Tasks/Helper/FindCountry.php new file mode 100644 index 00000000..d9ddb5f4 --- /dev/null +++ b/app/Console/Commands/Services/Tasks/Helper/FindCountry.php @@ -0,0 +1,44 @@ +value('en'); + + $event['txodds_country_id'] = Country::where('name', $country)->value('id'); + } else { + + $country = self::fix_country($event['country']); + + $event['txodds_country_id'] = Country::where('name', $country)->value('id'); + } + } + + public static function fix_country($country) + { + switch ($country) { + case 'Internazionale': + case 'International Club': + case 'Internazionali Di Club': + case 'FIBA Intercontinental Cup': + return 'International'; + case 'Euro Cup': + case 'Euro Cup Women': + case 'Euroleague': + case 'Euroleague Women': + return 'Europe'; + case 'WNBA': + return 'USA'; + default: + return $country; + } + } +} diff --git a/app/Console/Commands/Services/Tasks/Helper/FindElement.php b/app/Console/Commands/Services/Tasks/Helper/FindElement.php new file mode 100644 index 00000000..e6c434a9 --- /dev/null +++ b/app/Console/Commands/Services/Tasks/Helper/FindElement.php @@ -0,0 +1,42 @@ +where('provider_element_id', $event['home_id'])->value('element_id'); + } + if (! $event['txodds_home_id']) { + $arr = ExplodeString::grap($event['home']); + + $event['txodds_home_id'] = Element::where('sport_id', $event['sport_id']) + ->where(function ($query) use ($arr) { + foreach ($arr as $str) { + $query->orwhere('name', 'like', '%'.$str.'%'); + } + })->pluck('id')->toArray(); + } + + if (isset($event['away_id'])) { + $event['txodds_away_id'][] = ElementProvider::where('provider_id', $event['provider_id']) + ->where('provider_element_id', $event['away_id'])->value('element_id'); + } + if (! $event['txodds_away_id']) { + $arr = ExplodeString::grap($event['away']); + + $event['txodds_away_id'] = Element::where('sport_id', $event['sport_id']) + ->where(function ($query) use ($arr) { + foreach ($arr as $str) { + $query->orwhere('name', 'like', '%'.$str.'%'); + } + })->pluck('id')->toArray(); + } + } +} diff --git a/app/Console/Commands/Services/Tasks/Helper/FindGroup.php b/app/Console/Commands/Services/Tasks/Helper/FindGroup.php new file mode 100644 index 00000000..a1f56fde --- /dev/null +++ b/app/Console/Commands/Services/Tasks/Helper/FindGroup.php @@ -0,0 +1,29 @@ +where('provider_group_id', $event['group_id'])->value('competition_group_id'); + } + if (! $event['txodds_group_id']) { + $arr = ExplodeString::grap($event['group']); + + $event['txodds_group_id'] = CompetitionGroup::where('sport_id', $event['sport_id']) + ->where(function ($query) use ($arr) { + foreach ($arr as $str) { + $query->orwhere('name', 'like', '%'.$str.'%'); + } + })->pluck('id')->toArray(); + } + + } +} diff --git a/app/Console/Commands/Services/Tasks/Mapper.php b/app/Console/Commands/Services/Tasks/Mapper.php deleted file mode 100644 index e944075b..00000000 --- a/app/Console/Commands/Services/Tasks/Mapper.php +++ /dev/null @@ -1,40 +0,0 @@ - 'Txodds Markets', - 'Mapper Soccer' => 'Mapper Soccer', - 'Mapper Ice Hockey' => 'Mapper Ice Hockey', - 'Mapper Basketball' => 'Mapper Basketball', - 'Mapper Tennis' => 'Mapper Tennis', + 'DB Mapper' => 'DB Mapper', ]; case 9: case 10: diff --git a/app/Models/CountriesItalian.php b/app/Models/CountriesItalian.php new file mode 100644 index 00000000..59263039 --- /dev/null +++ b/app/Models/CountriesItalian.php @@ -0,0 +1,10 @@ +id(); + $table->string('en')->nullable(); + $table->string('it')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('countries_italians'); + } +}; diff --git a/database/seeders/CountryItalianSeeder.php b/database/seeders/CountryItalianSeeder.php new file mode 100644 index 00000000..cec4625c --- /dev/null +++ b/database/seeders/CountryItalianSeeder.php @@ -0,0 +1,250 @@ +