WaybillCreateInstantBill.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\LogService;
  4. use App\Services\WaybillService;
  5. use App\Waybill;
  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 WaybillCreateInstantBill implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. protected $waybill;
  15. /**
  16. * Create a new job instance.
  17. *
  18. * @param Waybill $waybill
  19. * @return void
  20. */
  21. public function __construct(Waybill $waybill)
  22. {
  23. $this->waybill = $waybill;
  24. }
  25. /**
  26. * Execute the job.
  27. *
  28. * @param WaybillService $service
  29. * @return void
  30. * @throws
  31. */
  32. public function handle(WaybillService $service)
  33. {
  34. try{
  35. $service->createInstantBill($this->waybill);
  36. }catch (\Exception $e){
  37. LogService::log(__METHOD__,"ERROR-运输计算运费失败",$this->waybill->toJson()." | ".$e->getMessage());
  38. throw new \Exception($e->getMessage());
  39. }
  40. }
  41. }