['action', 'status', 'trigger_type', 'source'], '%like%' => ['task_name', 'task_key'], 'between_time' => 'create_time', ]; } public function lists(): array { $lists = CrawlerTaskLog::field('id,task_key,task_name,action,cron_expression,source,container_id,status,trigger_type,output,error_message,elapsed,started_at,finished_at,create_time,update_time') ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->order('id', 'desc') ->select() ->toArray(); foreach ($lists as &$item) { $item = self::formatItem($item); } return $lists; } public function count(): int { return CrawlerTaskLog::where($this->searchWhere)->count(); } public static function formatItem(array $item): array { $item['status_text'] = match ((int) ($item['status'] ?? 0)) { 0 => '执行中', 1 => '成功', 2 => '失败', 3 => '已跳过', default => '未知', }; $item['trigger_type_text'] = ((int) ($item['trigger_type'] ?? 1)) === 2 ? '手动' : '自动'; foreach (['started_at', 'finished_at', 'create_time', 'update_time'] as $field) { $value = $item[$field] ?? 0; $item[$field . '_text'] = self::formatTime($value); } $item['output_preview'] = mb_substr((string) ($item['output'] ?? ''), 0, 120); return $item; } private static function formatTime($value): string { if (empty($value)) { return '-'; } return is_numeric($value) ? date('Y-m-d H:i:s', (int) $value) : (string) $value; } }