SFDeliveryService.php 2.3 KB

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