导出工单

This commit is contained in:
2025-03-30 18:50:00 +08:00
parent bae1f861ae
commit e7b5d17cb8
4 changed files with 51 additions and 2 deletions

View File

@ -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": {

View File

@ -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();
}
}

View File

@ -195,7 +195,10 @@
{if $ticket.repairs && sizeof($ticket.repairs) > 0}
<div class="layui-tab-item">
<div class="layui-card">
<div class="layui-card-header">维修信息</div>
<div class="layui-card-header" style="display: flex; flex-direction: row; justify-content: space-between; align-items: center;">
<span>维修信息</span>
<a class="layui-btn layui-btn-xs" target="_blank" href="{:url('ticket/repair_ticket_create_template')}?id={$ticket.id}">生成派工单模板</a>
</div>
<div class="layui-card-body">
{foreach $ticket.repairs as $repair}
<div class="layui-table">

BIN
public/tpl.docx Normal file

Binary file not shown.