Browse Source

用户排行榜使用新接口,新redis数据

lizhen_gitee 1 năm trước cách đây
mục cha
commit
b752fd439f
1 tập tin đã thay đổi với 40 bổ sung86 xóa
  1. 40 86
      application/api/controller/Party.php

+ 40 - 86
application/api/controller/Party.php

@@ -43,51 +43,6 @@ class Party extends Api
         parent::__construct();
     }
 
-    //记录所有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      本月第一天
-
-        //在线人列表。hSet增加,HDel减少, hGetAll来使用。大多用来计算数量 count(hGetAll),少数获取用户列表
-        //online_1
-
-        //房间列表页的用户头像 。zAdd增加,zRem减少,zRange来使用。 party_user_1 总是 与 online_1 共同出现,加的时候一起加,减的时候一起减。多处维护,只有 RoomService/getPartyUserList 这个方法有使用到
-        //party_user_1
-
-        //用户进房
-        //joinParty_days
-
-        //在线用户在房间情况。当前用户在哪个房间
-        //livingUser
-
-        //派对管理 1=房管,2=禁言,3=拉黑,4=踢出
-        //party_manage_1
-
-        //用户魅力值
-        //hourCharm_1
-
-        //用户排行榜前三名头像
-        //user_jewel_top3
-
-        //排麦
-        //party_lineup
-    }
-
 
     /**
      * 创建/进入派对
@@ -609,6 +564,25 @@ class Party extends Api
         return $this->success("获取成功!",$res);
     }
 
+    //获取派对用户排序(魅力榜,财富榜),有数值的在上,0的在下
+    public function getPartyUserRank_new() {
+        $party_id = input("party_id");// 派对ID
+        if (!$party_id) $this->error(__('Invalid parameters'));
+
+        $userModel = new \app\common\model\User();
+
+        // 获取50条魅力排行日记录
+        $getday = $this->redis->zRevRange("hourCharm_".$party_id,0,-1,true);
+        $res['getRankListDay'] = $userModel->rankList($getday);
+
+        // 获取50条财富排行日记录
+        $today  = $this->redis->zRevRange("hourWealth_".$party_id,0,-1,true);
+        $res['toRankListDay'] = $userModel->rankList($today);
+
+        return $this->success("获取成功!",$res);
+    }
+
+
     /**
      * 派对热度更新(已废弃)
      */
@@ -850,8 +824,8 @@ class Party extends Api
         $this->redis->hSet("livingUser", $user_id, $party_id);
         //下移
 
-        // 获取用户魅力值
-        $users = $this->redis->zRange("hourCharm_".$party_id,0,-1,true);
+        // 获取用户魅力值。大概率没用了
+        $users = $this->redis->zRevRange("hourCharm_".$party_id,0,-1,true);
         $u = [];
         if($users) {
             foreach($users as $k => $v) $u[] = [
@@ -1789,7 +1763,7 @@ class Party extends Api
         $money_to_jewel = config('site.money_to_jewel') ?: 10; //余额兑换金币
 
         // 不可以赠送给自己
-        //if(in_array($userauthid,$user_id_arr)) $this->error("不可以赠送给自己!");
+        if(in_array($userauthid,$user_id_arr)) $this->error("不可以赠送给自己!");
 
         $backGiftId = 0; //背包礼物表的 gift_id
         $boxgiftInfo = [];
@@ -1991,6 +1965,7 @@ class Party extends Api
 
                         // tcp 更新用户魅力值
                         $this->updateUserCharm($party_id, $user_id, $hotValue);
+                        $this->updateUserWealth($party_id, $user_id, $hotValue);
 
                         //更新麦位魅力值
                         //$this->updateSeatCharm($partyInfo['easemob_room_id'],$seat_id_arr[$user_id_key],$hotValue,$partyInfo);
@@ -2051,8 +2026,8 @@ class Party extends Api
                 $returnData['baobi_beilv'] = $res_baobi['baobi_beilv'];
             }
 
-            // 获取用户魅力值
-            $users = $this->redis->zRange("hourCharm_".$party_id,0,-1,true);
+            // 获取用户魅力值。大概率没用了
+            $users = $this->redis->zRevRange("hourCharm_".$party_id,0,-1,true);
             $u = [];
             if($users) {
                 foreach($users as $k => $v) $u[] = [
@@ -2344,7 +2319,7 @@ class Party extends Api
 
 
         // 获取用户魅力值
-        $users = $this->redis->zRange("hourCharm_".$party_id,0,-1,true);
+        $users = $this->redis->zRevRange("hourCharm_".$party_id,0,-1,true);
 
         if(!$users) $users[$user_id] = 0;
 
@@ -2358,55 +2333,34 @@ class Party extends Api
         return true;
 
     }
-
     /**
-     *  用户赠送礼物后房间内麦位魅力值增加,更新到麦位自定义信息
-     * $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]);
+    private function updateUserWealth($party_id,$user_id,$giftValue) {
 
-        if(empty($seatdata)){
-            //默认为空
-            $seatdata = [
-                'charm'    => 0,                    //红心,魅力值
 
-                'isMaster'       => false,            // 是否是房主
-                'headUrl'        => '',              // 头像
-                'userNo'         => '',               // 座位上用户no
-                'rtcUid'         => '',               // 座位上用户id,与rtc的userId一致
-                'name'           => '',                 // 座位上用户昵称
-                'seatIndex'      => $seatnum,               // 座位编号
-                'chorusSongCode' => '',             // 是否合唱
-                'isAudioMuted'   => 1,            // 是否静音
-                'isVideoMuted'   => 0,            // 是否开启视频
-                'checked'        => false,       // 用于送礼物选择用户
-                'isUsed'         => true,          // 用于送礼物选择用户
-                'gender'         => 1, //性别
-            ];
-        }else{
-            $seatdata = json_decode($seatdata[$key],true);
-        }
+        // 获取用户魅力值
+        $users = $this->redis->zRevRange("hourWealth_".$party_id,0,-1,true);
 
-        //魅力值自增
-        $seatdata['charm'] += $giftValue;
+        if(!$users) $users[$user_id] = 0;
 
-        //重新设置
-        $matedata = [
-            $key  => json_encode($seatdata),
-        ];
-        $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$party_info['user_id'],$matedata);
+        if(isset($users[$user_id])) {
+            $value = $users[$user_id] + $giftValue;
+        } else {
+            $value = $giftValue;
+        }
+        $this->redis->zAdd("hourWealth_".$party_id,$value,$user_id);
 
         return true;
+
     }
 
 
 
 
 
+
+
     /**
      * 单个房间魅力值清零
      */