TBDeliveryService.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Str;
  8. class TBDeliveryService implements DeliveryInterface
  9. {
  10. use DeliveryProcess;
  11. function getDeliveryInfo($OracleDocOrderDeliveryInfos): array
  12. {
  13. $items = $OracleDocOrderDeliveryInfos->filter(function ($item) {
  14. return in_array($item->docOrderHeader->consigneeid, ['TB', 'TMMK', 'TM']) || $item->docOrderheader['h_edi_01'] == '幼岚天猫超市';
  15. });
  16. return $items->map(function ($item) {
  17. return [
  18. // TODO 需要动态获取面单获取的组件 TYPE
  19. 'type' => 'CAINIAO', // PDD 或 CAINIAO 动态
  20. 'task_id' => Str::uuid(),
  21. 'is_process' => false,
  22. 'data' => $item['userdefine1'],
  23. 'component_type' => 'TB',
  24. 'owner_code' => $item->docOrderHeader->customerid ?? '',
  25. 'logistic_code' => $item->docOrderHeader->userdefine1 ?? '',
  26. 'logistic_number' => $item['trackingno'],
  27. 'delivery' => $this->getDelivery($item),
  28. 'base64' => null,
  29. 'printerName' => '',
  30. ];
  31. })->toArray();
  32. }
  33. public function getBase64($item)
  34. {
  35. }
  36. function getDelivery($item): array
  37. {
  38. return $this->getDocOrderDeliveryInfo($item);
  39. }
  40. function processing(array &$item)
  41. {
  42. $item['is_process'] = true;
  43. $PrintTemplate = OwnerLogisticPrintTemplate::query()->with('printTemplate')->where('owner_id', function (Builder $query) use ($item) {
  44. $query->from('owners')->selectRaw('id')->where("code", $item['owner_code']);
  45. })->where('logistic_id', function (Builder $query) use ($item) {
  46. $query->from('logistics')->selectRaw('id')->where("code", $item['logistic_code']);
  47. })->first();
  48. if (!$item) return $item;
  49. $path = '';
  50. $img = $this->getImage($item['base64'], $path);
  51. app(DeliveryService::class)->pushClearCache($path);
  52. $image = $this->draw($item['delivery'], $PrintTemplate->printTemplate, $img);
  53. $this->saveImage($image, $path);
  54. $item['base64'] = $this->readImageBase64($path);
  55. app(DeliveryService::class)->pushClearCache($path);
  56. return $item;
  57. }
  58. }