Commit bc527fab by 赵增煜
parents 7f9439e5 1c3fa528
...@@ -28,6 +28,7 @@ public function index(Content $content): Content ...@@ -28,6 +28,7 @@ public function index(Content $content): Content
public function search() public function search()
{ {
$prescriptionNo = request('prescription_no'); $prescriptionNo = request('prescription_no');
$printEseal = request('print_eseal', 0); // 是否打印电子印章,实时生成
if (empty($prescriptionNo)) { if (empty($prescriptionNo)) {
return response()->json([ return response()->json([
...@@ -36,14 +37,21 @@ public function search() ...@@ -36,14 +37,21 @@ public function search()
]); ]);
} }
// try { try {
// 获取处方信息 // 获取处方信息
$prescription = PrescriptionModel::where('id', $prescriptionNo)->first(); $prescription = PrescriptionModel::where('id', $prescriptionNo)->first();
if (! $prescription) { if (! $prescription) {
return response()->json(['status' => false, 'message' => '未找到该处方']); return response()->json(['status' => false, 'message' => '未找到该处方']);
} }
// 检查处方图片是否已经生成 // 检查处方图片是否已经生成
if ($prescription->prescription_pic) { if ($printEseal && $prescription->prescription_pic_eseal) {
return response()->json([
'status' => true,
'data' => [
'img_url' => Storage::url($prescription->prescription_pic_eseal),
],
]);
} elseif ($prescription->prescription_pic) {
return response()->json([ return response()->json([
'status' => true, 'status' => true,
'data' => [ 'data' => [
...@@ -174,34 +182,53 @@ public function search() ...@@ -174,34 +182,53 @@ public function search()
$pharmacistSign->resize(150, 100); $pharmacistSign->resize(150, 100);
$img->place($pharmacistSign, 'bottom-left', 870, 410); $img->place($pharmacistSign, 'bottom-left', 870, 410);
} }
// 不带印章处方图片生成
// 将图片保存到临时文件 $picName = $prescriptionNo.'.jpg';
$tempPath = storage_path('app/public').$prescriptionNo.'.jpg'; $tempPath = storage_path('app/public').$picName;
$img->save($tempPath); $img->save($tempPath); // 不带电子印章
// 上传到腾讯云 // 上传到腾讯云
Storage::putFileAs('prescriptions', $tempPath, $prescriptionNo.'.jpg'); Storage::putFileAs('prescriptions', $tempPath, $picName);
// 电子印章版处方图片生成
$eseal = Image::read(public_path('static/images/dianzizhang.png'));
// $eseal->rotate(90);
$eseal->resize(150, 150);
$img->place($eseal, 'bottom-right', 180, 500);
$picEsealName = $prescriptionNo.'-eseal.jpg';
$tempEsealPath = storage_path('app/public').$picEsealName;
$img->save($tempEsealPath);
// 上传到腾讯云
Storage::putFileAs('prescriptions', $tempEsealPath, $picEsealName);
// 删除临时文件 // 删除临时文件
unlink($tempPath); unlink($tempPath);
unlink($tempEsealPath);
$cosPath = 'prescriptions/'.$prescriptionNo.'.jpg'; $cosPath = "prescriptions/{$picName}";
$cosEsealPath = "prescriptions/{$picEsealName}";
// 将生成的图片路径存储到数据库 // 将生成的处方图片路径存储到数据库
$prescription->prescription_pic = $cosPath; $prescription->prescription_pic = $cosPath;
$prescription->save(); $prescription->prescription_pic_eseal = $cosEsealPath;
$prescription->save(); // 保存处方图片路径
if ($printEseal = true) {
$imgUrl = Storage::url($cosEsealPath);
} else {
$imgUrl = Storage::url($cosPath);
}
return response()->json([ return response()->json([
'status' => true, 'status' => true,
'data' => [ 'data' => [
'img_url' => Storage::url($cosPath), 'img_url' => $imgUrl,
], ],
]); ]);
// } catch (\Exception $e) { } catch (\Exception $e) {
// return response()->json([ return response()->json([
// 'status' => false, 'status' => false,
// 'message' => '处方生成失败:'.$e->getMessage(), 'message' => '处方生成失败:'.$e->getMessage(),
// ]); ]);
// } }
} }
} }
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('prescription', function (Blueprint $table) {
$table->string('prescription_pic_eseal')->nullable()->comment('处方单带电子印章图片地址');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('prescription', function (Blueprint $table) {
//
});
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment