Ken 1 月之前
父节点
当前提交
73a2723f64
共有 1 个文件被更改,包括 11 次插入18 次删除
  1. 11 18
      app/Services/FixtureService.php

+ 11 - 18
app/Services/FixtureService.php

@@ -10,6 +10,7 @@
 class FixtureService extends BaseService
 {
 
+    //  赛前赔率
     static function odds($id)
     {
         $key = "odds_{$id}";
@@ -23,27 +24,19 @@ static function odds($id)
     }
 
     /**
-     * 将进行中的赛事 更新赔率
+     * 比赛中的赔率
      * 5秒更新一次
-     * @return void
      */
-    static function updateOdds()
+    static function oddsLive($id)
     {
-        $list = Client::oddsLive();
-        foreach ($list['response'] as $item) {
-            $sport = Sport::where('data_id', $item['fixture']['id'])->first();
-            $sport->odds = json_encode($item['odds']);
-            $sport->state = 1;
-            $score = "";
-            $score .= $item['teams']['home']['goals'];
-            $score .= "-";
-            $score .= $item['teams']['away']['goals'];
-            if ($item['fixture']['status']['long'] == 'First Half') {
-                $sport->half_score = $score;
-            }
-            $sport->score = $score;
-            $sport->save();
-        }
+        $key = "odds_live_{$id}";
+        $odds = Cache::get($key, null);
+        if ($odds) return json_decode($odds, true);
+        $res = Client::oddsLive(['fixture' => $id]);
+        if (count($res['response']) <= 0) return [];
+        $res = $res['response'][0];
+        Cache::put($key, $res, now()->addHours(3));
+        return $res;
     }
 
     /**