LogisticYTOSync.php 1.8 KB

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