|
|
@@ -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;
|
|
|
}
|
|
|
|
|
|
/**
|