Jelajahi Sumber

解散派对

lizhen_gitee 1 tahun lalu
induk
melakukan
8c3c724d39

+ 1 - 1
application/api/controller/Easemob.php

@@ -296,7 +296,7 @@ class Easemob extends Api
 
     }
 
-    //待唱,增加
+    //清除某个麦位
     private function clean_seat($easemob_room_id,$uid){
 
         $party_info = Db::name('party')->where('easemob_room_id',$easemob_room_id)->find();

+ 105 - 12
application/api/controller/Party.php

@@ -47,6 +47,51 @@ class Party extends Common
         parent::__construct($request);
     }
 
+    //记录所有redis key
+    //$partyid = 1
+    public function redis_key(){
+
+        //派对热度
+        //partyRank,liveRank
+
+        //派对详情
+        //party_1,live_1
+
+        //派对魅力榜
+        //party_jewel_get_1:20231123d,live_jewel_get_1:20231123d  今天
+        //party_jewel_get_1:20231120w,live_jewel_get_1:20231120w  本周第一天
+        //party_jewel_get_1:20231101m,live_jewel_get_1:20231101m  本月第一天
+
+        //派对财富榜
+        //party_jewel_to_1:20231123d,live_jewel_to_1:20231123d      今天
+        //party_jewel_to_1:20231120w,live_jewel_to_1:20231120w      本周第一天
+        //party_jewel_to_1:20231101m,live_jewel_to_1:20231101m      本月第一天
+
+        //在线人列表
+        //online_1
+
+        //用户进房
+        //joinParty_days
+
+        //首页用户头像
+        //party_user_1
+
+        //在线用户在房间情况
+        //livingUser
+
+        //派对管理 1=房管,2=禁言,3=拉黑,4=踢出
+        //party_manage_1
+
+        //用户魅力值
+        //hourCharm_1
+
+        //用户排行榜前三名头像
+        //user_jewel_top3
+
+        //排麦
+        //party_lineup
+    }
+
 
     /**
      * 创建/进入派对
@@ -340,27 +385,68 @@ class Party extends Common
      */
     public function closeParty() {
 
-        $party_id = input('party_id'); // 派对ID
+        $party_id  = input('party_id'); // 派对ID
         $room_type = input('room_type',1); // 房间类型:1=派对,2=直播
-        if (!$party_id || !in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
+
+        if (!$party_id || !in_array($room_type,[1,2])) {
+            $this->error(__('Invalid parameters'));
+        }
 
         $partyInfo = \app\common\model\Party::where(["id"=>$party_id])->find();
-        if(!$partyInfo) $this->error(__('派对不存在!'));
+        if(!$partyInfo) {
+            $this->error(__('派对不存在!'));
+        }
 
+        if($partyInfo['user_id'] != $this->auth->id){
+            $this->error('房主才能解散');
+        }
 
-        // redis 删除
+        // redis操作
 
         //rediskey:派对热度
         $this->redis->zRem($this->roomTypeArr[$room_type]."Rank",$party_id);
-        //rediskey:派对详情
-        $this->redis->del($this->roomTypeArr[$room_type]."_".$party_id);
-        //清空房间所有人
-        //清空房间麦位
-        //清空房间待唱列表
 
+        //环信操作
+        $easemob_room_id = $partyInfo['easemob_room_id'];
+        if(!empty($easemob_room_id)){
+
+            //重置自定义属性
+            $online_user_num = [
+                'online_num' => 0,
+                'user_list'  => [],
+            ];
 
-        $this->success("删除成功!");
+            $matedata = [
+                'waitsing_list'  => json_encode([]),//清空房间待唱列表
+                'online_user_num' => json_encode($online_user_num),//当前房间在线的人
+            ];
+            $easemob = new easemob();
+            $easemob->room_setRoomCustomAttributeForced($partyInfo['easemob_room_id'],$partyInfo['user_id'],$matedata);
 
+            //重置麦位
+            $seatnum = $partyInfo['seatnum'];
+            $seatdata = [];
+            for($i=1;$i<=$seatnum;$i++){
+                $seat = [
+                    'charm'    => 0,                    //红心,魅力值
+
+                    'isMaster'       => false,            // 是否是房主
+                    'headUrl'        => '',              // 头像
+                    'userNo'         => '',               // 座位上用户no
+                    'rtcUid'         => '',               // 座位上用户id,与rtc的userId一致
+                    'name'           => '',                 // 座位上用户昵称
+                    'seatIndex'      => $i,               // 座位编号
+                    'chorusSongCode' => '',             // 是否合唱
+                    'isAudioMuted'   => 1,            // 是否静音
+                    'isVideoMuted'   => 0,            // 是否开启视频
+                ];
+
+                $seatdata['seat'.$i] = json_encode($seat);
+            }
+            $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$this->auth->id,$seatdata);
+        }
+
+        $this->success();
     }
 
 
@@ -512,7 +598,7 @@ class Party extends Common
     /**
      * 派对热度更新(已废弃)
      */
-    public function changeUserPartyhot() {
+    /*public function changeUserPartyhot() {
         $party_id = input('party_id',0,"intval"); // 派对ID
         $room_type = input('room_type',1); // 房间类型
         $party_hot = input('party_hot'); // 房间热度(正数表示提高的热度值,负数表示降低的热度值)
@@ -523,7 +609,7 @@ class Party extends Common
         // 更新热度
         $this->redis->zIncrBy($this->roomTypeArr[$room_type]."Rank", $party_hot, $party_id);
         return $this->success("更新成功!");
-    }
+    }*/
 
 
     /**
@@ -2386,6 +2472,8 @@ class Party extends Common
         $this->success(1,$singlist);
     }
 
+
+
     //轮询所有房间,挨个赋值新的初始化自定义属性
     public function room_task(){
         exit;
@@ -2395,6 +2483,10 @@ class Party extends Common
         foreach($ids as $key => $party){
 
             //[环信]初始化房间
+            $online_user_num = [
+                'online_num' => 0,
+                'user_list'  => [],
+            ];
             $matedata = [
                 'seatnum'=> $party['seatnum'],//麦位数量
                 'waitsing_list'  => json_encode([]),//已点歌曲列表
@@ -2402,6 +2494,7 @@ class Party extends Common
                 'party_logo' => localpath_to_netpath($party['party_logo']),//logo
                 'is_public'  => $party['is_public'],//是否公开
                 'room_type'  => $party['room_type'],//房间类型
+                'online_user_num' => json_encode($online_user_num),//当前房间在线的人
             ];
             $rs = $easemob->room_setRoomCustomAttributeForced($party['easemob_room_id'],$party['user_id'],$matedata);
 

+ 4 - 4
application/api/controller/Usercenter.php

@@ -72,7 +72,7 @@ class UserCenter extends Common
 
 
         // 获取用户在派对直播间情况信息
-        $redis = new Redis();
+        /*$redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
         if ($redisconfig['redis_pwd']) {
@@ -87,7 +87,7 @@ class UserCenter extends Common
         if ($livingUserPartyId) {
             $party = \app\common\model\Party::where('id',$livingUserPartyId)->field('id,room_type')->find();
             $userInfo['party_info'] = ['party_id' => $party['id'], 'room_type' => $party['room_type']];
-        }
+        }*/
 
         $memberinfo = Db::name('guild_member')->alias('m')->field('m.id as `member_id`,m.user_id,guild.name,guild.image,guild.member,guild.desc')->join('guild','m.guild_id = guild.id','LEFT')->where(['m.user_id'=>$user_id])->find();
         if ($memberinfo) {
@@ -301,7 +301,7 @@ class UserCenter extends Common
     /**
      * redis 数据恢复---非redis数据丢失请勿使用!!!!
      */
-    public function shujuhuifu() {
+    /*public function shujuhuifu() {
         $key = $this->request->request("key");// 操作验证 123456
         if($key != 123456) {
             $this->error(__('Invalid parameters'));
@@ -343,7 +343,7 @@ class UserCenter extends Common
             $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
         }
         $this->success("执行成功!");
-    }
+    }*/