Files
nuhodds_fi4/app/Console/Commands/Grapper/Logifuture/Soccer.php
T

198 lines
6.2 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\Logifuture;
use App\Console\Commands\Nuh;
use App\Models\Odds3way;
use App\Models\OddsDc;
use App\Models\OddsGgng;
use App\Models\OddsTotal;
use App\Models\OddsTq;
use App\Utilities\Margin;
class Soccer
{
public static function get(&$event, $match)
{
$_3way = [];
$_total = [];
$_ggng = [];
$_dc = [];
$_tq = [];
foreach ($match['odds'] as $name => $value) {
switch ($name) {
case 'S_1X2_1':
$_3way['h3w'] = number_format($value, 2);
break;
case 'S_1X2_X':
$_3way['d3w'] = number_format($value, 2);
break;
case 'S_1X2_2':
$_3way['a3w'] = number_format($value, 2);
break;
case 'S_OU@2.5_O':
$_total['over'] = number_format($value, 2);
break;
case 'S_OU@2.5_U':
$_total['under'] = number_format($value, 2);
break;
case 'S_GGNG_Y':
$_ggng['gg'] = number_format($value, 2);
break;
case 'S_GGNG_N':
$_ggng['ng'] = number_format($value, 2);
break;
// case 'S_DNB_1':
// break;
// case 'S_DNB_2':
// break;
case 'S_DC_12':
$_dc['dc12'] = number_format($value, 2);
break;
case 'S_DC_1X':
$_dc['dc1x'] = number_format($value, 2);
break;
case 'S_DC_X2':
$_dc['dcx2'] = number_format($value, 2);
break;
case 'S_12QUALIFY_1':
$_tq['htq'] = number_format($value, 2);
break;
case 'S_12QUALIFY_2':
$_tq['atq'] = number_format($value, 2);
break;
}
}
$base = [];
$base['event_id'] = $event['id'];
$base['bookmaker_id'] = $event['bookmaker_id'];
$base['sport_id'] = $event['sport_id'];
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event['event_id'];
$base['flags'] = 1;
// 1x2
if (\count($_3way) == 3) {
$_3way['margin'] = (float) Margin::calculate($_3way, 1);
$_3way = array_merge($_3way, $base);
$res = Odds3way::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds3way::create($_3way);
} else {
$res->h3w = number_format($_3way['h3w'], 2);
$res->d3w = number_format($_3way['d3w'], 2);
$res->a3w = number_format($_3way['a3w'], 2);
$res->flags = 1;
$res->margin = $_3way['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// OU
if (\count($_total) == 2) {
$_total['margin'] = (float) Margin::calculate($_total, 1);
$_total['total'] = 2.5;
$_total['active_spread'] = 1;
$_total = array_merge($_total, $base);
$res = OddsTotal::where('event_id', $event['id'])
->where('bookmaker_id', $event['bookmaker_id'])
->where('total', $_total['total'])
->first();
if (! $res) {
OddsTotal::create($_total);
} else {
$res->over = number_format($_total['over'], 2);
$res->under = number_format($_total['under'], 2);
$res->flags = 1;
$res->margin = $_total['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// GG NG
if (\count($_ggng) == 2) {
$_ggng['margin'] = (float) Margin::calculate($_ggng, 1);
$_ggng = array_merge($_ggng, $base);
$res = OddsGgng::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
OddsGgng::create($_ggng);
} else {
$res->gg = number_format($_ggng['gg'], 2);
$res->ng = number_format($_ggng['ng'], 2);
$res->flags = 1;
$res->margin = $_ggng['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// DC
if (\count($_dc) == 3) {
$_dc['margin'] = (float) Margin::calculate($_dc, 1);
$_dc = array_merge($_dc, $base);
$res = OddsDc::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
OddsDc::create($_dc);
} else {
$res->dc1x = number_format($_dc['dc1x'], 2);
$res->dc12 = number_format($_dc['dc12'], 2);
$res->dcx2 = number_format($_dc['dcx2'], 2);
$res->flags = 1;
$res->margin = $_dc['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// TQ
if (\count($_tq) == 2) {
$_tq['margin'] = (float) Margin::calculate($_tq, 1);
$_tq = array_merge($_tq, $base);
$res = OddsTq::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
OddsTq::create($_tq);
} else {
$res->htq = number_format($_tq['htq'], 2);
$res->atq = number_format($_tq['atq'], 2);
$res->flags = 1;
$res->margin = $_tq['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}