toArray(); } public static function add(array $params): bool { try { $now = time(); MatchLive::create([ 'match_id' => (int) $params['match_id'], 'title' => trim((string) $params['title']), 'source_url' => trim((string) $params['source_url']), 'fetch_status' => 0, 'fetch_error' => '', 'last_fetch_at' => 0, 'next_fetch_at' => $now, 'create_time' => $now, 'update_time' => $now, ]); MatchLiveService::syncLegacyLiveUrl((int) $params['match_id']); return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } public static function edit(array $params): bool { try { $live = MatchLive::findOrEmpty($params['id']); if ($live->isEmpty()) { self::setError('直播线路不存在'); return false; } $oldMatchId = (int) $live->match_id; $newMatchId = (int) $params['match_id']; $now = time(); $sourceUrl = trim((string) $params['source_url']); $sourceUrlChanged = $sourceUrl !== trim((string) $live->source_url); $saveData = [ 'match_id' => $newMatchId, 'title' => trim((string) $params['title']), 'source_url' => $sourceUrl, 'update_time' => $now, ]; if ($sourceUrlChanged) { $saveData['play_url_m3u8'] = ''; $saveData['play_url_hd_m3u8'] = ''; $saveData['play_url_flv'] = ''; $saveData['play_url_hd_flv'] = ''; $saveData['fetch_status'] = 0; $saveData['fetch_error'] = ''; $saveData['last_fetch_at'] = 0; $saveData['next_fetch_at'] = $now; } $live->save($saveData); if ($oldMatchId > 0 && $oldMatchId !== $newMatchId) { MatchLiveService::syncLegacyLiveUrl($oldMatchId); } MatchLiveService::syncLegacyLiveUrl($newMatchId); return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } public static function delete(array $params): bool { try { $live = MatchLive::findOrEmpty($params['id']); if ($live->isEmpty()) { self::setError('直播线路不存在'); return false; } $matchId = (int) $live->match_id; $live->delete(); MatchLiveService::syncLegacyLiveUrl($matchId); return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } }