From 2a508ce4d4344530f8023602a59dc723b68764e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Tue, 30 Sep 2025 14:36:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E6=97=B6=E6=A6=9C=E7=A4=BC=E7=89=A9?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +- .../adminapi/controller/RoomHourRanking.php | 185 ++++++++++++++---- application/api/model/Room.php | 44 +++-- application/api/model/Tencent.php | 28 +-- 4 files changed, 185 insertions(+), 76 deletions(-) diff --git a/.env b/.env index 766c404..376a98f 100644 --- a/.env +++ b/.env @@ -18,10 +18,10 @@ trace = false #hostport = 3306 #prefix = fa_ -hostname = 62.234.12.147 +hostname = 1.13.181.248 database = midi username = midi -password = EC6cak6fzXdXnERz +password = 5B2zwShhTi5L7t2w hostport = 3306 prefix = fa_ diff --git a/application/adminapi/controller/RoomHourRanking.php b/application/adminapi/controller/RoomHourRanking.php index 4c3f793..e93c83d 100644 --- a/application/adminapi/controller/RoomHourRanking.php +++ b/application/adminapi/controller/RoomHourRanking.php @@ -6,6 +6,36 @@ use think\Db; class RoomHourRanking { + public static function withdraw_status (){ + return [ + [25 => '全时段'], + [0 => '00:00-01:00'], + [1 => '01:00-02:00'], + [2 => '02:00-03:00'], + [3 => '03:00-04:00'], + [4 => '04:00-05:00'], + [5 => '05:00-06:00'], + [6 => '06:00-07:00'], + [7 => '07:00-08:00'], + [8 => '08:00-09:00'], + [9 => '09:00-10:00'], + [10 => '10:00-11:00'], + [11 => '11:00-12:00'], + [12 => '12:00-13:00'], + [13 => '13:00-14:00'], + [14 => '14:00-15:00'], + [15 => '15:00-16:00'], + [16 => '16:00-17:00'], + [17 => '17:00-18:00'], + [18 => '18:00-19:00'], + [19 => '19:00-20:00'], + [20 => '20:00-21:00'], + [21 => '21:00-22:00'], + [22 => '22:00-23:00'], + [23 => '23:00-00:00'], + ]; + } + //房间小时榜列表 public function room_hour_ranking() @@ -32,7 +62,7 @@ class RoomHourRanking $v['room_name'] = db::name('vs_room')->where(['id'=>$v['room_id']])->value('room_name'); $v['user_id'] = db::name('vs_room')->where(['id'=>$v['room_id']])->value('user_id'); if($v['user_id']){ - $v['nickname'] = db::name('vs_user')->where(['id'=>$v['user_id']])->value('nickname'); + $v['nickname'] = db::name('user')->where(['id'=>$v['user_id']])->value('nickname'); } } @@ -77,34 +107,15 @@ class RoomHourRanking //时间段对应关系 public function time_period_correspondence() { - $list = [ - [25 => '全时段'], - [0 => '00:00-01:00'], - [1 => '01:00-02:00'], - [2 => '02:00-03:00'], - [3 => '03:00-04:00'], - [4 => '04:00-05:00'], - [5 => '05:00-06:00'], - [6 => '06:00-07:00'], - [7 => '07:00-08:00'], - [8 => '08:00-09:00'], - [9 => '09:00-10:00'], - [10 => '10:00-11:00'], - [11 => '11:00-12:00'], - [12 => '12:00-13:00'], - [13 => '13:00-14:00'], - [14 => '14:00-15:00'], - [15 => '15:00-16:00'], - [16 => '16:00-17:00'], - [17 => '17:00-18:00'], - [18 => '18:00-19:00'], - [19 => '19:00-20:00'], - [20 => '20:00-21:00'], - [21 => '21:00-22:00'], - [22 => '22:00-23:00'], - [23 => '23:00-00:00'], - ]; - return V(1,"成功", $list); + $list = $this->withdraw_status(); + $timePeriods = $this->withdraw_status(); + $timeMap = []; + foreach($timePeriods as $period) { + foreach($period as $key => $value) { + $timeMap[$key] = $value; + } + } + return V(1,"成功", $timeMap); } @@ -122,24 +133,118 @@ class RoomHourRanking //核心配置列表 public function core_config_list() { - $list = db::name('vs_hour_ranking_gift_config') - ->group('time_id') - ->select(); - var_dump($list); + $list = db::name('vs_hour_ranking_gift_config')->select(); + $data = []; if($list){ - $lis = $this->time_period_correspondence()['data']; - foreach ($list as $k => $v){ - $list[$k]['time_id'] = $lis[$v['time_id']] ; - $list[$k]['time_id']['index'] = $k + 1; - $list[$k]['time_id']['content'] = $k + 1; + // 获取时间段对应关系 + $timePeriods = $this->withdraw_status(); + $timeMap = []; + foreach($timePeriods as $period) { + foreach($period as $key => $value) { + $timeMap[$key] = $value; + } + } + // 按时间段和排名分组数据 + $groupedData = []; + foreach ($list as $item) { + $timeId = $item['time_id']; + $ranking = $item['ranking']; + + if (!isset($groupedData[$timeId])) { + $groupedData[$timeId] = []; + } + + if (!isset($groupedData[$timeId][$ranking])) { + $groupedData[$timeId][$ranking] = []; + } + + // 根据礼物类型确定值 + if($item['gift_type'] == 1) { + $value = $item['coin']; + } else { + $value = $item['gift_id']; + } + + $groupedData[$timeId][$ranking][] = [ + 'type' => $item['gift_type'], + 'value' => $value + ]; + } + + // 构建最终数据结构 + foreach ($groupedData as $timeId => $rankings) { + $timeKey = $timeMap[$timeId] ?? "未知时间段"; + $data[$timeKey] = []; + + // 按排名排序 + ksort($rankings); + + foreach ($rankings as $ranking => $contents) { + $data[$timeKey][] = [ + 'index' => $ranking, + 'content' => $contents + ]; + } } } - - return V(1,"成功", $list); + return V(1, "成功", $data); } + + public function core_config_lists() + { + $list = db::name('vs_hour_ranking_gift_config')->select(); + $data = []; + + // 按 time_id 和 ranking 重组数据 + $reorganizedData = []; + $timePeriods = $this->withdraw_status(); + + // 构建正确的时间映射关系 + $timeMap = []; + foreach($timePeriods as $period) { + foreach($period as $key => $value) { + $timeMap[$key] = $value; + } + } + + foreach ($list as $item) { +// $timeId = $item['time_id']; + $timeId = $timeMap[$item['time_id']] ?? '未知时间段'; + $ranking = $item['ranking']; + + if (!isset($reorganizedData[$timeId])) { + $reorganizedData[$timeId] = []; + } + if (!isset($reorganizedData[$timeId][$ranking])) { + $reorganizedData[$timeId][$ranking] = []; + } + if($item['gift_id']){ + if($item['gift_type'] == 2){ + $gift_name = db::name('vs_gift')->where(['gid'=>$item['gift_id']])->value('gift_name'); + } + if($item['gift_type'] == 3 || $item['gift_type'] == 4){ + $gift_name = db::name('vs_decorate')->where(['did'=>$item['gift_id']])->value('title'); + } + + }else{ + $gift_name = ''; + } + $reorganizedData[$timeId][$ranking][] = [ + 'gift_type' => $item['gift_type'], + 'gift_id' => $item['gift_id'], + 'gift_name' => $gift_name, + 'coin' => $item['coin'] + ]; + } + + // 输出重组后的数据 + print_r($reorganizedData); + return V(1, "成功", $data); + } + } diff --git a/application/api/model/Room.php b/application/api/model/Room.php index 0dec574..d02977b 100644 --- a/application/api/model/Room.php +++ b/application/api/model/Room.php @@ -2594,30 +2594,34 @@ class Room extends Model if(!$room_id){ return ['code' => 0, 'msg' => '参数错误', 'data' => null]; } - if($type == 1){//1-切后台,2-切前台 - $is_bg = db::name('vs_user_in_room_bg')->where(['user_id' => $user_id,'room_id' => $room_id])->find(); - if($is_bg){ - $up_bg = [ - 'updatetime' => time(), - ]; - db::name('vs_user_in_room_bg')->where('id',$is_bg['id'])->update($up_bg); - }else{ - $data = [ - 'user_id' => $user_id, - 'room_id' => $room_id, - 'createtime' => time(), - 'updatetime' => time(), - ]; - $room_background = db::name('vs_user_in_room_bg')->insert($data); - if(!$room_background){ - return ['code' => 0, 'msg' => '操作失败', 'data' => null]; + $room_t = db::name('vs_room')->field('type_id,label_id')->where('id',$room_id)->find(); + if(!(($room_t == 1 || $room_t == 8) && $room_t['label_id'] == 1)){ + if($type == 1){//1-切后台,2-切前台 + $is_bg = db::name('vs_user_in_room_bg')->where(['user_id' => $user_id,'room_id' => $room_id])->find(); + if($is_bg){ + $up_bg = [ + 'updatetime' => time(), + ]; + db::name('vs_user_in_room_bg')->where('id',$is_bg['id'])->update($up_bg); + }else{ + $data = [ + 'user_id' => $user_id, + 'room_id' => $room_id, + 'createtime' => time(), + 'updatetime' => time(), + ]; + $room_background = db::name('vs_user_in_room_bg')->insert($data); + if(!$room_background){ + return ['code' => 0, 'msg' => '操作失败', 'data' => null]; + } } - } - }else{ - db::name('vs_user_in_room_bg')->where(['user_id' => $user_id,'room_id' => $room_id])->delete(); + }else{ + db::name('vs_user_in_room_bg')->where(['user_id' => $user_id,'room_id' => $room_id])->delete(); + } } + return ['code' => 1, 'msg' => '操作成功', 'data' => null]; } } \ No newline at end of file diff --git a/application/api/model/Tencent.php b/application/api/model/Tencent.php index 46a1b5d..dfe6074 100644 --- a/application/api/model/Tencent.php +++ b/application/api/model/Tencent.php @@ -925,21 +925,21 @@ class Tencent extends Model if($quit_room) { foreach ($quit_room as $v){ - $room_type = db::name('vs_room')->where(['id' => $v['room_id'],'room_status' => 1])->field('step,type_id,label_id')->find(); - if(isset($room_type) && ($room_type['type_id'] == 7 && ($room_type['step'] == 2 ||$room_type['step'] == 3)) || $room_type == 2){ - $text['text'] = '掉线!'; - $text['user_id'] = $uid; - $text['type'] = 2; - model('Chat')->sendMsg(1058,$v['room_id'],$text); - }elseif(isset($room_type) && ($room_type['type_id'] == 1||$room_type['type_id'] == 8) && $room_type['label_id'] == 1){ + $room_type = db::name('vs_room')->where(['id' => $v['room_id']])->field('step,type_id,label_id')->find(); + if($room_type['label_id'] == 1 && ($room_type['type_id'] == 1 || $room_type['type_id'] == 8)){ Db::name('user')->where('id', $uid)->update(['is_online' => 1, 'updatetime' => time()]); -// return true; - }else - { - //查询是否有切后台的操作 - $bg_room = db::name('vs_user_in_room_bg')->where(['room_id' => $v['room_id'],'user_id' => $v['user_id']])->find(); - if(!$bg_room){ - model('Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id'],2); + }else{ + if(isset($room_type) && ($room_type['type_id'] == 7 && ($room_type['step'] == 2 ||$room_type['step'] == 3)) || $room_type == 2){ + $text['text'] = '掉线!'; + $text['user_id'] = $uid; + $text['type'] = 2; + model('Chat')->sendMsg(1058,$v['room_id'],$text); + }else { + //查询是否有切后台的操作 + $bg_room = db::name('vs_user_in_room_bg')->where(['room_id' => $v['room_id'],'user_id' => $v['user_id']])->find(); + if(!$bg_room){ + model('Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id'],2); + } } } }