LogisticYTOSync.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\LogisticYTOService;
  4. use App\Services\LogService;
  5. use App\Services\OrderPackageReceivedSyncService;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Queue\SerializesModels;
  11. class LogisticYTOSync implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. /**
  15. * @var $logisticYTOService LogisticYTOService
  16. * @var $orderPackageReceivedSyncService OrderPackageReceivedSyncService
  17. * @var $logistic_number string
  18. */
  19. protected $logistic_number;
  20. protected $logisticYTOService;
  21. protected $orderPackageReceivedSyncService;
  22. /**
  23. * LogisticYDSync constructor.
  24. * @param $logistic_number
  25. */
  26. public function __construct($logistic_number)
  27. {
  28. $this->logistic_number = $logistic_number;
  29. }
  30. /**
  31. * Execute the job.
  32. *
  33. * @return void
  34. */
  35. public function handle()
  36. {
  37. LogService::log(LogisticYTOSync::class, "JOB-YTO", $this->logistic_number);
  38. $this->logisticYTOService = app('LogisticYTOService');
  39. $this->orderPackageReceivedSyncService = app('OrderPackageReceivedSyncService');
  40. $nativeResponse = $this->logisticYTOService->query($this->logistic_number);
  41. $formattedData = $this->logisticYTOService->format($nativeResponse,$this->logistic_number);
  42. try {
  43. if ($formattedData && isset($formattedData['logistic_number'])) $this->orderPackageReceivedSyncService->update([$formattedData]);
  44. } catch (\Exception $e) {
  45. LogService::log(LogisticYTOService::class, "YTO快递无快递单号异常", json_encode($formattedData));
  46. }
  47. }
  48. }