This commit is contained in:
salam committed 2026-10-04 15:25:03 +02:00
1 parent 9bcd4432c6
commit 6f92f9e1d5
1209 files changed
+220940

No files matched your search

@@ -0,0 +1,35 @@
<?php
namespace App\Console\Commands\Services;
use App\Console\Commands\Nuh;
use App\Console\Commands\Services\Tasks\GenerateAlarms;
use App\Console\Commands\Services\Tasks\GenerateSetting;
use App\Console\Commands\Services\Tasks\MarketsList;
use App\Console\Commands\Services\Tasks\NotifyAlarms;
use App\Console\Commands\Services\Tasks\TxoddsFlags;
class Services
{
public static function switch()
{
switch (Nuh::$options['name']) {
case 'Txodds Markets':
MarketsList::call();
break;
case 'Txodds Flags':
TxoddsFlags::call();
break;
case 'Generate Setting':
GenerateSetting::run();
break;
case 'Generate Alarms':
GenerateAlarms::run();
break;
case 'Notify Alarms':
NotifyAlarms::run();
break;
}
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Models\ComparingBookmaker;
class AlarmBookmakerFilter
{
public static function get($client_bookmaker_id, $sport_id)
{
$res = ComparingBookmaker::where('sport_id', $sport_id)
->where('client_bookmaker_id', $client_bookmaker_id)
->where('is_active', 1)
->orderBy('sorting', 'asc')
->select('bookmaker_id', 'time_lastcheck', 'margin_threshold', 'sorting')
->get();
$arr = [];
foreach ($res as $value) {
$arr[$value->bookmaker_id] = [
'sorting' => $value->sorting,
'time_lastcheck' => $value->time_lastcheck,
'margin_threshold' => $value->margin_threshold,
];
}
return $arr;
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
class AlarmFilterClient
{
public static function get($odds, $client_bookmaker_id)
{
if (isset($odds[$client_bookmaker_id])) {
return $odds[$client_bookmaker_id];
}
return [];
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
class AlarmFilterCompare
{
public static function get($odds, $filter)
{
foreach ($filter as $bookmaker_id => $value) {
if (isset($odds[$bookmaker_id])) {
$data = $odds[$bookmaker_id];
if ($data['margin'] <= $value['margin_threshold']) {
$data['bookmaker_id'] = $bookmaker_id;
return $data;
}
}
}
return [];
}
}
@@ -0,0 +1,100 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use Illuminate\Support\Facades\DB;
class AlarmLoadOdds
{
public static function get($event_id, $table, $oddnames)
{
if (in_array($table, ['odds_points', 'odds_points_ht', 'odds_points_q1', 'odds_totals', 'odds_totals_ht', 'odds_totals_q1'])) {
$res = DB::table($table)->where('active_spread', 1)->where('flags', 1)->where('event_id', $event_id)->get();
} else {
$res = DB::table($table)->where('flags', 1)->where('event_id', $event_id)->get();
}
$arr = [];
foreach ($res as $value) {
if (in_array($table, ['odds_totals', 'odds_totals_ht', 'odds_totals_q1'])) {
$arr[(int) $value->bookmaker_id]['total'] = (float) $value->total;
} elseif (in_array($table, ['odds_points', 'odds_points_ht', 'odds_points_q1'])) {
$arr[(int) $value->bookmaker_id]['handicap'] = (float) $value->handicap;
}
if ($table == 'odds_dc') {
$arr[(int) $value->bookmaker_id]['margin'] = (float) $value->margin * 2;
} else {
$arr[(int) $value->bookmaker_id]['margin'] = (float) $value->margin;
}
foreach ($oddnames as $odd) {
switch ($odd) {
case 'h3w':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->h3w;
break;
case 'd3w':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->d3w;
break;
case 'a3w':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->a3w;
break;
case 'h2w':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->h2w;
break;
case 'a2w':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->a2w;
break;
case 'dnb1':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->dnb1;
break;
case 'dnb2':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->dnb2;
break;
case 'gg':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->gg;
break;
case 'ng':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->ng;
break;
case 'dc1x':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->dc1x;
break;
case 'dc12':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->dc12;
break;
case 'dcx2':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->dcx2;
break;
case 'home':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->home;
break;
case 'away':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->away;
break;
case 'over':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->over;
break;
case 'under':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->under;
break;
case 'htq':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->htq;
break;
case 'atq':
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->atq;
break;
}
}
}
return $arr;
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
class AlarmMap
{
public static function get($table)
{
$map = [
'odds_2ways' => ['alarm_2w_h2w' => 'h3w', 'alarm_2w_a2w' => 'a2w'],
'odds_2ways_s1' => ['alarm_2ws1_h2w' => 'h3w', 'alarm_2ws1_a2w' => 'a2w'],
'odds_3ways' => ['alarm_3w_h3w' => 'h3w', 'alarm_3w_d3w' => 'd3w', 'alarm_3w_a3w' => 'a3w'],
'odds_3ways_ht' => ['alarm_3wht_h3w' => 'h3w', 'alarm_3wht_d3w' => 'd3w', 'alarm_3wht_a3w' => 'a3w'],
'odds_dc' => ['alarm_dc_dc1x' => 'dc1x', 'alarm_dc_dc12' => 'dc12', 'alarm_dc_dcx2' => 'dcx2'],
'odds_dnb' => ['alarm_dbn_dnb1' => 'dnb1', 'alarm_dbn_dnb2' => 'dnb2'],
'odds_ggng' => ['alarm_ggng_gg' => 'gg', 'alarm_ggng_ng' => 'ng'],
'odds_points' => ['alarm_po_home' => 'home', 'alarm_po_away' => 'away'],
'odds_points_ht' => ['alarm_poht_home' => 'home', 'alarm_poht_away' => 'away'],
'odds_points_q1' => ['alarm_poq1_home' => 'home', 'alarm_poq1_away' => 'away'],
'odds_totals' => ['alarm_to_over' => 'over', 'alarm_to_under' => 'under'],
'odds_totals_ht' => ['alarm_toht_over' => 'over', 'alarm_toht_under' => 'under'],
'odds_totals_q1' => ['alarm_toq1_over' => 'over', 'alarm_toq1_under' => 'under'],
'odds_tq' => ['alarm_tq_htq' => 'htq', 'alarm_tq_atq' => 'atq'],
];
return $map[$table];
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Models\MultilineSetting;
class AlarmMultilineSetting
{
public static function get($sport_id)
{
$res = MultilineSetting::where('sport_id', $sport_id)->get();
$arr = [];
foreach ($res as $value) {
$arr[$value->id] = [
'table' => $value->table,
'oddnames' => $value->oddnames,
];
}
return $arr;
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Models\AlarmSetting;
class AlarmSettings
{
public static function get($client_bookmaker_id, $sport_id)
{
$res = AlarmSetting::where('sport_id', $sport_id)
->where('client_bookmaker_id', $client_bookmaker_id)
->where('disabled', 0)
->select('multiline_setting_id', 'alarm_level_id', 'alarm_threshold')
->get();
$arr = [];
foreach ($res as $value) {
$arr[$value->multiline_setting_id][$value->alarm_level_id] = $value->alarm_threshold;
}
return $arr;
}
}
@@ -0,0 +1,70 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Models\EventBookmaker;
class AlarmStore
{
public static function get($table, $event_id, $oddnames, $client_bookmaker_id, $alarm_threshold, $compare_odds, $client_odds)
{
if (! $compare_odds) {
return;
}
if (! $client_odds) {
return;
}
$favorit = min($client_odds);
// if ($table == 'odds_points') {
// dd($compare_odds);
// }
$update_array = [];
foreach ($oddnames as $fieldname => $oddname) {
if ($client_odds[$oddname] == $favorit) {
$threshold = $client_odds[$oddname] - $compare_odds[$oddname];
if (in_array($table, ['odds_totals', 'odds_totals_ht', 'odds_totals_q1'])) {
if ((float) $client_odds['total'] == (float) $compare_odds['total']) {
self::setAlarm($update_array, $fieldname, $threshold, $alarm_threshold);
} else {
$update_array[$fieldname] = 0;
}
} elseif (in_array($table, ['odds_points', 'odds_points_ht', 'odds_points_q1'])) {
if ((float) $client_odds['handicap'] == (float) $compare_odds['handicap']) {
self::setAlarm($update_array, $fieldname, $threshold, $alarm_threshold);
} else {
$update_array[$fieldname] = 0;
}
} else {
self::setAlarm($update_array, $fieldname, $threshold, $alarm_threshold);
}
} else {
$update_array[$fieldname] = 0;
}
}
EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $client_bookmaker_id)->update($update_array);
}
public static function setAlarm(&$update_array, $fieldname, $threshold, $alarm_threshold)
{
if ($threshold > $alarm_threshold[3]) {
// ROT
$update_array[$fieldname] = 3;
} elseif ($threshold > $alarm_threshold[2]) {
// ORANGE
$update_array[$fieldname] = 2;
} elseif ($threshold > $alarm_threshold[1]) {
// GRÜNE
$update_array[$fieldname] = 1;
} else {
// Reset Alarm
$update_array[$fieldname] = 0;
}
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Utilities\Notice;
use Illuminate\Support\Facades\DB;
class DBConsistencyChecker
{
public static function checkEvents()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('DB Consistency Checker', 'b');
}
$res = DB::raw('select * from event_bookmakers where not exists (select * from events where events.id = event_bookmakers.event_id)');
dd($res);
}
}
@@ -0,0 +1,85 @@
<?php
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Console\Commands\Services\Tasks\Alarm\AlarmBookmakerFilter;
use App\Console\Commands\Services\Tasks\Alarm\AlarmFilterClient;
use App\Console\Commands\Services\Tasks\Alarm\AlarmFilterCompare;
use App\Console\Commands\Services\Tasks\Alarm\AlarmLoadOdds;
use App\Console\Commands\Services\Tasks\Alarm\AlarmMultilineSetting;
use App\Console\Commands\Services\Tasks\Alarm\AlarmSettings;
use App\Console\Commands\Services\Tasks\Alarm\AlarmStore;
use App\Models\Client;
use App\Models\EventBookmaker;
use App\Models\OddsTable;
use App\Utilities\Notice;
class GenerateAlarms
{
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('GENERATE ALARMS', 'b');
}
$oddnames = OddsTable::oddnames();
$clients = Client::get();
foreach ($clients as $client) {
if ($debug) {
Notice::note($client->name, 'b');
}
foreach ($client->sport as $sport_id) {
if ($debug) {
Notice::note('Sport: ' . $sport_id, 'b');
}
$multilines = AlarmMultilineSetting::get($sport_id);
foreach ($client->bookmaker as $client_bookmaker_id) {
$alarm_threshold = AlarmSettings::get($client_bookmaker_id, $sport_id);
$filter = AlarmBookmakerFilter::get($client_bookmaker_id, $sport_id);
$res = EventBookmaker::with('event')->where('bookmaker_id', $client_bookmaker_id)->where('sport_id', $sport_id)->get();
if ($debug) {
Notice::note('Event: ' . \count($res), 'b');
}
// $res = EventBookmaker::where('event_id', 14597944)->where('bookmaker_id', $client_bookmaker_id)->where('sport_id', $sport_id)->get();
foreach ($res as $event) {
if ($event->event->starttime > now()) {
foreach ($multilines as $multiline_id => $multiline) {
$table = $multiline['table'];
$odds = AlarmLoadOdds::get($event->event_id, $table, $oddnames[$table]);
// check if margin is > 1
$compare_odds = AlarmFilterCompare::get($odds, $filter);
// check if client has odds
$client_odds = AlarmFilterClient::get($odds, $client_bookmaker_id);
if (isset($oddnames[$table]) && isset($alarm_threshold[$multiline_id])) {
AlarmStore::get($table, $event->event_id, $oddnames[$table], $client_bookmaker_id, $alarm_threshold[$multiline_id], $compare_odds, $client_odds);
}
}
}
}
}
}
}
}
}
@@ -0,0 +1,204 @@
<?php
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Models\AlarmLevel;
use App\Models\AlarmSetting;
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\PersonalNotification;
use App\Models\Sport;
use App\Models\User;
use App\Utilities\Notice;
class GenerateSetting
{
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('GENERATE DEFAULT SETTING', 'b');
}
$clients = Client::get();
$users = User::get();
$alarm_levels = AlarmLevel::get();
$sports = Sport::getActiveSports();
/**************************************************
* 1) ALARM SETTING (client_bookmaker_id)
**************************************************/
if ($debug) {
Notice::note('1) ALARM SETTING', 'p');
}
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 ($alarm_levels as $alarm_level) {
AlarmSetting::firstOrCreate(
['client_bookmaker_id' => $client_bookmaker_id, 'sport_id' => $sport_id, 'multiline_setting_id' => $multiline_id, 'alarm_level_id' => $alarm_level->id],
['alarm_threshold' => $alarm_level->default_threshold]
);
}
}
}
}
}
/**************************************************
* 2) MULTILINE SLOTS (client_bookmaker_id)
**************************************************/
if ($debug) {
Notice::note('2) MULTILINE SLOTS', 'p');
}
$bookmaker_slots = [1 => 6, 2 => 30, 3 => 649, 4 => 126];
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]
);
}
}
}
}
}
/**************************************************
* 3) BETTYPES for USER in MONITOR (user_id)
**************************************************/
if ($debug) {
Notice::note('3) GENERATOR BETTYPES IM COMPARATORE FOR USERS', 'p');
}
foreach ($users as $user) {
$multilines = MultilineSetting::orderBy('sport_id')->get();
foreach ($multilines as $multiline) {
$is_active = in_array($multiline->id, [1, 2, 9, 10, 16, 17, 22, 23]) ? true : false;
BettypeUser::updateOrCreate(
['sport_id' => $multiline->sport_id, 'user_id' => $user->id, 'multiline_setting_id' => $multiline->id],
['is_active' => $is_active, 'sorting' => $multiline->sorting],
);
}
}
/**************************************************
* 4) COMPARING BOOKMAKER (client_bookmaker_id)
**************************************************/
if ($debug) {
Notice::note('4) COMPARING BOOKMAKER', 'p');
}
$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 ($clients as $client) {
$client_bookmakers = $client->bookmaker;
foreach ($client_bookmakers as $client_bookmaker_id) {
$i = 1;
foreach ($bookmakers_soccer as $bookmaker_id) {
$margin_threshold = $bookmaker_id == 110 ? 103 : 115;
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' => $margin_threshold, '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 ($clients 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++;
}
}
}
}
/**************************************************
* 5) ALARM NOTIFICATION SETTINGS FOR USERS (user_id)
**************************************************/
if ($debug) {
Notice::note('5) ALARM NOTIFICATION SETTINGS FOR USERS', 'p');
}
$users = User::with('client')->get();
foreach ($users as $user) {
foreach ($alarm_levels as $alarm_level) {
PersonalNotification::firstOrCreate(
['user_id' => $user->id, 'bookmaker_id' => $user->bookmaker_id, 'alarm_level_id' => $alarm_level->id],
['notify_by_system' => 0, 'notify_by_email' => 0]
);
if ($user->partner_bookmaker_id) {
PersonalNotification::firstOrCreate(
['user_id' => $user->id, 'bookmaker_id' => $user->partner_bookmaker_id, 'alarm_level_id' => $alarm_level->id],
['notify_by_system' => 0, 'notify_by_email' => 0]
);
}
}
}
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Console\Commands\Xml;
use App\Models\TxoddsMarket;
use App\Utilities\Notice;
class MarketsList
{
public static function call()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('TxoddsMarkets', 'b');
}
$url = 'https://xml2.txodds.com/feed/odds_types.php';
$data = Xml::load($url);
foreach ($data as $row) {
$market = [
'shortname' => $row->sname,
'name' => (string) $row->name,
];
TxoddsMarket::updateOrCreate(['market_id' => (int) $row->ot], $market);
}
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Console\Commands\Services\Tasks\Notification;
use App\Models\PersonalNotificationSend;
class CheckSend
{
public static function check($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, $sendtype)
{
$res = PersonalNotificationSend::where('event_id', $event_id)
->where('user_id', $user_id)
->where('bookmaker_id', $bookmaker_id)
->where('alarm_level_id', $alarm_level_id)
->where('fieldname', $fieldname)
->where($sendtype, 1)
->first();
if (! $res) {
return false;
}
return $res->id;
}
}
@@ -0,0 +1,40 @@
<?php
namespace App\Console\Commands\Services\Tasks\Notification;
use App\Models\EventBookmaker;
use App\Models\OddsTable;
use App\Models\PersonalNotification;
class LoadAlarmEvents
{
public static function load()
{
$map = OddsTable::alarm_fieldnames_by_sport();
$users = PersonalNotification::where('notify_by_system', 1)->orwhere('notify_by_email', 1)->orderby('bookmaker_id')->get();
$alarms = [];
foreach ($users as $user) {
$events = EventBookmaker::where('bookmaker_id', $user->bookmaker_id)->get();
foreach ($events as $event) {
foreach ($map[$event->sport_id] as $field) {
if ($event[$field] == $user->alarm_level_id) {
if ($user->notify_by_system) {
$alarms[$event->event_id][$user->user_id][$user->bookmaker_id]['system'][$field] = $event[$field];
}
if ($user->notify_by_email) {
$alarms[$event->event_id][$user->user_id][$user->bookmaker_id]['mail'][$field] = $event[$field];
}
}
}
}
}
return $alarms;
}
}
@@ -0,0 +1,157 @@
<?php
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Console\Commands\Services\Tasks\Notification\CheckSend;
use App\Console\Commands\Services\Tasks\Notification\LoadAlarmEvents;
use App\Mail\AlarmNotification;
use App\Models\Bookmaker;
use App\Models\Event;
use App\Models\OddsName;
use App\Models\PersonalNotificationSend;
use App\Models\User;
use App\Utilities\Notice;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
class NotifyAlarms
{
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('Notify Alarms', 'b');
}
$stored_alarms = [];
$alarms = LoadAlarmEvents::load();
foreach ($alarms as $event_id => $alarm) {
$event = Event::with('competition_group')->with('home')->with('away')->find($event_id);
foreach ($alarm as $user_id => $alarm_user) {
$user = User::find($user_id);
foreach ($alarm_user as $bookmaker_id => $alarm_user_bookmaker) {
$bookmaker = Bookmaker::find($bookmaker_id);
foreach ($alarm_user_bookmaker as $mode => $alarm_user_bookmaker_mode) {
foreach ($alarm_user_bookmaker_mode as $fieldname => $alarm_level_id) {
$bet = OddsName::where('alarm', $fieldname)->select('table', 'bettype', 'name')->first()->toArray();
$quote = DB::table($bet['table'])->where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->value($bet['name']);
switch ($mode) {
case 'mail':
$send = CheckSend::check($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, 'notify_by_email');
if (! $send) {
$send = PersonalNotificationSend::create([
'event_id' => (int) $event_id,
'user_id' => (int) $user_id,
'bookmaker_id' => (int) $bookmaker_id,
'alarm_level_id' => (int) $alarm_level_id,
'fieldname' => $fieldname,
'notify_by_mail' => 1,
]);
$stored_alarms[] = $send->id;
switch ($alarm_level_id) {
case 1:
$message = 'ALARM LEVEL '.$alarm_level_id;
break;
case 2:
$message = 'ALARM LEVEL '.$alarm_level_id;
break;
default:
$message = 'ALARM LEVEL '.$alarm_level_id;
break;
}
$tablecontent = [
['key' => 'League', 'value' => $event->competition_group->name],
['key' => 'Event', 'value' => $event->home->name.' vs '.$event->away->name],
['key' => 'Starttime', 'value' => $event->starttime],
['key' => 'Bookmaker', 'value' => $bookmaker->name],
['key' => 'Bettype', 'value' => $bet['bettype']],
['key' => 'Odd Name', 'value' => $bet['name']],
['key' => 'Value', 'value' => $quote],
['key' => 'Id', 'value' => $event_id],
];
Mail::to($user)
->send(new AlarmNotification($message, $tablecontent, $alarm_level_id));
} else {
$stored_alarms[] = $send;
}
break;
case 'system':
$send = CheckSend::check($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, 'notify_by_system');
if (! $send) {
$send = PersonalNotificationSend::create([
'event_id' => (int) $event_id,
'user_id' => (int) $user_id,
'bookmaker_id' => (int) $bookmaker_id,
'alarm_level_id' => (int) $alarm_level_id,
'fieldname' => $fieldname,
'notify_by_system' => 1,
]);
$stored_alarms[] = $send->id;
switch ($alarm_level_id) {
case 1:
$title = '<div class="text-green-500">ALARM LEVEL '.$alarm_level_id.'</div>';
break;
case 2:
$title = '<div class="text-blue-500">ALARM LEVEL '.$alarm_level_id.'</div>';
break;
default:
$title = '<div class="text-red-500">ALARM LEVEL '.$alarm_level_id.'</div>';
break;
}
$message = '<a href="/events?search='.$event_id.'"><div class="grid grid-cols-2 gap-1">';
$message .= '<div>League</div><div>'.$event->competition_group->name.'</div>';
$message .= '<div>Event</div><div>'.$event->home->name.' vs '.$event->away->name.'</div>';
$message .= '<div>Starttime</div><div>'.$event->starttime.'</div>';
$message .= '<div>Bookmaker</div><div>'.$bookmaker->name.'</div>';
$message .= '<div>Bettype</div><div>'.$bet['bettype'].'</div>';
$message .= '<div>Odd Name</div><div>'.$bet['name'].'</div>';
$message .= '<div>Value</div><div>'.$quote.'</div></div></a>';
Notification::make()
->title($title)
->icon('phosphor-envelope-duotone')
->body($message)
->sendToDatabase($user);
break;
} else {
$stored_alarms[] = $send;
}
}
}
}
}
}
}
if ($stored_alarms) {
PersonalNotificationSend::whereNotIn('id', $stored_alarms)->delete();
}
}
}
@@ -0,0 +1,62 @@
<?php
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Console\Commands\Xml;
use App\Models\OddsTable;
use App\Models\Supervisor;
use App\Utilities\Notice;
use Illuminate\Support\Facades\DB;
class TxoddsFlags
{
public static function call()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('Txodds Markets Status', 'b');
}
$lastcall = Nuh::$options['lastcall'] > time() - 600 ? '&last='.Nuh::$options['lastcall'] : '&last='.time() - 600;
/**
* SOCCER
*/
$tables = OddsTable::where('soccer', 1)->pluck('name');
$url = 'https://xml2.txodds.com/feed/boid_states.php?ident=betaid1&passwd=Dy59vpRC'.$lastcall;
$data = Xml::load($url);
if (is_array($data)) {
Supervisor::where('id', Nuh::$options['supervisor_id'])->update(['lastcall' => (int) $data['timestamp']]);
foreach ($data as $row) {
foreach ($tables as $table) {
DB::table($table)->where('offer_id', (int) $row['id'])->update(['last_updated' => $row['last_updated'], 'flags' => $row['flags']]);
}
}
}
/**
* OTHER
*/
$tables = OddsTable::where('other', 1)->pluck('name');
$url = 'https://xml2.txodds.com/feed/boid_states.php?ident=betaid2&passwd=Dy59vpRC'.$lastcall;
$data = Xml::load($url);
if (is_array($data)) {
foreach ($data as $row) {
foreach ($tables as $table) {
DB::table($table)->where('offer_id', (int) $row['id'])->update(['last_updated' => $row['last_updated'], 'flags' => $row['flags']]);
}
}
}
}
}