瀏覽代碼

新玩法,socket推送

lizhen_gitee 1 年之前
父節點
當前提交
8ab38a0f65
共有 2 個文件被更改,包括 24 次插入20 次删除
  1. 21 17
      application/api/controller/Grabgift.php
  2. 3 3
      application/common/library/GatewayworkerTools.php

+ 21 - 17
application/api/controller/Grabgift.php

@@ -121,6 +121,7 @@ class Grabgift extends Api
         $winer_nickname = '';
         $new_seatnum = $seat_number;//因为开奖之后,要用新一期的座位数
 
+        //座位满了,开奖
         if($count == $seat_number){
 
             $rand_data_new = [];
@@ -190,6 +191,7 @@ class Grabgift extends Api
         }
         Db::commit();
 
+        //推送内容
         $user_list = Db::name('grabgift_log')->alias('log')->field('log.myseatnum,user.nickname,user.id as user_id,user.avatar')
             ->join('user','log.user_id = user.id','LEFT')
             ->where('log.grab_id',$grab_id)->order('log.myseatnum asc')->select();
@@ -209,8 +211,18 @@ class Grabgift extends Api
             'user_list' => $user_list
         ];
 
-        //socket推送
-        $this->grabgift_notice($result);
+        //坐上座位socket推送
+        $this->grabgift_notice('grabgift',$result);
+
+        //开奖倒计时socket推送
+        if($count == $seat_number){
+
+            $data = [
+                'grab_id' => $grab_id,
+                'nowtime' => time(),
+            ];
+            $this->grabgift_notice('daojishi',$data);
+        }
 
         $this->success(1,$result);
     }
@@ -224,29 +236,21 @@ class Grabgift extends Api
 
     }
 
-    //送礼完成之后,大礼物飘屏
-    private function grabgift_notice($result){
+    //socket,通知所有人
+    private function grabgift_notice($type,$result){
         $notice = new GatewayworkerTools();
-        $notice->sendGrabgift($result);
+        $notice->sendGrabgift($type,$result);
     }
 
     public function test(){
-        $result = [
-            'grab_id'     => 1,
-            'count'       => 4,
-            'is_finish'   => 0,
-            'seat_number' => 5,
-            'nickname'    => '加入者昵称',
-            'user_id'     => 1,
-            'avatar'      => '/1.jpg',
-            'gift_name'   => '礼物名',
-            'winer_nickname'    => '中奖者昵称',
+        $data = [
+            'grab_id' => 1,
+            'nowtime' => time(),
         ];
-        $this->grabgift_notice($result);
+        $this->grabgift_notice('daojishi',$data);
     }
 
 
 
 
-
 }

+ 3 - 3
application/common/library/GatewayworkerTools.php

@@ -11,12 +11,12 @@ class GatewayworkerTools
 {
 
     /**
-     * 直播间中发送大礼物,全服通告
+     * 房间中全民抢礼物,全服通告
      */
-    public static function sendGrabgift($data)
+    public static function sendGrabgift($type,$data)
     {
         $messageData = [
-            'type'    => 'grabgift',
+            'type'    => $type,
             'data'    => $data
         ];