64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\lists\match;
|
|
|
|
use app\adminapi\lists\BaseAdminDataLists;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\match\MatchLive;
|
|
|
|
class MatchLiveLists extends BaseAdminDataLists implements ListsSearchInterface
|
|
{
|
|
public function setSearch(): array
|
|
{
|
|
return [
|
|
'=' => ['match_id', 'fetch_status'],
|
|
];
|
|
}
|
|
|
|
public function lists(): array
|
|
{
|
|
$lists = $this->buildQuery()
|
|
->field('id,match_id,title,source_url,play_url_m3u8,play_url_hd_m3u8,play_url_flv,play_url_hd_flv,fetch_status,fetch_error,last_fetch_at,next_fetch_at,create_time,update_time')
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->order('create_time', 'asc')
|
|
->order('id', 'asc')
|
|
->select()
|
|
->toArray();
|
|
|
|
foreach ($lists as &$item) {
|
|
$item['fetch_status_text'] = self::formatFetchStatus((int) ($item['fetch_status'] ?? 0));
|
|
}
|
|
unset($item);
|
|
|
|
return $lists;
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return $this->buildQuery()->count();
|
|
}
|
|
|
|
public static function formatFetchStatus(int $status): string
|
|
{
|
|
return match ($status) {
|
|
0 => '待抓取',
|
|
1 => '抓取成功',
|
|
2 => '抓取失败',
|
|
default => '未知',
|
|
};
|
|
}
|
|
|
|
protected function buildQuery()
|
|
{
|
|
$query = MatchLive::whereNull('delete_time')
|
|
->where($this->searchWhere);
|
|
|
|
$matchId = (int) ($this->params['match_id'] ?? 0);
|
|
if ($matchId <= 0) {
|
|
$query->where('match_id', 0);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
}
|