From dbdb418e151944f763325b8bb16c7f111456e238 Mon Sep 17 00:00:00 2001 From: hajimi Date: Sun, 21 Jun 2026 11:32:08 +0800 Subject: [PATCH] feat: add match live service helpers --- qa/backend/test_match_live_backend_static.php | 28 +++++++++ .../common/service/match/MatchLiveService.php | 63 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 qa/backend/test_match_live_backend_static.php create mode 100644 server/app/common/service/match/MatchLiveService.php diff --git a/qa/backend/test_match_live_backend_static.php b/qa/backend/test_match_live_backend_static.php new file mode 100644 index 0000000..7668772 --- /dev/null +++ b/qa/backend/test_match_live_backend_static.php @@ -0,0 +1,28 @@ +order('create_time', 'asc') + ->order('id', 'asc') + ->find(); + + MatchEvent::where('id', $matchId)->update([ + 'live_url' => $row ? (string) $row->source_url : '', + 'update_time' => time(), + ]); + } + + public static function getLiveListForApi(int $matchId): array + { + $rows = MatchLive::where('match_id', $matchId) + ->order('create_time', 'asc') + ->order('id', 'asc') + ->select() + ->toArray(); + + foreach ($rows as &$row) { + $row['stream_options'] = self::buildStreamOptions($row); + $row['default_play_url'] = $row['stream_options'][0]['url'] ?? ''; + } + unset($row); + + return $rows; + } + + public static function buildStreamOptions(array $row): array + { + $definitions = [ + ['label' => 'M3U8', 'field' => 'play_url_m3u8'], + ['label' => 'HD M3U8', 'field' => 'play_url_hd_m3u8'], + ['label' => 'FLV', 'field' => 'play_url_flv'], + ['label' => 'HD FLV', 'field' => 'play_url_hd_flv'], + ]; + + $options = []; + foreach ($definitions as $definition) { + $url = trim((string) ($row[$definition['field']] ?? '')); + if ($url === '') { + continue; + } + $options[] = [ + 'label' => $definition['label'], + 'url' => $url, + ]; + } + + return $options; + } +}