OrderCreateInstantBill.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\LogService;
  4. use App\Services\OrderService;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Database\Eloquent\Collection;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. class OrderCreateInstantBill implements ShouldQueue
  11. {
  12. use Dispatchable, InteractsWithQueue, Queueable;
  13. protected $orders;
  14. /**
  15. * Create a new job instance.
  16. *
  17. * @param Collection $orders
  18. * @return void
  19. */
  20. public function __construct($orders)
  21. {
  22. $this->orders = $orders;
  23. }
  24. /**
  25. *
  26. * @param OrderService $service
  27. * @return void
  28. * @throws
  29. */
  30. public function handle(OrderService $service)
  31. {
  32. if ($this->orders){
  33. foreach ($this->orders as $order){
  34. try{
  35. if (!$service->createInstantBill($order))
  36. LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson());
  37. }catch (\Exception $e){
  38. LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson()." | ".$e->getMessage());
  39. throw new \Exception($e->getMessage());
  40. }
  41. }
  42. }
  43. }
  44. }