ExecutePostBillHandler.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Jobs;
  3. use App\Feature;
  4. use App\Order;
  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. class ExecutePostBillHandler implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable;
  14. /**
  15. * @var \Closure $closure
  16. */
  17. protected $closure;
  18. /**
  19. * @var Collection $collection
  20. */
  21. protected $collection;
  22. /**
  23. * @var string $modelClass
  24. */
  25. protected $modelClass;
  26. /**
  27. * Create a new job instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct(\Closure $closure, Collection $collection, string $modelClass)
  32. {
  33. $this->closure = $closure;
  34. $this->connection = $collection;
  35. $this->modelClass = $modelClass;
  36. }
  37. /**
  38. * Execute the job.
  39. *
  40. * @return void
  41. */
  42. public function handle()
  43. {
  44. $closure = $this->closure;
  45. switch ($this->modelClass){
  46. case Store::class:
  47. foreach ($this->collection as $detail){
  48. $closure(Feature::MAPPING["store"],$detail->store,$detail);
  49. }
  50. break;
  51. case Order::class:
  52. foreach ($this->collection as $detail){
  53. $closure(Feature::MAPPING["order"],$detail->order,$detail);
  54. }
  55. }
  56. }
  57. }