Ken há 1 mês atrás
pai
commit
3d8a71b181

+ 2 - 8
app/Http/Controllers/Api/Test.php

@@ -14,14 +14,8 @@ class Test extends Controller
     public function index()
     {
 
-        //  5秒更新一次
-        $list = $this->football('/odds/live');
-        foreach ($list['response'] as $item) {
-            $sport = Sport::where('data_id', $item['fixture']['id'])->first();
-            $sport->odds = json_encode($item['odds']);
-            $sport->save();
-        }
-        return $this->success($list);
+
+//        return $this->success($list);
     }
 
     function football($api, $params = [])

+ 10 - 0
app/Services/ApiFootball/Client.php

@@ -63,6 +63,16 @@ public static function leaguesSeasons($params = [])
         return static::get('leagues/seasons', $params);
     }
 
+
+    //  This endpoint returns in-play odds for fixtures in progress.
+    //  此端点会返回正在进行的比赛的实时赔率。
+    //  Update Frequency : This endpoint is updated every 5 seconds.
+    //  更新频率:此端点每 5 秒钟更新一次。
+    public static function oddsLive($params = [])
+    {
+        return static::get('odds/live', $params);
+    }
+
     public static function fixturesRounds($params = [])
     {
         return static::get('fixtures/rounds', $params);

+ 12 - 0
app/Services/FixtureService.php

@@ -8,6 +8,18 @@
 
 class FixtureService extends BaseService
 {
+
+    //  5秒更新一次
+    static function updateOdds()
+    {
+        $list = Client::oddsLive();
+        foreach ($list['response'] as $item) {
+            $sport = Sport::where('data_id', $item['fixture']['id'])->first();
+            $sport->odds = json_encode($item['odds']);
+            $sport->save();
+        }
+    }
+
     static function index()
     {
         $date = Carbon::tomorrow()->toDateString();