| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Services;
- use App\PrintTemplate;
- use App\Traits\DrawImage;
- use App\Traits\ModelSearchWay;
- use App\Traits\ServiceAppAop;
- use Illuminate\Support\Str;
- use Intervention\Image\Facades\Image;
- class PrintService
- {
- use ModelSearchWay;
- use ServiceAppAop;
- use DrawImage;
- /**
- * 处理打印请求参数
- * @param $oracleDocOrderDeliveryInfos
- * @return array
- */
- public function disposesPrintInfo($oracleDocOrderDeliveryInfos): array
- {
- foreach ($oracleDocOrderDeliveryInfos as $key => $info){
- $data[] = [
- 'documentID' => $info->orderno ?? '',
- 'encryptedData' => $info->userDefine4->encryptedData ?? '',
- 'signature' => $info->userDefine4->signature ?? '',
- 'templateURL' => $info->userDefine4->templateURL ?? '',
- 'ver' => $info->userDefine4->ver ?? '',
- ];
- }
- return $data ?? [];
- }
- /**
- * 处理打印参数 返回 打印图片
- * @param array $params
- * @return mixed
- */
- public function processingPrintData(array $params)
- {
- $array = [];
- foreach ($params as $param) {
- $img_base64_code = $param['base64'];
- $img = Image::make($img_base64_code);
- $printTemplate = PrintTemplate::query()->where('name','123')->first();
- $img = $this->convertPrintImage($img,$printTemplate);
- $img_name = Str::uuid().'.png';
- $path_arr = ['app','public','print'];
- $dir_path = implode(DIRECTORY_SEPARATOR,$path_arr);
- if (!file_exists(storage_path($dir_path))) mkdir(storage_path($dir_path));
- $path_arr[] = 'image';
- $dir_path = implode(DIRECTORY_SEPARATOR,$path_arr);
- if (!file_exists(storage_path($dir_path))) mkdir(storage_path($dir_path));
- $path_arr[] = $img_name;
- $path = storage_path(implode(DIRECTORY_SEPARATOR,$path_arr));
- $img->save($path); // 图片保存
- $file = file_get_contents($path);
- $array[] = [
- 'type' => '',
- 'base64' => base64_encode($file),
- 'logistic_number' => '',
- ''
- ];
- }
- return $array;
- }
- /**
- * 数据转图片
- * @param $image
- * @param $printTemplate
- * @param null $order_package
- * @return mixed
- */
- public function convertPrintImage($image,$printTemplate,$order_package = null)
- {
- $items = $printTemplate->value;
- $bg = array_filter($items,function ($item){
- return $item['type'] == 'bg';
- });
- $items = array_filter($items,function($item){
- return $item['type'] !== 'bg';
- });
- usort($items,function ($a, $b) {
- return $a['z_index'] > $b['z_index'] ? 1 : 0;
- });
- return $image;
- }
- }
|