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