*/ public function page(Request $request): array { $filters = $this->filters($request); $page = max((int) $request->query('page', 1), 1); $perPage = 50; try { $result = $this->repository->paginate($filters, $page, $perPage); $options = $this->repository->filterOptions(); return [ 'processRows' => new LengthAwarePaginator( $result['data'], $result['total'], $perPage, $page, ['path' => $request->url(), 'query' => $request->except('page')], ), 'filters' => $filters, 'summary' => $result['summary'], 'months' => $options['months'], 'documentTypes' => $options['document_types'], 'statuses' => $options['statuses'], 'mirrorStatus' => $result['status'], 'mirrorSyncedAt' => $result['last_synced_at'], 'scope' => $result['scope'], 'error' => null, ]; } catch (Throwable $exception) { report($exception); return [ 'processRows' => new LengthAwarePaginator([], 0, $perPage, $page, [ 'path' => $request->url(), 'query' => $request->except('page'), ]), 'filters' => $filters, 'summary' => [ 'rows' => 0, 'approvals' => 0, 'amount_total' => 0.0, 'bank_amount_total' => 0.0, ], 'months' => [], 'documentTypes' => [], 'statuses' => [], 'mirrorStatus' => 'unavailable', 'mirrorSyncedAt' => null, 'scope' => $this->repository->scope(), 'error' => '流程明细镜像尚未完成导入,请稍后重试。', ]; } } /** @return array */ private function filters(Request $request): array { $month = trim((string) $request->query('month', '')); $status = trim((string) $request->query('status', '')); return [ 'month' => preg_match('/^\d{4}-\d{2}$/', $month) === 1 ? $month : '', 'document_type' => mb_substr(trim((string) $request->query('document_type', '')), 0, 100), 'status' => mb_substr($status, 0, 20), 'business_id' => mb_substr(trim((string) $request->query('business_id', '')), 0, 32), 'originator_name' => mb_substr(trim((string) $request->query('originator_name', '')), 0, 100), 'keyword' => mb_substr(trim((string) $request->query('keyword', '')), 0, 100), ]; } }