MakeCodeJob.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\LibraryCategory;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use Illuminate\Support\Facades\Storage;
  10. use SimpleSoftwareIO\QrCode\Facades\QrCode;
  11. class MakeCodeJob implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. private $cid = 0;
  15. /**
  16. * Create a new job instance.
  17. *
  18. * @return void
  19. */
  20. public function __construct($cid)
  21. {
  22. $this->cid = $cid;
  23. }
  24. /**
  25. * Execute the job.
  26. *
  27. * @return void
  28. */
  29. public function handle()
  30. {
  31. if ($this->cid) {
  32. $id = $this->cid;
  33. $code = QrCode::format('png')->size(600)->generate(config('app.code_url') . "?cid={$id}");
  34. $file_path = "codes/{$id}.png";
  35. Storage::disk(config('admin.upload.disk'))->put($file_path, $code);
  36. LibraryCategory::query()->where('id', $id)->update([
  37. 'code_path' => $file_path
  38. ]);
  39. }
  40. }
  41. }