feat: match detail live room matching
This commit is contained in:
@@ -28,6 +28,47 @@ class MatchLiveService
|
||||
return $liveMap[$matchId] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取赛事可用的直播间:优先返回已绑定赛事,未绑定的房间则按标题中的主客队名称补充匹配。
|
||||
*/
|
||||
public static function getMatchedLiveListForApi(array $match): array
|
||||
{
|
||||
$matchId = (int) ($match['id'] ?? 0);
|
||||
$liveList = $matchId > 0 ? self::getLiveListForApi($matchId) : [];
|
||||
$knownLiveIds = array_flip(array_filter(array_map(
|
||||
static fn(array $item): int => (int) ($item['id'] ?? 0),
|
||||
$liveList
|
||||
)));
|
||||
|
||||
$homeTeam = trim((string) ($match['home_team'] ?? ''));
|
||||
$awayTeam = trim((string) ($match['away_team'] ?? ''));
|
||||
if ($homeTeam === '' || $awayTeam === '') {
|
||||
return $liveList;
|
||||
}
|
||||
|
||||
$homeKeyword = '%' . addcslashes($homeTeam, '\\%_') . '%';
|
||||
$awayKeyword = '%' . addcslashes($awayTeam, '\\%_') . '%';
|
||||
$matchedRows = MatchLive::where('fetch_status', 1)
|
||||
->whereNull('delete_time')
|
||||
->where('title', 'like', $homeKeyword)
|
||||
->where('title', 'like', $awayKeyword)
|
||||
->order('create_time', 'asc')
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($matchedRows as $row) {
|
||||
$liveId = (int) ($row['id'] ?? 0);
|
||||
if ($liveId <= 0 || isset($knownLiveIds[$liveId])) {
|
||||
continue;
|
||||
}
|
||||
$liveList[] = self::decorateLiveRow($row);
|
||||
$knownLiveIds[$liveId] = true;
|
||||
}
|
||||
|
||||
return $liveList;
|
||||
}
|
||||
|
||||
public static function getLiveMapForApi(array $matchIds): array
|
||||
{
|
||||
$matchIds = array_values(array_unique(array_filter(array_map('intval', $matchIds))));
|
||||
@@ -44,8 +85,7 @@ class MatchLiveService
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as &$row) {
|
||||
$row['stream_options'] = self::buildStreamOptions($row);
|
||||
$row['default_play_url'] = self::resolveDefaultPlayUrl($row);
|
||||
$row = self::decorateLiveRow($row);
|
||||
$matchId = (int) ($row['match_id'] ?? 0);
|
||||
if ($matchId <= 0) {
|
||||
continue;
|
||||
@@ -57,6 +97,14 @@ class MatchLiveService
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected static function decorateLiveRow(array $row): array
|
||||
{
|
||||
$row['stream_options'] = self::buildStreamOptions($row);
|
||||
$row['default_play_url'] = self::resolveDefaultPlayUrl($row);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function buildStreamOptions(array $row): array
|
||||
{
|
||||
$definitions = [
|
||||
|
||||
Reference in New Issue
Block a user