149 lines
4.8 KiB
PHP
149 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Services\Tasks;
|
|
|
|
use App\Console\Commands\Nuh;
|
|
use App\Models\BettypeUser;
|
|
use App\Models\Bookmaker;
|
|
use App\Models\Client;
|
|
use App\Models\ComparingBookmaker;
|
|
use App\Models\MultilineClient;
|
|
use App\Models\MultilineSetting;
|
|
use App\Models\Sport;
|
|
use App\Models\User;
|
|
use App\Utilities\Notice;
|
|
|
|
class GenerateDefaultSetting
|
|
{
|
|
public static function run()
|
|
{
|
|
$debug = Nuh::$options['d'] ?? 0;
|
|
|
|
if ($debug) {
|
|
Notice::note('GENERATE DEFAULT SETTING', 'b');
|
|
}
|
|
|
|
/**************************************************
|
|
* MULTILINE SLOTS
|
|
**************************************************/
|
|
|
|
if ($debug) {
|
|
Notice::note('1) MULTILINE SLOTS', 'p');
|
|
}
|
|
|
|
$bookmaker_slots = [1 => 6, 2 => 30, 3 => 649, 4 => 126];
|
|
|
|
$clients = Client::get();
|
|
|
|
foreach ($clients as $client) {
|
|
|
|
foreach ($client->sport as $sport_id) {
|
|
|
|
foreach ($client->bookmaker as $client_bookmaker_id) {
|
|
|
|
$multilines = MultilineSetting::where('sport_id', $sport_id)->get()->pluck('id');
|
|
|
|
foreach ($multilines as $multiline_id) {
|
|
|
|
foreach ($bookmaker_slots as $slot => $bookmaker_id) {
|
|
|
|
MultilineClient::firstOrCreate(
|
|
['client_bookmaker_id' => $client_bookmaker_id, 'sport_id' => $sport_id, 'multiline_setting_id' => $multiline_id, 'position' => $slot],
|
|
['bookmaker_id' => $bookmaker_id, 'sort' => $slot, 'disabled' => 0]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**************************************************
|
|
* BETTYPES for USER in MONITOR
|
|
**************************************************/
|
|
|
|
if ($debug) {
|
|
Notice::note('2) GENERATOR BETTYPES IM COMPARATORE FOR USERS', 'p');
|
|
}
|
|
|
|
$users = User::get();
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$multilines = MultilineSetting::orderBy('sport_id')->pluck('sport_id', 'id');
|
|
|
|
foreach ($multilines as $multiline_setting_id => $sport_id) {
|
|
|
|
$is_active = in_array($multiline_setting_id, [1, 2, 9, 10, 16, 17, 22, 23]) ? 1 : 0;
|
|
|
|
BettypeUser::firstOrCreate(
|
|
['sport_id' => $sport_id, 'user_id' => $user->id, 'multiline_setting_id' => $multiline_setting_id],
|
|
['is_active' => $is_active]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**************************************************
|
|
* COMPARING BOOKMAKER
|
|
**************************************************/
|
|
|
|
if ($debug) {
|
|
Notice::note('3) COMPARING BOOKMAKER', 'p');
|
|
}
|
|
|
|
$res = Client::get();
|
|
|
|
$bookmakers_soccer = Bookmaker::where('in_soccer', 1)->orderBy('name')->pluck('id')->toArray();
|
|
|
|
ComparingBookmaker::where('method_id', 1)->where('sport_id', 1)->whereNotIn('bookmaker_id', $bookmakers_soccer)->delete();
|
|
|
|
foreach ($res as $client) {
|
|
|
|
$client_bookmakers = $client->bookmaker;
|
|
|
|
foreach ($client_bookmakers as $client_bookmaker_id) {
|
|
|
|
$i = 1;
|
|
foreach ($bookmakers_soccer as $bookmaker_id) {
|
|
|
|
ComparingBookmaker::updateOrCreate(
|
|
['method_id' => 1, 'sport_id' => 1, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id],
|
|
['is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => 110, 'sorting' => $i]
|
|
);
|
|
$i++;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
$sports = Sport::getActiveSports();
|
|
if (($key = array_search(1, $sports)) !== false) {
|
|
unset($sports[$key]);
|
|
}
|
|
|
|
$bookmakers_other = Bookmaker::where('in_other', 1)->orderBy('name')->pluck('id')->toArray();
|
|
|
|
ComparingBookmaker::where('method_id', 1)->whereIn('sport_id', $sports)->whereNotIn('bookmaker_id', $bookmakers_other)->delete();
|
|
|
|
foreach ($res as $client) {
|
|
|
|
$client_bookmakers = $client->bookmaker;
|
|
|
|
foreach ($client_bookmakers as $client_bookmaker_id) {
|
|
|
|
foreach ($sports as $sport_id) {
|
|
$i = 1;
|
|
foreach ($bookmakers_other as $bookmaker_id) {
|
|
|
|
ComparingBookmaker::updateOrCreate(
|
|
['method_id' => 1, 'sport_id' => $sport_id, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id],
|
|
['is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => 110, 'sorting' => $i]
|
|
);
|
|
$i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|