GrabgiftJob.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Jobs;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Foundation\Bus\Dispatchable;
  6. use Illuminate\Queue\InteractsWithQueue;
  7. use Illuminate\Queue\SerializesModels;
  8. use Illuminate\Support\Facades\Redis;
  9. use Illuminate\Support\Facades\Log;
  10. class GrabgiftJob implements ShouldQueue
  11. {
  12. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  13. protected $params;
  14. protected $redis;
  15. /**
  16. * Create a new job instance.
  17. *
  18. * @return void
  19. */
  20. public function __construct($params)
  21. {
  22. $this->params = $params;
  23. $this->redis = Redis::connection();
  24. Log::info(date('Y-m-d H:i:d').':'.json_encode($params));
  25. }
  26. /**
  27. * Execute the job.
  28. *
  29. * @return void
  30. */
  31. public function handle()
  32. {
  33. $grab_id = $this->params['grab_id'];
  34. $new_grab_id = $this->params['new_grab_id'];
  35. $seat_number = $this->params['seat_number'];
  36. //开奖了,旧的一期结束了
  37. $this->redis->del('kge_grabgift_num_'.$grab_id);
  38. $this->redis->del('kge_grabgift_data_'.$grab_id);
  39. $this->redis->del('kge_grabgift_'.$grab_id);
  40. //新的一期开始了
  41. $this->redis->set('kge_grabgift_'.$new_grab_id,$seat_number);
  42. $this->redis->set('kge_grabgift_lastgrabid',$new_grab_id);
  43. $this->redis->set('kge_grabgift_lock',0);
  44. $data = [
  45. 'grab_id' => $new_grab_id,
  46. 'kge_grabgift_lock' => 0,
  47. ];
  48. $this->sendGrabgift('startnew',$data);
  49. }
  50. /**
  51. * 房间中全民抢礼物,全服通告
  52. */
  53. public static function sendGrabgift($type,$data)
  54. {
  55. $messageData = [
  56. 'type' => $type,
  57. 'data' => $data
  58. ];
  59. $Gateway = new Gateway();
  60. $Gateway::$registerAddress = '127.0.0.1:2345';
  61. $Gateway::sendToAll(json_encode($messageData));
  62. }
  63. }