StoreCreateInstantBill.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\LogService;
  4. use App\Services\StoreService;
  5. use App\Store;
  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 StoreCreateInstantBill implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable;
  15. protected $stores;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @param Collection $stores
  20. * @return void
  21. */
  22. public function __construct($stores)
  23. {
  24. $this->stores = $stores;
  25. }
  26. /**
  27. * Execute the job.
  28. *
  29. * @param StoreService $service
  30. * @return void
  31. * @throws
  32. */
  33. public function handle(StoreService $service)
  34. {
  35. foreach ($this->stores as $store){
  36. try{
  37. $service->createInstantBill($store);
  38. }catch (\Exception $e){
  39. LogService::log(__METHOD__,"ERROR-入库生成即时账单",$store->toJson()." | ".$e->getMessage());
  40. throw new \Exception($e->getMessage());
  41. }
  42. }
  43. }
  44. }