| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Services;
- use App\Logistic;
- use App\OracleDocOrderDeliveryInfo;
- use App\OracleDOCOrderHeader;
- use App\Owner;
- use App\OwnerLogisticPrintTemplate;
- use App\Services\Interfaces\DeliveryInterface;
- use App\Traits\DrawImage;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\File;
- class PDDDeliveryService implements DeliveryInterface
- {
- use DrawImage;
- function getDeliveryInfo($OracleDocOrderDeliveryInfos): ?array
- {
- $items = $OracleDocOrderDeliveryInfos->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;
- }
- }
|