|
|
|
|
@ -25,6 +25,7 @@ use App\Models\ProductParamedicLevel;
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
use App\Models\Recharge;
|
|
|
|
|
use App\Models\Refund;
|
|
|
|
|
use App\Models\Uploads;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
@ -1960,29 +1961,33 @@ class OrdersController extends CommonController
|
|
|
|
|
'format' => 'png',
|
|
|
|
|
// 允许访问本地文件(解决Blocked access to file警告)
|
|
|
|
|
'enable-local-file-access' => true,
|
|
|
|
|
// 禁止加载图片(如果不需要图片可以开启)
|
|
|
|
|
// 'no-images' => true,
|
|
|
|
|
// 禁止加载JavaScript(如果不需要JS可以开启)
|
|
|
|
|
// 'no-js' => true,
|
|
|
|
|
];
|
|
|
|
|
$tempPath = storage_path('app/temp/' . uniqid() . '.' . $options['format']);
|
|
|
|
|
// 目录
|
|
|
|
|
$save_folder = "public";
|
|
|
|
|
// 文件名
|
|
|
|
|
$name = "协议" . date("YmdHis") . uniqid(). "." . $options['format'];
|
|
|
|
|
$tempPath = storage_path("app/{$save_folder}/" . $name. '.' . $options['format']);
|
|
|
|
|
// 确保临时目录存在
|
|
|
|
|
Storage::makeDirectory('temp');
|
|
|
|
|
Storage::makeDirectory($save_folder);
|
|
|
|
|
// 2. 生成图片到临时文件(需要两个参数:html内容和输出路径)
|
|
|
|
|
SnappyImage::setOptions($options)->generateFromHtml($html, $tempPath);
|
|
|
|
|
// 3. 读取临时文件内容并转换为Base64
|
|
|
|
|
$imageContent = file_get_contents($tempPath);
|
|
|
|
|
$base64Image = 'data:image/' . $options['format'] . ';base64,' . base64_encode($imageContent);
|
|
|
|
|
|
|
|
|
|
// 4. 删除临时文件(清理资源)
|
|
|
|
|
unlink($tempPath);
|
|
|
|
|
return response()->json([
|
|
|
|
|
"errorcode" => "200",
|
|
|
|
|
"errormsg" => "success",
|
|
|
|
|
"data" => [
|
|
|
|
|
"base64_image" => $base64Image
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
$upload = new Uploads();
|
|
|
|
|
$upload->original_name = $name;
|
|
|
|
|
$upload->folder = "agreement";
|
|
|
|
|
$upload->name = $name;;
|
|
|
|
|
$upload->extension = $options['format'];
|
|
|
|
|
$upload->creator_type = get_class($this->manager);
|
|
|
|
|
$upload->creator_id = $this->manager->id;
|
|
|
|
|
$upload->size = Storage::size($save_folder . "/" . $name);
|
|
|
|
|
$upload->save();
|
|
|
|
|
if ($save_folder == "public") {
|
|
|
|
|
$upload->public_path = "/storage/" . $name;
|
|
|
|
|
} else {
|
|
|
|
|
$upload->public_path = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json($upload);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|