diff --git a/composer.json b/composer.json index e0a615a..a789983 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,9 @@ "zoujingli/think-plugs-center": "^1.0", "zoujingli/think-plugs-account": "^1.0", "ext-json": "*", - "phpoffice/phpspreadsheet": "^4.0" + "topthink/think-orm": "^3.0", + "phpoffice/phpspreadsheet": "^4.0", + "phpoffice/phpword": "^1.3" }, "repositories": { "jerryyan/think-plugs-cms": { diff --git a/plugs/think-plugs-ticket/src/controller/Ticket.php b/plugs/think-plugs-ticket/src/controller/Ticket.php index cf021ce..6bb7d3b 100644 --- a/plugs/think-plugs-ticket/src/controller/Ticket.php +++ b/plugs/think-plugs-ticket/src/controller/Ticket.php @@ -3,6 +3,8 @@ namespace plugin\ticket\controller; use app\custom\model\CustomMessage; +use PhpOffice\PhpWord\Settings; +use PhpOffice\PhpWord\TemplateProcessor; use plugin\inspection\model\InspectionStaff; use plugin\ticket\model\ApprovalInstance; use plugin\ticket\model\ApprovalProcess; @@ -507,4 +509,46 @@ class Ticket extends Controller $this->fetch(); } } + + public function repair_ticket_create_template() + { + $data = $this->_vali([ + 'id.require'=>'请指定工单ID!', + ]); + $ticket = TicketTicket::query()->where('id', '=', $data['id'])->findOrEmpty(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + $view_content = $ticket->content; + if ($ticket->source_type != 1) { + $views = $ticket->views; + if (empty($views) || sizeof($views) == 0) { + $this->error("该工单未被核验"); + } + $view_content = $views[0]->content; + } + $template = new TemplateProcessor(public_path()."/tpl.docx"); + $template->setValue('today', date('Y/m/d')); + $template->setValue('ticket_address', $ticket->ticket_region.$ticket->ticket_address); + $template->setValue('ticket_gc_content', $ticket->gc_content); + $template->setValue('ticket_zf_content', $ticket->zf_content); + $template->setValue('ticket_ys_content', $ticket->ys_content); + $template->setValue('ticket_work_days', $ticket->work_days); + $template->setValue('ticket_view_content', $view_content); + + $tempFile = tempnam(sys_get_temp_dir(), 'phpword_'); + $template->saveAs($tempFile); + + // 2. 设置下载头 + $downloadFilename = 'output.docx'; // 用户下载时显示的文件名 + header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + header("Content-Disposition: attachment; filename=\"" . basename($downloadFilename) . "\""); + header("Content-Length: " . filesize($tempFile)); + header("Content-Transfer-Encoding: binary"); + @readfile($tempFile); + + // 3. 删除临时文件(可选) + unlink($tempFile); + exit(); + } } \ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/view/common/ticket_flow.html b/plugs/think-plugs-ticket/src/view/common/ticket_flow.html index 8d297bd..1be2cf1 100644 --- a/plugs/think-plugs-ticket/src/view/common/ticket_flow.html +++ b/plugs/think-plugs-ticket/src/view/common/ticket_flow.html @@ -195,7 +195,10 @@ {if $ticket.repairs && sizeof($ticket.repairs) > 0}