Commit 1c3fa528 by lujunyi

电子 印章

parent 9b23667f
......@@ -28,6 +28,7 @@ public function index(Content $content): Content
public function search()
{
$prescriptionNo = request('prescription_no');
$printEseal = request('print_eseal', 0); // 是否打印电子印章,实时生成
if (empty($prescriptionNo)) {
return response()->json([
......@@ -36,14 +37,21 @@ public function search()
]);
}
// try {
try {
// 获取处方信息
$prescription = PrescriptionModel::where('id', $prescriptionNo)->first();
if (! $prescription) {
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([
'status' => true,
'data' => [
......@@ -174,34 +182,53 @@ public function search()
$pharmacistSign->resize(150, 100);
$img->place($pharmacistSign, 'bottom-left', 870, 410);
}
// 将图片保存到临时文件
$tempPath = storage_path('app/public').$prescriptionNo.'.jpg';
$img->save($tempPath);
// 不带印章处方图片生成
$picName = $prescriptionNo.'.jpg';
$tempPath = storage_path('app/public').$picName;
$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($tempEsealPath);
$cosPath = 'prescriptions/'.$prescriptionNo.'.jpg';
$cosPath = "prescriptions/{$picName}";
$cosEsealPath = "prescriptions/{$picEsealName}";
// 将生成的图片路径存储到数据库
// 将生成的处方图片路径存储到数据库
$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([
'status' => true,
'data' => [
'img_url' => Storage::url($cosPath),
'img_url' => $imgUrl,
],
]);
// } catch (\Exception $e) {
// return response()->json([
// 'status' => false,
// 'message' => '处方生成失败:'.$e->getMessage(),
// ]);
// }
} catch (\Exception $e) {
return response()->json([
'status' => false,
'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