Selaa lähdekoodia

赠送礼物修改麦位小红心

lizhen_gitee 1 vuosi sitten
vanhempi
commit
5ff023aa4f
2 muutettua tiedostoa jossa 64 lisäystä ja 11 poistoa
  1. 58 5
      application/api/controller/Party.php
  2. 6 6
      application/api/controller/Test.php

+ 58 - 5
application/api/controller/Party.php

@@ -1448,13 +1448,14 @@ class Party extends Common
         }*/
         }*/
 
 
         //接收参数
         //接收参数
-        $user_ids  = input("user_id");// 赠送对象
+        $user_ids  = input("user_id");// 赠送对象用户id
+        $seat_ids  = input("seat_id");// 赠送对象麦位id
         $gift_id   = input("gift_id");// 礼物ID。如果是背包赠送,则是gift_back表的id,这样不合理,但是已经不好改了
         $gift_id   = input("gift_id");// 礼物ID。如果是背包赠送,则是gift_back表的id,这样不合理,但是已经不好改了
         $party_id  = input("party_id",0);// 派对ID
         $party_id  = input("party_id",0);// 派对ID
         $room_type = input('room_type',1); // 房间类型
         $room_type = input('room_type',1); // 房间类型
         $number    = input("number");// 赠送数量
         $number    = input("number");// 赠送数量
 
 
-        if (!$user_ids || !in_array($is_back,[0,1]) || !$gift_id || !$number || !in_array($room_type,[1,2]))
+        if (!$user_ids || !$seat_ids || !in_array($is_back,[0,1]) || !$gift_id || !$number || !in_array($room_type,[1,2]))
         {
         {
             $this->error(__('Invalid parameters'));
             $this->error(__('Invalid parameters'));
         }
         }
@@ -1464,7 +1465,13 @@ class Party extends Common
 
 
         //处理参数
         //处理参数
         $user_id_arr = explode(",",$user_ids);
         $user_id_arr = explode(",",$user_ids);
+        $seat_id_arr = explode(",",$seat_ids);
         $userCount = count($user_id_arr);
         $userCount = count($user_id_arr);
+        $seatCount = count($seat_id_arr);
+        if($userCount != $seatCount){
+            $this->error();
+        }
+
         $userauthid = $this->auth->id;
         $userauthid = $this->auth->id;
         $money_to_jewel = config('site.money_to_jewel') ?: 10; //余额兑换钻石
         $money_to_jewel = config('site.money_to_jewel') ?: 10; //余额兑换钻石
 
 
@@ -1552,7 +1559,7 @@ class Party extends Common
             $platRate = 10;
             $platRate = 10;
             $guilderRate = 30;
             $guilderRate = 30;
         } else {
         } else {
-            $partyInfo = \app\common\model\Party::field("id,room_type,party_name,party_hot,user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
+            $partyInfo = \app\common\model\Party::field("id,room_type,party_name,party_hot,user_id,platRate,guilderRate,easemob_room_id")->where(["id"=>$party_id])->find();
             // 获取系统配置信息
             // 获取系统配置信息
             $platRate    = $partyInfo->platRate; // 平台抽成百分比
             $platRate    = $partyInfo->platRate; // 平台抽成百分比
             $guilderRate = $partyInfo->guilderRate; // 工会长抽成百分比
             $guilderRate = $partyInfo->guilderRate; // 工会长抽成百分比
@@ -1581,7 +1588,7 @@ class Party extends Common
             if($userCount > 1){
             if($userCount > 1){
                 $touserInfo_arr = Db::name('user')->where('id','IN',$user_id_arr)->column('id,nickname,u_id');
                 $touserInfo_arr = Db::name('user')->where('id','IN',$user_id_arr)->column('id,nickname,u_id');
             }
             }
-            foreach($user_id_arr as $user_id) {
+            foreach($user_id_arr as $user_id_key => $user_id) {
                 // 获取赠送用户信息
                 // 获取赠送用户信息
                 if($userCount > 1){
                 if($userCount > 1){
                     $touserInfo = $touserInfo_arr[$user_id];
                     $touserInfo = $touserInfo_arr[$user_id];
@@ -1699,6 +1706,9 @@ class Party extends Common
                         // tcp 更新用户魅力值
                         // tcp 更新用户魅力值
                         $this->updateUserCharm($party_id, $user_id, $hotValue);
                         $this->updateUserCharm($party_id, $user_id, $hotValue);
 
 
+                        //更新麦位魅力值
+                        $this->updateSeatCharm($partyInfo['easemob_room_id'],$seat_id_arr[$user_id_key],$hotValue,$partyInfo);
+
                         // 如果是主播,则添加魅力值记录做榜单统计
                         // 如果是主播,则添加魅力值记录做榜单统计
                         /*if($room_type == 2) {
                         /*if($room_type == 2) {
                             $data = [];
                             $data = [];
@@ -2060,7 +2070,6 @@ class Party extends Common
         return $avatarArr;
         return $avatarArr;
     }
     }
 
 
-
     /**
     /**
      *  用户赠送礼物后房间内用户魅力值增加
      *  用户赠送礼物后房间内用户魅力值增加
      */
      */
@@ -2083,6 +2092,50 @@ class Party extends Common
 
 
     }
     }
 
 
+    /**
+     *  用户赠送礼物后房间内麦位魅力值增加,更新到麦位自定义信息
+     * $seatnum 座位数字 1,不是键名 seat1
+     */
+    private function updateSeatCharm($easemob_room_id,$seatnum,$giftValue,$party_info) {
+        //获取已有信息
+        $key = 'seat'.$seatnum;
+        $easemob = new easemob();
+        $seatdata = $easemob->room_getRoomCustomAttribute($easemob_room_id,[$key]);
+
+        if(empty($seatdata)){
+            //默认为空
+            $seatdata = [
+                'charm'    => 0,                    //红心,魅力值
+
+                'isMaster'       => false,            // 是否是房主
+                'headUrl'        => '',              // 头像
+                'userNo'         => '',               // 座位上用户no
+                'rtcUid'         => '',               // 座位上用户id,与rtc的userId一致
+                'name'           => '',                 // 座位上用户昵称
+                'seatIndex'      => $seatnum,               // 座位编号
+                'chorusSongCode' => '',             // 是否合唱
+                'isAudioMuted'   => 1,            // 是否静音
+                'isVideoMuted'   => 0,            // 是否开启视频
+            ];
+        }else{
+            $seatdata = json_decode($seatdata[$key],true);
+        }
+
+        //魅力值自增
+        $seatdata['charm'] += $giftValue;
+
+        //重新设置
+        $matedata = [
+            $key  => json_encode($seatdata),
+        ];
+        $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$party_info['user_id'],$matedata);
+
+        return true;
+    }
+
+
+
+
 
 
     /**
     /**
      * 单个房间魅力值清零
      * 单个房间魅力值清零

+ 6 - 6
application/api/controller/Test.php

@@ -80,20 +80,20 @@ class Test extends Api
     //获取聊天室属性
     //获取聊天室属性
     public function getmetadata(){
     public function getmetadata(){
         $easemob = new Easemob();
         $easemob = new Easemob();
-        $room_id = 230909536174085;
+        $room_id = 230909515202562;
 
 
-        $key = 'seat2';
-        $key2 = 'seat22';
+        $key = 'seat1';
+        $key2 = 'seat2';
 
 
         //可以一个,可以多个,不能有重复
         //可以一个,可以多个,不能有重复
         $keys = [$key,$key2];
         $keys = [$key,$key2];
         //空数组,则全返回
         //空数组,则全返回
-        $keys = [];
+        //$keys = [];
 
 
         $rs = $easemob->room_getRoomCustomAttribute($room_id,$keys);
         $rs = $easemob->room_getRoomCustomAttribute($room_id,$keys);
         dump($rs);
         dump($rs);
-        dump($rs[$key]);
-        dump($rs[$key2]);
+        //dump($rs[$key]);
+        //dump($rs[$key2]);
     }
     }
 
 
     //强制删除聊天室属性
     //强制删除聊天室属性