user()->sport_id); $has_active_spread = OddsTable::where('name', $table)->value('has_active_spread'); if ($has_active_spread) { $clients = DB::table($table) ->where('bookmaker_id', auth()->user()->bookmaker_id) ->where('active_spread', 1) ->get(); $comparing = DB::table($table) ->where('bookmaker_id', $compare_bookmaker_id) ->where('active_spread', 1) ->get(); } else { // $clients = DB::table($table)->whereIn('bookmaker_id', [auth()->user()->bookmaker_id, $compare_bookmaker_id])->get(); $clients = DB::table($table) ->where('bookmaker_id', auth()->user()->bookmaker_id) ->get(); $comparing = DB::table($table) ->where('bookmaker_id', $compare_bookmaker_id) ->get(); } $event_ids = []; foreach ($clients as $client) { $row1 = get_object_vars($client); foreach ($comparing as $compare) { $row2 = get_object_vars($compare); if ($row1['event_id'] == $row2['event_id']) { switch ($target) { case 'Favorit': $bk = 100; $co = 100; foreach ($fields[$table] as $field) { if ($row1[$field] < $bk) { $bk = $row1[$field]; } if ($row2[$field] < $co) { $co = $row2[$field]; } } switch ($mode) { case 'lte': if ($bk > 1 && $co > 1 && $bk <= $co) { $event_ids[] = $row1['event_id']; } break; case 'gte': if ($bk > 1 && $co > 1 && $bk >= $co) { $event_ids[] = $row1['event_id']; } break; } break; case 'Margin': switch ($mode) { case 'gte': if ($row1['margin'] >= $row2['margin']) { $event_ids[] = $row1['event_id']; } break; case 'lt': if ($row1['margin'] < $row2['margin']) { $event_ids[] = $row1['event_id']; } break; } break; case 'X': if ($row1['d3w'] < $row2['d3w']) { $event_ids[] = $row1['event_id']; } break; } } } } return array_unique($event_ids); } }