lizhen_gitee 1 год назад
Родитель
Сommit
1a945bfb9d

+ 31 - 8
application/api/controller/Grabgift.php

@@ -5,6 +5,7 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use think\Db;
 use Redis;
+use app\common\library\GatewayworkerTools;
 /**
  * 示例接口
  */
@@ -72,7 +73,7 @@ class Grabgift extends Api
     //立即加入
     public function joinin(){
         $grab_id = input('grab_id',0);
-        $kai_count = 5;
+        $seat_number = 5;
 
         //先用redis看开奖状态
         $status = $this->redis->get('kge_grabgift_'.$grab_id);
@@ -95,7 +96,7 @@ class Grabgift extends Api
 
         //数量限制
         $count = $this->redis->incr('kge_grabgift_num_'.$grab_id);
-        if ($count > $kai_count) {
+        if ($count > $seat_number) {
             $this->redis->decr('kge_grabgift_num_'.$grab_id);
             $this->redis->hDel('kge_grabgift_data_'.$grab_id,$this->auth->id);
             $this->error('此期人数已满');
@@ -133,19 +134,23 @@ class Grabgift extends Api
         }
 
         //如果是最后一个,开奖
-        if($count == $kai_count){
+        $gift_name = '';
+        $winer_nickname = '';
+
+        if($count == $seat_number){
 
             $rand_data_new = [];
             $rand_data = $this->redis->hGetAll('kge_grabgift_data_'.$grab_id);
             foreach($rand_data as $uid => $val){
                 $rand_data_new[] = $uid;
             }
-            $zhongjiang_uid = $rand_data_new[rand(0,4)];
+            $winer_uid = $rand_data_new[rand(0,4)];
+            $winer_nickname = Db::name('user')->where('id',$winer_uid)->value('nickname');
 
             //修改
             $nowtime = time();
             $rs1 = Db::name('grabgift_log')->where('grab_id',$grab_id)->update(['grabtime'=>$nowtime]);
-            $rs2 = Db::name('grabgift_log')->where('grab_id',$grab_id)->where('user_id',$zhongjiang_uid)->update(['grabstatus'=>1]);
+            $rs2 = Db::name('grabgift_log')->where('grab_id',$grab_id)->where('user_id',$winer_uid)->update(['grabstatus'=>1]);
             $rs3 = Db::name('grabgift')->where('id',$grab_id)->update(['status'=>1,'grabtime'=>$nowtime]);
 
             //发放到背包
@@ -163,6 +168,8 @@ class Grabgift extends Api
                     'createtime' => $nowtime,
                 ];
                 $rs4 = Db::name('gift_back')->insertGetId($giftdata);
+
+                $gift_name = $gift_info['name'];
             }else{
                 $rs4 = true;
             }
@@ -183,10 +190,20 @@ class Grabgift extends Api
         Db::commit();
 
         $result = [
-            'grab_id'=>$grab_id,
-            'count'  => $count,
-            'is_finish' => $count == $kai_count ? 1 : 0,
+            'grab_id'     => $grab_id,
+            'count'       => $count,
+            'is_finish'   => $count == $seat_number ? 1 : 0,
+            'seat_number' => $seat_number,
+            'nickname'    => $this->auth->nickname,
+            'user_id'     => $this->auth->id,
+            'avatar'      => localpath_to_netpath($this->auth->avatar),
+            'gift_name'    => $gift_name,
+            'winer_nickname'    => $winer_nickname,
         ];
+
+        //socket推送
+        $this->grabgift_notice($result);
+
         $this->success(1,$result);
     }
 
@@ -199,6 +216,12 @@ class Grabgift extends Api
 
     }
 
+    //送礼完成之后,大礼物飘屏
+    private function grabgift_notice($result){
+        $notice = new GatewayworkerTools();
+        $notice->sendGrabgift($result);
+    }
+
 
 
 

+ 4 - 17
application/common/library/GatewayworkerTools.php

@@ -13,25 +13,11 @@ class GatewayworkerTools
     /**
      * 直播间中发送大礼物,全服通告
      */
-    public static function sendBigGiftInParty($sender, $receiver, $partyInfo, $giftUserParty)
+    public static function sendGrabgift($data)
     {
         $messageData = [
-            'type'    => 'bigGiftNotice',
-            'data' => [
-                'party_info'  => [
-                    'party_id'   => $partyInfo['id'],
-                    'room_type'  => $partyInfo['room_type'],
-                    'party_name' => $partyInfo['party_name']
-                ],
-                'notice_info' => [
-                    'sender'         => $sender,
-                    'receiver'       => $receiver,
-                    'gift_num'       => $giftUserParty['number'],
-                    'gift_name'      => $giftUserParty['gift_name'],
-                    'gift_image'     => $giftUserParty['gift_gif_image'],
-                    'value'          => $giftUserParty['value'],
-                ]
-            ]
+            'type'    => 'grabgift',
+            'data'    => $data
         ];
 
         $Gateway = new Gateway();
@@ -41,6 +27,7 @@ class GatewayworkerTools
 
     /**
      * 直播间中发送礼物,本房间飘屏
+     * kge没用到
      */
     public static function sendGiftInParty($sender, $receiver, $partyInfo, $giftUserParty)
     {