OrderCreateInstantBill.php 1.3 KB

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