0, 'NS' => 0, '1H' => 1, 'HT' => 1, '2H' => 1, 'ET' => 1, 'BT' => 1, 'P' => 1, 'SUSP' => 1, 'INT' => 1, 'FT' => 2, 'AET' => 2, 'PEN' => 2, 'PST' => 3, 'CANC' => 4, 'ABD' => 4, 'AWD' => 4, 'WO' => 4, 'LIVE' => 1, ]; /** * 命令描述 * * @var string */ protected $description = '当天会去更新明天的赛事(23:59:00执行一次)'; /** * 执行命令 * * @return int */ public function handle() { $this->info('开始执行统计比赛数据任务...'); // $data = SportClientService::fixtures(['id' => '1506018']); // file_put_contents('fixtures-1506018.json', json_encode($data)); // die; $this->fixtures(); $this->info('结束执行统计比赛数据任务'); } public function initOdds(){ $page = 1; $limit = 10; while (true) { $list = SportModel::where('odds','<>', null)->forPage($page, $limit)->get()->toArray(); if (empty($list)) { break; } echo $page.PHP_EOL; foreach($list as $item) { $odds = json_decode($item['odds'], true); foreach($odds as $odd) { $odd_id = $odd['id']; $odd_name = $odd['name']; $info = DB::table('sport_odds')->where('odd_id',$odd_id)->where('odd_name_en',$odd_name)->first(); if ($info && (!$info->odd_name || $odd_name != $info->odd_name_en)) { DB::table('sport_odds')->where('id', $info->id)->update([ 'odd_name_en' => $odd_name, 'odd_name' => $this->getZhName($odd_name), ]); echo '更新数据:'.$odd_id.'-'.$odd_name.PHP_EOL; } elseif (!$info) { DB::table('sport_odds')->insert([ 'odd_id' => $odd_id, 'odd_name_en' => $odd_name, 'odd_name' => $this->getZhName($odd_name), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); echo '插入数据:'.$odd_id.'-'.$odd_name.PHP_EOL; } } } $page++; } } public function getZhName ($name) { $betting_terms = [ "Match Winner" => "全场胜负", "Home/Away" => "主胜/客胜", "Second Half Winner" => "下半场胜负", "Asian Handicap" => "亚洲让球盘", "Goals Over/Under" => "全场大小球", "Goals Over/Under First Half" => "上半场大小球", "Goals Over/Under - Second Half" => "下半场大小球", "HT/FT Double" => "半场+全场双猜", "Both Teams Score" => "双方均进球", "Handicap Result" => "让球结果", "Exact Score" => "精确比分", "Correct Score - First Half" => "上半场精确比分", "Correct Score - Second Half" => "下半场精确比分", "Double Chance" => "双选胜平负", "First Half Winner" => "上半场胜负", "Team To Score First" => "首支进球球队", "Team To Score Last" => "最后进球球队", "Win Both Halves" => "上下半场均获胜", "Total - Home" => "主队总进球数", "Total - Away" => "客队总进球数", "Both Teams Score - First Half" => "上半场双方均进球", "Both Teams To Score - Second Half" => "下半场双方均进球", "Odd/Even" => "总进球数奇偶", "Odd/Even - First Half" => "上半场进球奇偶", "Home Team Exact Goals Number" => "主队精确进球数", "Away Team Exact Goals Number" => "客队精确进球数", "Results/Both Teams Score" => "赛果+双方进球", "Odd/Even - Second Half" => "下半场进球奇偶", "Clean Sheet - Home" => "主队零封", "Clean Sheet - Away" => "客队零封", "Win to Nil - Home" => "主队零封获胜", "Win to Nil - Away" => "客队零封获胜", "Highest Scoring Half" => "进球更多的半场", "Handicap Result - First Half" => "上半场让球结果", "Asian Handicap First Half" => "上半场亚洲让球盘", "Double Chance - First Half" => "上半场双选胜平负", "Win To Nil" => "零封获胜", "Home Odd/Even" => "主队进球奇偶", "Away Odd/Even" => "客队进球奇偶", "To Win Either Half" => "赢得任意半场", "Result/Total Goals" => "赛果+总进球数", "First 10 min Winner" => "前10分钟胜负", "Corners Over Under" => "角球大小", "Home Team Total Goals(1st Half)" => "主队上半场总进球", "Away Team Total Goals(1st Half)" => "客队上半场总进球", "Home Team Total Goals(2nd Half)" => "主队下半场总进球", "Away Team Total Goals(2nd Half)" => "客队下半场总进球", "Draw No Bet (1st Half)" => "上半场让球平注", "European Handicap (2nd Half)" => "下半场欧洲让球", "Draw No Bet (2nd Half)" => "下半场让球平注", "Total Goals/Both Teams To Score" => "总进球+双方进球", "Home Corners Over/Under" => "主队角球大小", "Away Corners Over/Under" => "客队角球大小", "Total Corners (3 way)" => "总角球三路", "1x2 - 60 minutes" => "60分钟胜平负", "1x2 - 30 minutes" => "30分钟胜平负", "First Team to Score (3 way) 1st Half" => "上半场首支进球球队(三路)", "Total Corners (1st Half)" => "上半场总角球", "Corners. Odd/Even" => "角球奇偶", "RTG_H1" => "上半场进球数(简写)", "Cards Over/Under" => "黄牌大小", "To Qualify" => "晋级球队", "Goal Line" => "进球线", "Goal Line (1st Half)" => "上半场进球线", "Home team will score in both halves" => "主队上下半场均进球", "Away team will score in both halves" => "客队上下半场均进球", "Last Corner" => "最后角球", "How many goals will Away Team score?" => "客队进球数", "Asian Corners" => "亚洲让角球", "Match Corners" => "全场角球", "Final Score" => "最终比分", "Match Goals" => "全场进球", "Home Team Score a Goal (2nd Half)" => "主队下半场进球", "Result / Both Teams To Score" => "赛果/双方进球", "To Win 2nd Half" => "赢下半场", "Over/Under Line" => "大小球盘口", "3-Way Handicap" => "三路让球", "Away Team Goals" => "客队进球", "Both Teams To Score (2nd Half)" => "下半场双方进球", "Which team will score the 5th corner? (2 Way)" => "第5个角球归属(二路)", "Race to the 9th corner?" => "先得9个角球", "Race to the 7th corner?" => "先得7个角球", "Draw No Bet" => "让球平注", "Home Team Goals" => "主队进球", "Total Corners" => "总角球", "Fulltime Result" => "全场赛果", "Race to the 5th corner?" => "先得5个角球", "Last Team to Score (3 way)" => "最后进球球队(三路)", "Which team will score the 2nd goal?" => "第二球归属球队", "Home Team Clean Sheet" => "主队零封", "How many goals will Home Team score?" => "主队进球数", "Goals Odd/Even" => "进球奇偶", "Both Teams to Score" => "双方均进球", "Away Team Score a Goal (2nd Half)" => "客队下半场进球", "Which team will score the 4th goal?" => "第四球归属球队", "Which team will score the 7th corner? (2 Way)" => "第7个角球归属(二路)", ]; if (isset($betting_terms[$name])) { return $betting_terms[$name]; } return ''; } /** * 获取指定日期的所有赛事 * * @return array */ public function fixtures() { $date = Carbon::tomorrow()->toDateString(); // $date = '2026-03-07'; $data = SportClientService::fixtures(['date' => $date]); // $data = SportClientService::fixtures(['live' => 'all']); $data = $data['response']; $tableData = []; $status = $this->short_status; foreach ($data as $item) { $home_statistics = !empty($item['statistics']) ? $item['statistics'][0]['statistics'] : ''; $away_statistics = !empty($item['statistics']) ? $item['statistics'][1]['statistics'] : ''; $sport_data = [ 'data_id' => $item['fixture']['id'], 'home_team_id' => $item['teams']['home']['id'], 'home_team_en' => $item['teams']['home']['name'], 'home_team' => lang($item['teams']['home']['name']), 'home_team_logo' => $item['teams']['home']['logo'], 'guest_team_id' => $item['teams']['away']['id'], 'guest_team_en' => $item['teams']['away']['name'], 'guest_team' => lang($item['teams']['away']['name']), 'guest_team_logo' => $item['teams']['away']['logo'], 'half_score' => "{$item['score']['halftime']['home']}-{$item['score']['halftime']['away']}", 'rbt' => $item['fixture']['timestamp'], 'score' => isset($item['score']['fulltime']) ? "{$item['score']['fulltime']['home']}-{$item['score']['fulltime']['away']}":'-', 'league' => lang($item['league']['name']), 'league_en' => $item['league']['name'], 'state' => $status[$item['fixture']['status']['short']],//比赛状态:0未开始1进行中2已完场3延期4取消 'game_time' => $item['fixture']['timestamp'], 'status' => 1, 'updated_at' => now(), 'home_statistics' => $home_statistics, 'away_statistics' => $away_statistics, ]; $sport_data['score'] = $sport_data['score'] == '-' ? '' : $sport_data['score']; $sport_data['half_score'] = $sport_data['half_score'] == '-' ? '' : $sport_data['half_score']; if (!SportModel::where('data_id', $item['fixture']['id'])->exists()) { $sport_data['created_at'] = now(); $tableData[] = $sport_data; } else { SportModel::where('data_id', $item['fixture']['id'])->update($sport_data); } //比赛结束,插入比赛事件 if ($sport_data['state'] == 2 && !empty($item['events'])) { foreach($item['events'] as $event) { SportEvent::create([ 'data_id' => $item['fixture']['id'], 'type' => $event['type'], 'time_elapsed' => $event['time']['elapsed'], 'time' => json_encode($event['time']), 'detail' => $event['detail'], 'player' => $event['player'] ? json_encode($event['player']) : $event['player'], 'team_id' => $event['team']['id'], 'comments' => $event['comments'], 'assist' => $event['assist'] ? json_encode($event['assist']) : $event['assist'], ]); } } } if ($tableData) { SportModel::insert($tableData); } return $tableData; } }