diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index a4e2567..567dcf9 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -21,7 +21,9 @@ use Extend\Ca\Ca; use Hyperf\Amqp\Producer; use Hyperf\DbConnection\Db; use Hyperf\Utils\ApplicationContext; +use Imagick; use Intervention\Image\ImageManager; +use Spatie\PdfToImage\Pdf; use TCPDF; class TestController extends AbstractController @@ -505,22 +507,27 @@ class TestController extends AbstractController } public function test_11(){ - - $OrderPrescriptionService = new OrderPrescriptionService(); - $prescription_img = $OrderPrescriptionService->openPrescription($order_prescription->order_prescription_id,$user_info['user_id']); - if (empty($prescription_img)){ - Db::rollBack(); - return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败"); + $ca = new Ca(); + $prescription_pdf_result = $ca->getSignedFile("491925054435950592","1641368425758359554"); + if (empty($prescription_pdf_result)){ + throw new BusinessException("下载处方签章文件失败"); } - // 修改处方表 - $data = array(); - $data['prescription_img'] = $prescription_img; - $data['doctor_created_time'] = date('Y-m-d H:i:s',time()); + $file = fopen("./runtime/test.pdf", "w") or die("Unable to open file!"); + fwrite($file, $prescription_pdf_result); + fclose($file); - $params = array(); - $params['order_prescription_id'] = $order_prescription->order_prescription_id; - OrderPrescription::edit($params,$data); + // 将临时文件转换为图片 + $pdf = new Pdf("./runtime/test.pdf"); + $pdf->saveImage("./runtime/test.jpg"); + +// dump($prescription_pdf_result); +// +// $manager = new ImageManager(); +// $image = $manager->make($prescription_pdf_result)->convert('jpg'); +// +// // 保存图片 +// $image->save('./runtime/image.jpg'); } } \ No newline at end of file diff --git a/app/Request/PatientFamilyRequest.php b/app/Request/PatientFamilyRequest.php index 741a2de..739d0bf 100644 --- a/app/Request/PatientFamilyRequest.php +++ b/app/Request/PatientFamilyRequest.php @@ -19,7 +19,7 @@ class PatientFamilyRequest extends FormRequest protected array $scenes = [ 'addFamily' => [ // 新增家庭成员 - 'relation', +// 'relation', 'is_default', 'card_name', 'mobile', @@ -33,7 +33,7 @@ class PatientFamilyRequest extends FormRequest 'marital_status', ], 'editFamily' => [ // 修改家庭成员 - 'relation', +// 'relation', 'is_default', 'card_name', 'type', diff --git a/app/Services/OrderPrescriptionService.php b/app/Services/OrderPrescriptionService.php index 109378d..d92dbc1 100644 --- a/app/Services/OrderPrescriptionService.php +++ b/app/Services/OrderPrescriptionService.php @@ -112,9 +112,9 @@ class OrderPrescriptionService extends BaseService * 开具处方 * @param string $order_prescription_id * @param string $user_id - * @return string + * @return array */ - public function openPrescription(string $order_prescription_id,string $user_id): string + public function openPrescription(string $order_prescription_id,string $user_id): array { try { // 获取用户数据 @@ -253,7 +253,8 @@ class OrderPrescriptionService extends BaseService $image = $manager->make($prescription_image); - $fontPath = './extend/Ca/ZiYuYongSongTi-2.ttf'; +// $fontPath = './extend/Ca/ZiYuYongSongTi-2.ttf'; + $fontPath = './extend/Ca/msyh.ttf'; // 处方号 $image->text($order_prescription['prescription_code'], 1480, 540, function ($font) use($fontPath) { @@ -354,6 +355,12 @@ class OrderPrescriptionService extends BaseService // 生成图片 $img_result = (string) $image->encode('png', 75); + dump("处方图片生成成功"); + + // 上传处方图片至oss + $filename = "applet/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'jpg'; + $prescription_img_url = $oss->putObject($filename, $img_result); + dump("处方图片上传oss成功"); // 图片生成pdf $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); @@ -432,7 +439,10 @@ class OrderPrescriptionService extends BaseService $filename = "applet/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'pdf'; $prescription_pdf_url = $oss->putObject($filename, $prescription_pdf_result); - return $prescription_pdf_url; + $result = array(); + $result['prescription_img_url'] = $prescription_img_url ?: ""; + $result['prescription_pdf_url'] = $prescription_pdf_url ?: ""; + return $result; } catch (\Exception $e) { throw new BusinessException($e->getMessage()); diff --git a/app/Services/PatientFamilyService.php b/app/Services/PatientFamilyService.php index b20ad38..4dd9b8a 100644 --- a/app/Services/PatientFamilyService.php +++ b/app/Services/PatientFamilyService.php @@ -171,7 +171,9 @@ class PatientFamilyService extends BaseService // 新增 患者家庭成员信息表-基本信息(patient_family) $data = array(); $data['patient_id'] = $user_info['client_user_id']; - $data['relation'] = $request_params['relation']; + if (!empty($request_params['relation'])){ + $data['relation'] = $request_params['relation']; + } $data['status'] = 1; $data['is_default'] = empty($request_params['is_default']) ? 0 : 1; $data['card_name'] = $request_params['card_name']; diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index a74b2e6..75dc856 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -1117,15 +1117,16 @@ class UserDoctorService extends BaseService } $OrderPrescriptionService = new OrderPrescriptionService(); - $prescription_img = $OrderPrescriptionService->openPrescription($order_prescription->order_prescription_id,$user_info['user_id']); - if (empty($prescription_img)){ + $prescription_open_result = $OrderPrescriptionService->openPrescription($order_prescription->order_prescription_id,$user_info['user_id']); + if (empty($prescription_open_result['prescription_img_url']) || empty($prescription_open_result['prescription_pdf_url'])){ Db::rollBack(); return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败"); } // 修改处方表 $data = array(); - $data['prescription_img'] = $prescription_img; + $data['prescription_img'] = $prescription_open_result['prescription_img_url']; + $data['prescription_pdf'] = $prescription_open_result['prescription_pdf_url']; $data['doctor_created_time'] = date('Y-m-d H:i:s',time()); $params = array(); @@ -1310,15 +1311,16 @@ class UserDoctorService extends BaseService // 开具处方 $OrderPrescriptionService = new OrderPrescriptionService(); - $prescription_img = $OrderPrescriptionService->openPrescription($order_prescription->order_prescription_id,$user_info['user_id']); - if (empty($prescription_img)){ + $prescription_open_result = $OrderPrescriptionService->openPrescription($order_prescription->order_prescription_id,$user_info['user_id']); + if (empty($prescription_open_result['prescription_img_url']) || empty($prescription_open_result['prescription_pdf_url'])){ Db::rollBack(); return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败"); } // 修改处方表 $data = array(); - $data['prescription_img'] = $prescription_img; + $data['prescription_img'] = $prescription_open_result['prescription_img_url']; + $data['prescription_pdf'] = $prescription_open_result['prescription_pdf_url']; $data['doctor_created_time'] = date('Y-m-d H:i:s',time()); $params = array(); diff --git a/composer.json b/composer.json index baa5ecc..f6a36c0 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "hyperf/snowflake": "^3.0", "hyperf/validation": "^3.0", "intervention/image": "^2.7", + "spatie/pdf-to-image": "^1.2", "tecnickcom/tcpdf": "^6.6", "w7corp/easywechat": "^6.7" }, diff --git a/composer.lock b/composer.lock index a0fa059..bffb598 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f11dd54f0558de3aed797460197d3986", + "content-hash": "bdf6fc89c13c332770e8c88e1076586f", "packages": [ { "name": "adbario/php-dot-notation", @@ -4689,6 +4689,55 @@ "description": "A polyfill for getallheaders.", "time": "2019-03-08T08:55:37+00:00" }, + { + "name": "spatie/pdf-to-image", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/spatie/pdf-to-image.git", + "reference": "9a5cb264a99e87e010c65d4ece03b51f821d55bd" + }, + "dist": { + "type": "zip", + "url": "https://mirrors.huaweicloud.com/repository/php/spatie/pdf-to-image/1.2.2/spatie-pdf-to-image-1.2.2.zip", + "reference": "9a5cb264a99e87e010c65d4ece03b51f821d55bd", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*", + "scrutinizer/ocular": "~1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\PdfToImage\\": "src" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Convert a pdf to an image", + "homepage": "https://github.com/spatie/pdf-to-image", + "keywords": [ + "convert", + "image", + "pdf", + "pdf-to-image", + "spatie" + ], + "time": "2016-12-14T15:37:00+00:00" + }, { "name": "symfony/cache", "version": "v6.0.18", diff --git a/extend/Ca/msyh.ttf b/extend/Ca/msyh.ttf new file mode 100755 index 0000000..b4456b2 Binary files /dev/null and b/extend/Ca/msyh.ttf differ