TBDeliveryService.php 2.6 KB

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