From fe7cf2b8406401eb760e187f52c9971cd3513900 Mon Sep 17 00:00:00 2001 From: pengda <10266652509@qq.com> Date: Fri, 20 Sep 2024 14:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8C=BB=E6=A1=88=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/index.php | 49 +++++++++++++-------------------------------- model/mUserCase.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 36 deletions(-) diff --git a/control/index.php b/control/index.php index 4776b25..d32bdcd 100644 --- a/control/index.php +++ b/control/index.php @@ -342,50 +342,29 @@ class index extends publicBase { public function export_user_case() { $uinfo = $this->_check_login(); - //导出单个医案 $id = $this->post('id') + 0; - if ($id > 0) { - $post_url = USER_CASE_HTML_URL; - $data = array( - "uid" => $uinfo['uid'], - "id" => $id, - ); - } - - //导出全部医案 - if ($id == 0) { - $start_date = $this->post('start_date'); - //if (empty($start_date)) $this->ajax_json(false, '请选择导出开始时间'); - - $end_date = $this->post('end_date'); - //if (empty($end_date)) $this->ajax_json(false, '请选择导出结束时间'); - - $post_url = USER_CASE_LIST_HTML_URL; - $data = array( - "uid" => $uinfo['uid'], - "start_date" => $start_date, - "end_date" => $end_date, - ); - } + $start_date = $this->post('start_date'); + //if (empty($start_date)) $this->ajax_json(false, '请选择导出开始时间'); + $end_date = $this->post('end_date'); + //if (empty($end_date)) $this->ajax_json(false, '请选择导出结束时间'); $m_user_case = new mUserCase(); - $return = $m_user_case->postCUrl($post_url, $data); - - $res = json_decode($return, 1); - if (isset($res['info'])) $this->ajax_json(false, '未查询到可导出的医案记录'); - - $pdf_name = md5($uinfo['uid'] . $id) . ".pdf"; - $m_user_case->createPdf($uinfo['uid'], $pdf_name, $return); + $pdf_info = $m_user_case->getPdf($uinfo['uid'], $id, $start_date, $end_date); $email = $this->post('email'); if (!empty($email)) { - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $this->ajax_json(false, '邮箱地址无效'); - $res = $m_user_case->sendMail(array($email), date('Y年m月d日', time()) . '-医案导出', '', sprintf(USER_CASE_PDF_PATH, $uinfo['uid']) . $pdf_name); - if (!$res) $this->ajax_json(true, '发送失败'); + //生成唯一id 防止重复请求 + $request_id = md5($email . $pdf_info['pdf_path']); + $request_times = $m_user_case->requestLimit(sprintf(_QR_REQUEST_LIMIT, $request_id), 1, 7200); + if (!$request_times) $this->ajax_json(false, "医案记录已发送至您的邮箱,请查收邮件"); + + $res = $m_user_case->sendPdf($email, $pdf_info['pdf_path']); + if (!$res) $this->ajax_json(false, $m_user_case->getError()); + $this->ajax_json(true, '发送成功'); } - $this->ajax_json(true, '获取成功', array('pdf_url' => sprintf(USER_CASE_PDF_URL, $uinfo['uid']) . $pdf_name)); + $this->ajax_json(true, '获取成功', array('pdf_url' => $pdf_info['pdf_url'])); } public function user_case_list() { diff --git a/model/mUserCase.php b/model/mUserCase.php index f7c74b3..cb3cabf 100644 --- a/model/mUserCase.php +++ b/model/mUserCase.php @@ -355,8 +355,50 @@ class mUserCase extends mBase { return $data; } - public function createPdf($uid, $pdf_name, $pdf_html) { + public function getPdf($uid, $id, $start_date = '', $end_date = '') { + $pdf_name = md5($uid . $id . $start_date . $end_date) . ".pdf"; $temp_dir = sprintf(USER_CASE_PDF_PATH, $uid); + $temp_url = sprintf(USER_CASE_PDF_URL, $uid); + + if (file_exists($temp_dir . $pdf_name)) { + return array( + 'pdf_path' => $temp_dir . $pdf_name, + 'pdf_url' => $temp_url . $pdf_name, + ); + } + + //导出单个医案 + if ($id > 0) { + $post_url = USER_CASE_HTML_URL; + $data = array( + "uid" => $uid, + "id" => $id, + ); + } else { + $post_url = USER_CASE_LIST_HTML_URL; + $data = array( + "uid" => $uid, + "start_date" => $start_date, + "end_date" => $end_date, + ); + } + + $return = $this->postCUrl($post_url, $data); + $res = json_decode($return, 1); + if (isset($res['info'])) { + $this->setError('抱歉,未找到可导出的医案记录'); + return false; + } + + $this->createPdf($temp_dir, $pdf_name, $return); + + return array( + 'pdf_path' => $temp_dir . $pdf_name, + 'pdf_url' => $temp_url . $pdf_name, + ); + } + + public function createPdf($temp_dir, $pdf_name, $pdf_html) { if (!is_dir($temp_dir)) { mkdir($temp_dir, 0755, true); chown($temp_dir, 'nobody'); @@ -369,4 +411,17 @@ class mUserCase extends mBase { return $mpdf->Output($temp_dir . $pdf_name, 'F'); // D表示下载,I表示在浏览器中查看 } + + function sendPdf($email, $pdf_path) { + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $this->setError('请填写合法的邮箱地址'); + return false; + } + $res = $this->sendMail(array($email), date('Y年m月d日', time()) . '-医案导出', '', $pdf_path); + if (!$res) { + $this->setError('发送失败'); + return false; + } + return true; + } } \ No newline at end of file