PDDDeliveryService.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Services;
  3. use App\Logistic;
  4. use App\OracleDocOrderDeliveryInfo;
  5. use App\OracleDOCOrderHeader;
  6. use App\Owner;
  7. use App\OwnerLogisticPrintTemplate;
  8. use App\Services\Interfaces\DeliveryInterface;
  9. use App\Traits\DrawImage;
  10. use Illuminate\Support\Carbon;
  11. use Illuminate\Support\Facades\Cache;
  12. use Illuminate\Support\Facades\File;
  13. class PDDDeliveryService implements DeliveryInterface
  14. {
  15. use DrawImage;
  16. function getDeliveryInfo($OracleDocOrderDeliveryInfos): ?array
  17. {
  18. $items = $OracleDocOrderDeliveryInfos->filter(function($item){
  19. return $item->docOrderHeader->consigneeid == 'PDD';
  20. });
  21. return $items->map(function($item) {
  22. return [
  23. // TODO 需要动态获取面单获取的组件 TYPE
  24. 'type' => 'PDD',
  25. 'task_id' => $item['trackingno'],
  26. 'is_process' => false,
  27. 'data' => $item['userdefine1'],
  28. 'component_type' => 'PDD',
  29. 'owner_code' => $item->docOrderHeader->customerid ?? '',
  30. 'logistic_code' => $item->docOrderHeader->userdefine1 ?? '',
  31. 'logistic_number' => $item['trackingno'],
  32. 'delivery' => $this->getDelivery($item),
  33. 'base64' => null,
  34. ];
  35. })->toArray();
  36. }
  37. public function getDelivery($item = null)
  38. {
  39. return null;
  40. }
  41. public function getBase64($img = null, $item = null): ?string
  42. {
  43. if (!$img) return null;
  44. $imgName = 'PDD-' . $item['logistic_code'] . 'png';
  45. $path = storage_path(['app/public/files/' . $imgName]);
  46. $img->save($path);
  47. return File::get($path);
  48. }
  49. function processing(&$params)
  50. {
  51. // TODO 获取模板
  52. $owner_query = Owner::query()->selectRaw('id')->where('code', $params['owner_code']);
  53. $logistic_query = Logistic::query()->selectRaw('id')->where('code', $params['logistic_code']);
  54. $item = OwnerLogisticPrintTemplate::query()->with('printTemplate')->where('owner_id', $owner_query)->where('logistic_id', $logistic_query)->first();
  55. $item = $item->printTemplate;
  56. $item->printTemplate;
  57. $path = '';
  58. $img = $this->getImage($params['base64'],$path);
  59. $img = $this->draw(null,$item,$img);
  60. $img->save($path);
  61. $arr = Cache::get('print-template-file-list') ?? [];
  62. $arr[] = ['time' => Carbon::now(),'path' => $path];
  63. Cache::put('print-template-file-list',$arr);
  64. // TODO 将文件进行base64编码
  65. if ($fp = fopen($path,"rp",0)){
  66. $gambar = fread($fp,filesize($path));
  67. fclose($fp);
  68. $params['base64'] = chunk_split(base64_encode($gambar));
  69. }
  70. $params['is_process'] = true;
  71. return $params;
  72. }
  73. }