|
@@ -0,0 +1,79 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Jobs;
|
|
|
+
|
|
|
+use Illuminate\Bus\Queueable;
|
|
|
+use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
+use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
+use Illuminate\Queue\InteractsWithQueue;
|
|
|
+use Illuminate\Queue\SerializesModels;
|
|
|
+
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
+
|
|
|
+class GrabgiftJob implements ShouldQueue
|
|
|
+{
|
|
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
+
|
|
|
+ protected $params;
|
|
|
+ protected $redis;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Create a new job instance.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function __construct($params)
|
|
|
+ {
|
|
|
+ $this->params = $params;
|
|
|
+ $this->redis = Redis::connection();
|
|
|
+ Log::info(date('Y-m-d H:i:d').':'.json_encode($params));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Execute the job.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function handle()
|
|
|
+ {
|
|
|
+ $grab_id = $this->params['grab_id'];
|
|
|
+ $new_grab_id = $this->params['new_grab_id'];
|
|
|
+ $seat_number = $this->params['seat_number'];
|
|
|
+
|
|
|
+ //开奖了,旧的一期结束了
|
|
|
+ $this->redis->del('kge_grabgift_num_'.$grab_id);
|
|
|
+ $this->redis->del('kge_grabgift_data_'.$grab_id);
|
|
|
+ $this->redis->del('kge_grabgift_'.$grab_id);
|
|
|
+
|
|
|
+ //新的一期开始了
|
|
|
+ $this->redis->set('kge_grabgift_'.$new_grab_id,$seat_number);
|
|
|
+ $this->redis->set('kge_grabgift_lastgrabid',$new_grab_id);
|
|
|
+
|
|
|
+ $this->redis->set('kge_grabgift_lock',0);
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'grab_id' => $new_grab_id,
|
|
|
+ 'kge_grabgift_lock' => 0,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->sendGrabgift('startnew',$data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 房间中全民抢礼物,全服通告
|
|
|
+ */
|
|
|
+ public static function sendGrabgift($type,$data)
|
|
|
+ {
|
|
|
+ $messageData = [
|
|
|
+ 'type' => $type,
|
|
|
+ 'data' => $data
|
|
|
+ ];
|
|
|
+
|
|
|
+ $Gateway = new Gateway();
|
|
|
+ $Gateway::$registerAddress = '127.0.0.1:2345';
|
|
|
+ $Gateway::sendToAll(json_encode($messageData));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|