GrabgiftJob.php 2.1 KB

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