filter(function($item){ return $item->docOrderHeader->consigneeid == 'PDD'; }); return $items->map(function($item) { return [ // TODO 需要动态获取面单获取的组件 TYPE 'type' => 'PDD', 'task_id' => $item['trackingno'], 'is_process' => false, 'data' => $item['userdefine1'], 'component_type' => 'PDD', 'owner_code' => $item->docOrderHeader->customerid ?? '', 'logistic_code' => $item->docOrderHeader->userdefine1 ?? '', 'logistic_number' => $item['trackingno'], 'delivery' => $this->getDelivery($item), 'base64' => null, ]; })->toArray(); } public function getDelivery($item = null) { return null; } public function getBase64($img = null, $item = null): ?string { if (!$img) return null; $imgName = 'PDD-' . $item['logistic_code'] . 'png'; $path = storage_path(['app/public/files/' . $imgName]); $img->save($path); return File::get($path); } function processing(&$params) { // TODO 获取模板 $owner_query = Owner::query()->selectRaw('id')->where('code', $params['owner_code']); $logistic_query = Logistic::query()->selectRaw('id')->where('code', $params['logistic_code']); $item = OwnerLogisticPrintTemplate::query()->with('printTemplate')->where('owner_id', $owner_query)->where('logistic_id', $logistic_query)->first(); $item = $item->printTemplate; $item->printTemplate; $path = ''; $img = $this->getImage($params['base64'],$path); $img = $this->draw(null,$item,$img); $img->save($path); $arr = Cache::get('print-template-file-list') ?? []; $arr[] = ['time' => Carbon::now(),'path' => $path]; Cache::put('print-template-file-list',$arr); // TODO 将文件进行base64编码 if ($fp = fopen($path,"rp",0)){ $gambar = fread($fp,filesize($path)); fclose($fp); $params['base64'] = chunk_split(base64_encode($gambar)); } $params['is_process'] = true; return $params; } }