|
|
@@ -2,22 +2,23 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\OracleActAllocationDetails;
|
|
|
use App\OracleDocOrderDeliveryInfo;
|
|
|
use App\OracleDOCOrderHeader;
|
|
|
use App\PrintTemplate;
|
|
|
+use App\Traits\DrawImage;
|
|
|
use App\Traits\ModelSearchWay;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
-use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Str;
|
|
|
use Intervention\Image\Facades\Image;
|
|
|
-use Picqer\Barcode\BarcodeGeneratorPNG;
|
|
|
|
|
|
class PrintService
|
|
|
{
|
|
|
use ModelSearchWay;
|
|
|
use ServiceAppAop;
|
|
|
+ use DrawImage;
|
|
|
|
|
|
/**
|
|
|
* 分列 订单号,快递单号,波次号
|
|
|
@@ -53,7 +54,7 @@ class PrintService
|
|
|
$orderCodes = array_merge($orderHeaders, $orderCodes);
|
|
|
}
|
|
|
if($orderCodes) {
|
|
|
- $info = OracleDocOrderDeliveryInfo::query()->where('OrderNo',$orderCodes)->get()->map(function($item){
|
|
|
+ $info = OracleActAllocationDetails::query()->where('OrderNo',$orderCodes)->get()->map(function($item){
|
|
|
return $item->tackingno;
|
|
|
});
|
|
|
$logistic_numbers = array_merge($info, $logistic_numbers);
|
|
|
@@ -105,10 +106,8 @@ class PrintService
|
|
|
$img_base64_code = $param['base64'];
|
|
|
$img = Image::make($img_base64_code);
|
|
|
$printTemplate = PrintTemplate::query()->where('name','123')->first();
|
|
|
-// $img = $this->convertPrintImage($img,$printTemplate);
|
|
|
-
|
|
|
+ $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));
|
|
|
@@ -141,71 +140,23 @@ class PrintService
|
|
|
*/
|
|
|
public function convertPrintImage($image,$printTemplate,$order_package = null)
|
|
|
{
|
|
|
- $values = $printTemplate->value;
|
|
|
- usort($values,function($itemA,$itemB){
|
|
|
- if( $itemA['type'] == "bg") return 1;
|
|
|
- if (!isset($itemA['z-index'])) return -1;
|
|
|
- if (!isset($itemB['z-index'])) return 1;
|
|
|
- if($itemA['z_index'] > $itemB['z_index'])return 1;
|
|
|
- if($itemA['z_index'] < $itemB['z_index'])return -1;
|
|
|
- if($itemA['z_index'] == $itemB['z_index'])return 0;
|
|
|
- });
|
|
|
|
|
|
- foreach ($values as $value) {
|
|
|
- if($value['type'] == 'bg') continue;
|
|
|
-// $img = $this->getTextBox($value);
|
|
|
-// $img = $this->getStripeCode('75175934320303',$value);
|
|
|
-// $img = $this->getImage(123,123);
|
|
|
-// $image->insert($img,'top-left', $value['left'], $value['top']);
|
|
|
- }
|
|
|
- return $image;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 文本框
|
|
|
- * @param $value
|
|
|
- * @return \Intervention\Image\Image
|
|
|
- */
|
|
|
- public function getTextBox($value): \Intervention\Image\Image
|
|
|
- {
|
|
|
- $bgImage = Image::canvas($value['width'],$value['height'],'#000');
|
|
|
- $borderWidth = $value['borderWidth'] * 2;
|
|
|
- $img = Image::canvas($value['width']-$borderWidth,$value['height']-$borderWidth,'#fff');
|
|
|
-
|
|
|
- $textX = $value['justifyContent'] == 'center' ? ($value['width']-$borderWidth)/2 : ($value['justifyContent'] == 'left' ? 0 : $value['width']-$borderWidth);
|
|
|
- $textY = $value['alignItems'] == 'center' ? ($value['height']-$borderWidth)/2 : ($value['alignItems'] == 'top' ? 0 : $value['height']-$borderWidth);
|
|
|
- $img->text($value['text'],$textX,$textY,function($font)use($value){
|
|
|
- $font->size(25);
|
|
|
- $font->align($value['justifyContent']); // 水平对其
|
|
|
- $font->valign($value['alignItems']); // 垂直对其
|
|
|
- $font->angle(100);
|
|
|
+ $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;
|
|
|
});
|
|
|
- $bgImage->insert($img,'top-left', $value['borderWidth'], $value['borderWidth']);
|
|
|
|
|
|
- return $bgImage;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 条纹码
|
|
|
- * @param $code
|
|
|
- * @param $value
|
|
|
- * @return \Intervention\Image\Image
|
|
|
- */
|
|
|
- public function getStripeCode($code,$value): \Intervention\Image\Image
|
|
|
- {
|
|
|
- $generatorPng = new BarcodeGeneratorPNG();
|
|
|
- $img = $generatorPng->getBarcode($code,$generatorPng::TYPE_CODE_128,1,20,[0, 0, 200]);
|
|
|
- return Image::make($img)->resize($value['width'],$value['height']);
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 图片
|
|
|
- * @param $code
|
|
|
- * @param $value
|
|
|
- */
|
|
|
- public function getImage($code,$value)
|
|
|
- {
|
|
|
- // Image::make(Storage::get('\\ownerMaterial\\3ce187cf-391e-3e54-9501-de06d57fd8e7.png'));
|
|
|
- return Image::make('')->resize($value['width'],$value['height']);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|