request->params([ ['template_id', 0], ['user_id', 0], ['user_type', ''], ['status', ''], ['page', 1], ['limit', 20] ]); return success((new DocumentGenerateService())->getPage($data)); } /** * 获取生成记录详情 * @param int $id * @return Response */ public function info(int $id): Response { return success((new DocumentGenerateService())->getInfo($id)); } /** * 生成文档 * @return Response */ public function generate(): Response { $data = $this->request->params([ ['template_id', 0], ['user_type', 1], ['user_id', 0], ['fill_data', []], ['output_filename', ''] ]); $this->validate($data, 'app\validate\document\DocumentGenerate.generate'); $result = (new DocumentGenerateService())->generate($data); return success('GENERATE_SUCCESS', $result); } /** * 重新生成文档 * @param int $id * @return Response */ public function regenerate(int $id): Response { $result = (new DocumentGenerateService())->regenerate($id); return success('REGENERATE_SUCCESS', $result); } /** * 下载生成的文档 * @param int $id * @return Response */ public function download(int $id): Response { $result = (new DocumentGenerateService())->download($id); if (!$result['success']) { return fail($result['error']); } return download($result['file_path'], $result['file_name']); } /** * 删除生成记录 * @param int $id * @return Response */ public function del(int $id): Response { (new DocumentGenerateService())->del($id); return success('DELETE_SUCCESS'); } /** * 批量删除生成记录 * @return Response */ public function batchDel(): Response { $ids = $this->request->param('ids', []); if (empty($ids)) { return fail('请选择要删除的记录'); } (new DocumentGenerateService())->batchDel($ids); return success('BATCH_DELETE_SUCCESS'); } /** * 获取生成统计信息 * @return Response */ public function getStats(): Response { $templateId = $this->request->param('template_id', 0); return success((new DocumentGenerateService())->getStats($templateId)); } /** * 预览文档数据 * @return Response */ public function preview(): Response { $data = $this->request->params([ ['template_id', 0], ['fill_data', []] ]); $this->validate($data, 'app\validate\document\DocumentGenerate.preview'); return success((new DocumentGenerateService())->preview($data['template_id'], $data['fill_data'])); } }