PDDDeliveryService.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Services;
  3. use App\OwnerLogisticPrintTemplate;
  4. use App\Services\Interfaces\DeliveryInterface;
  5. use App\Traits\DeliveryProcess;
  6. use Illuminate\Database\Query\Builder;
  7. use Illuminate\Support\Facades\File;
  8. use Illuminate\Support\Str;
  9. class PDDDeliveryService implements DeliveryInterface
  10. {
  11. use DeliveryProcess;
  12. function getDeliveryInfo($OracleDocOrderDeliveryInfos): ?array
  13. {
  14. $items = $OracleDocOrderDeliveryInfos->filter(function($item){
  15. return $item->docOrderHeader->consigneeid == 'PDD' || $item->docOrderHeader['h_edi_01'] == 'PDD';
  16. });
  17. return $items->map(function($item) {
  18. return [
  19. // TODO 需要动态获取面单获取的组件 TYPE
  20. 'type' => 'PDD',
  21. 'task_id' => Str::uuid(),
  22. 'is_process' => false,
  23. 'data' => $item['userdefine1'],
  24. 'component_type' => 'PDD',
  25. 'owner_code' => $item->docOrderHeader->customerid ?? '',
  26. 'logistic_code' => $item->docOrderHeader->userdefine1 ?? '',
  27. 'logistic_number' => $item['trackingno'],
  28. 'delivery' => $this->getDelivery($item),
  29. 'base64' => null,
  30. ];
  31. })->toArray();
  32. }
  33. public function getDelivery($item): array
  34. {
  35. return $this->getDocOrderDeliveryInfo($item);
  36. }
  37. public function getBase64($img = null, $item = null): ?string
  38. {
  39. if (!$img) return null;
  40. $imgName = 'PDD-' . $item['logistic_code'] . 'png';
  41. $path = storage_path(['app/public/files/' . $imgName]);
  42. $img->save($path);
  43. return File::get($path);
  44. }
  45. function processing(&$item)
  46. {
  47. $item['is_process'] = true;
  48. $PrintTemplate = OwnerLogisticPrintTemplate::query()->with('printTemplate')->where('owner_id', function (Builder $query) use ($item) {
  49. $query->from('owners')->selectRaw('id')->where("code", $item['owner_code']);
  50. })->where('logistic_id', function (Builder $query) use ($item) {
  51. $query->from('logistics')->selectRaw('id')->where("code", $item['logistic_code']);
  52. })->first();
  53. if (!$item) return $item;
  54. $path = '';
  55. $img = $this->getImage($item['base64'], $path);
  56. app(DeliveryService::class)->pushClearCache($path);
  57. $image = $this->draw($item['delivery'], $PrintTemplate, $img);
  58. $this->saveImage($image, $path);
  59. $item['base64'] = $this->readImageBase64($path);
  60. app(DeliveryService::class)->pushClearCache($path);
  61. return $item;
  62. }
  63. }