'like', 'recon_id' => '=', 'store_id' => '=', 'status' => '=', ]; /** 结算表列表 */ #[GetRoute(authorize: 'query')] public function query(Request $request): JsonResponse { $params = $request->all(); $pageSize = $params['pageSize'] ?? 10; $data = $this->buildSearch( $params, SettlementModel::query()->with(['store:id,name', 'recon:id,recon_no,title']) ) ->orderBy('id', 'desc') ->paginate($pageSize) ->toArray(); return $this->success($data); } /** 结算表详情 */ #[GetRoute(route: '/{id}', authorize: 'query', where: ['id' => '[0-9]+'])] public function detail(int $id): JsonResponse { $settlement = SettlementModel::with(['store:id,name', 'recon:id,recon_no,title', 'operator:id,nickname']) ->find($id); if (empty($settlement)) { throw new RepositoryException('结算表不存在'); } return $this->success($settlement->toArray()); } /** * D10 导出下载:?format=xlsx|pdf,成功后回写 file_path 存档标记 */ #[GetRoute(route: '/{id}/download', authorize: 'download', where: ['id' => '[0-9]+'])] public function download(int $id, Request $request): Response { $settlement = SettlementModel::find($id); if (empty($settlement)) { throw new RepositoryException('结算表不存在'); } $format = (string) $request->query('format', ExportService::FORMAT_XLSX); $response = app(ExportService::class)->download('settlement', $settlement, $format); // 同步流式下载不落盘,file_path 仅作存档标记(后续切队列导出时替换为真实文件路径) $extension = $format === ExportService::FORMAT_PDF ? 'pdf' : 'xlsx'; $settlement->file_path = 'exports/settlement/' . $settlement->settlement_no . '.' . $extension; $settlement->save(); return $response; } }