63 lines
2.5 KiB
PHP
63 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\TxOdds\Odds\Tools;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ActiveSpread
|
|
{
|
|
public static $collector = [];
|
|
|
|
public static $event_id = 0;
|
|
|
|
public static $provider_id = 0;
|
|
|
|
public static function collect($odds, $bettype)
|
|
{
|
|
if ($odds['event_id'] != self::$event_id) {
|
|
self::$event_id = $odds['event_id'];
|
|
self::$provider_id = $odds['provider_id'];
|
|
self::$collector = [];
|
|
}
|
|
if (! isset(self::$collector[$bettype][$odds['bookmaker_id']]['difference'])) {
|
|
self::$collector[$bettype][$odds['bookmaker_id']]['difference'] = $odds['difference'];
|
|
if (isset($odds['handicap'])) {
|
|
self::$collector[$bettype][$odds['bookmaker_id']]['active_spread'] = $odds['handicap'];
|
|
} else {
|
|
self::$collector[$bettype][$odds['bookmaker_id']]['active_spread'] = $odds['total'];
|
|
}
|
|
} elseif ($odds['difference'] < self::$collector[$bettype][$odds['bookmaker_id']]['difference']) {
|
|
self::$collector[$bettype][$odds['bookmaker_id']]['difference'] = $odds['difference'];
|
|
if (isset($odds['handicap'])) {
|
|
self::$collector[$bettype][$odds['bookmaker_id']]['active_spread'] = $odds['handicap'];
|
|
} else {
|
|
self::$collector[$bettype][$odds['bookmaker_id']]['active_spread'] = $odds['total'];
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function set()
|
|
{
|
|
foreach (self::$collector as $table => $value) {
|
|
DB::table($table)->where('event_id', self::$event_id)->where('provider_id', self::$provider_id)->update(['active_spread' => 0]);
|
|
}
|
|
foreach (self::$collector as $table => $bookmaker) {
|
|
foreach ($bookmaker as $bookmaker_id => $values) {
|
|
if (in_array($table, ['odds_points', 'odds_points_ht', 'odds_points_q1'])) {
|
|
DB::table($table)
|
|
->where('event_id', self::$event_id)
|
|
->where('bookmaker_id', $bookmaker_id)
|
|
->where('handicap', $values['active_spread'])
|
|
->update(['active_spread' => 1]);
|
|
} else {
|
|
DB::table($table)
|
|
->where('event_id', self::$event_id)
|
|
->where('bookmaker_id', $bookmaker_id)
|
|
->where('total', $values['active_spread'])
|
|
->update(['active_spread' => 1]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|