SignQueueJob.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Basic;
  4. use App\Models\Enroll;
  5. use Carbon\Carbon;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Queue\SerializesModels;
  11. use Illuminate\Support\Facades\Cache;
  12. class SignQueueJob implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. /**
  16. * Create a new job instance.
  17. *
  18. * @return void
  19. */
  20. public $data;
  21. public function __construct($data)
  22. {
  23. $this->data=$data;
  24. }
  25. /**
  26. * Execute the job.
  27. *
  28. * @return void
  29. */
  30. public function handle()
  31. {
  32. $id=$this->data;
  33. $re=new Enroll();
  34. $season=Cache::remember('daweiboshi-szy-basic-info', Carbon::now()->addHours(2), function () {
  35. return Basic::where('id', '>', 0)->pluck('value', 'keys');
  36. });
  37. Cache::increment('SIGNNUMS',1);
  38. $num=Cache::get('SIGNNUMS');
  39. $queue=0;
  40. if ($season->type==0){
  41. if ($num>$season['limit_num']){
  42. $queue=1;
  43. }
  44. }
  45. $re->user_id=$id;
  46. $re->season=$season->season;
  47. $re->type=$season->type;
  48. $re->timeout_time=Carbon::now()->addMinutes(5);
  49. $re->enroll_no=mb_substr(time(),4,6).random_int(11111,99999).str_pad($id, 6, 0, STR_PAD_LEFT);
  50. $re->is_queue=$queue;
  51. $re->save();
  52. // $count=Enroll::where('is_queue')
  53. }
  54. }