| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Services;
- use App\OwnerLogisticPrintTemplate;
- use App\Services\Interfaces\DeliveryInterface;
- use App\Traits\DeliveryProcess;
- use Illuminate\Database\Query\Builder;
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Str;
- class PDDDeliveryService implements DeliveryInterface
- {
- use DeliveryProcess;
- function getDeliveryInfo($OracleDocOrderDeliveryInfos): ?array
- {
- $items = $OracleDocOrderDeliveryInfos->filter(function($item){
- return $item->docOrderHeader->consigneeid == 'PDD' || $item->docOrderHeader['h_edi_01'] == 'PDD';
- });
- return $items->map(function($item) {
- return [
- // TODO 需要动态获取面单获取的组件 TYPE
- 'type' => 'PDD',
- 'task_id' => Str::uuid(),
- '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): array
- {
- return $this->getDocOrderDeliveryInfo($item);
- }
- 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(&$item)
- {
- $item['is_process'] = true;
- $PrintTemplate = OwnerLogisticPrintTemplate::query()->with('printTemplate')->where('owner_id', function (Builder $query) use ($item) {
- $query->from('owners')->selectRaw('id')->where("code", $item['owner_code']);
- })->where('logistic_id', function (Builder $query) use ($item) {
- $query->from('logistics')->selectRaw('id')->where("code", $item['logistic_code']);
- })->first();
- if (!$item) return $item;
- $path = '';
- $img = $this->getImage($item['base64'], $path);
- app(DeliveryService::class)->pushClearCache($path);
- $image = $this->draw($item['delivery'], $PrintTemplate, $img);
- $this->saveImage($image, $path);
- $item['base64'] = $this->readImageBase64($path);
- app(DeliveryService::class)->pushClearCache($path);
- return $item;
- }
- }
|