From 2ebc3bdd5a38cb2646660683cd4b9cb397617273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=92=8A?= Date: Tue, 14 Oct 2025 10:21:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=9C=80=E6=B1=82-=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E9=9C=80=E6=B1=82-=E7=9B=B2=E7=9B=92=E8=BD=AC=E7=9B=98?= =?UTF-8?q?=E8=B0=83=E9=80=9A=E7=9B=98-=E8=B0=83=E8=AF=95-=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Activities.php | 2 +- .../model/BlindBoxTurntableGiftDrawWorld.php | 70 ++++++++++--------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/application/api/controller/Activities.php b/application/api/controller/Activities.php index a1b926a..ef5108c 100644 --- a/application/api/controller/Activities.php +++ b/application/api/controller/Activities.php @@ -137,7 +137,7 @@ class Activities extends BaseCom //规则 $data['rule'] = get_system_config_value('web_site')."/api/Page/page_show?id=13"; $ext = json_decode($gift_bag['ext'],true); - $data['money'] = $ext['money']; + $data['money'] = $gift_bag['money']; $data['counter'] = $ext['counter']; $data['money'] = $ext['money_str']; $data['diamond'] = $ext['diamond']; diff --git a/application/api/model/BlindBoxTurntableGiftDrawWorld.php b/application/api/model/BlindBoxTurntableGiftDrawWorld.php index 67ca1a7..bd7f7cd 100644 --- a/application/api/model/BlindBoxTurntableGiftDrawWorld.php +++ b/application/api/model/BlindBoxTurntableGiftDrawWorld.php @@ -103,7 +103,6 @@ class BlindBoxTurntableGiftDrawWorld extends Model } catch (\Exception $e) { $key = 'blind_box_draw_errors_' . date('Y-m-d-H-i-s'); $errorData = [ - 'error_message' => $e->getMessage(), 'gift_bag_id' => $gift_bag_id, 'user_id' => $user_id, 'gift_user_ids' => $gift_user_ids, @@ -112,8 +111,7 @@ class BlindBoxTurntableGiftDrawWorld extends Model 'heart_id' => $heart_id, 'auction_id' => $auction_id, ]; - $this->redis->setex($key, 86400 * 7, json_encode($errorData)); - + $this->redis->setex($key, 86400 * 7, $e->getMessage(). ' ' .json_encode($errorData)); return ['code' => 0, 'msg' => "网络加载失败,请重试!", 'data' => null]; } @@ -219,11 +217,11 @@ class BlindBoxTurntableGiftDrawWorld extends Model $giftInfoMap = $this->preloadGiftInfo($availableGifts); // 4. 处理奖池重置逻辑 - $needGiftNum = count($toarray) * $num; + $needGiftNum = count($toarray) * $num; //总需要的礼物数 $remaining_available_gifts=[]; - if ($totalRemaining - $needGiftNum <= 0) { - $remaining_available_gifts = $availableGifts; - $availableGifts = $this->resetPoolAndReload($bag_data['id']); + if ($totalRemaining - $needGiftNum <= 0) {//奖池剩余数量-需要的礼物数小于0 + $remaining_available_gifts = $availableGifts; //剩余可用礼物 + $availableGifts = $this->resetPoolAndReload($bag_data['id']); //重置奖池并重新加载 if (empty($availableGifts)) { throw new \Exception('重置奖池后仍无可用礼物'); } @@ -727,7 +725,7 @@ class BlindBoxTurntableGiftDrawWorld extends Model private function handleXlhPiaoPing($room_id, $xlh_ext, $xlhIsPiaoPing,$room){ if($xlhIsPiaoPing == 1){ // 即将开始推送飘屏 - $text = $room['room_name']."的巡乐会即将开始..."; + $text = "巡乐会即将开始..."; // 推送礼物横幅 $push = new Push(UID, $room_id); $text_list_new = [ @@ -739,7 +737,7 @@ class BlindBoxTurntableGiftDrawWorld extends Model } if($xlhIsPiaoPing == 2){ // 正式开始推送飘屏 - $text = $room['room_name']."已正式开启巡乐会游戏..."; + $text = "巡乐会游戏已正式开启..."; // 推送礼物横幅 $push = new Push(UID, $room_id); $text_list_new = [ @@ -783,13 +781,22 @@ class BlindBoxTurntableGiftDrawWorld extends Model }else{ $xlh['status'] = 0; } - // 推送 - $text = [ + // 推送进度条 + $push = new Push(UID, $room_id); + $text_list_new = [ 'xlh_data' => $xlh, - 'text' => "" + 'text' => "", + 'from_type' => 0 ]; + $push->xunlehui($text_list_new); + // 聊天室推送系统消息 - model('Chat')->sendMsg(1056,$room_id,$text); + // 推送 +// $text = [ +// 'xlh_data' => $xlh, +// 'text' => "" +// ]; +// model('Chat')->sendMsg(1056,$room_id,$text); } /** * 统计礼物数量 @@ -979,27 +986,14 @@ class BlindBoxTurntableGiftDrawWorld extends Model public function xlh_draw_gift($user_id, $num, $room_id) { $gift_bag_id = 13; - // 1. 获取并缓存盲盒配置 - $cacheKey = "xlh_config_{$gift_bag_id}"; $ext = $this->getCachedXlhConfig(); - // 2. 检查用户金币和房间状态 $bag_gift_price = $ext['xlh_box_price'] * $num; $user_waller = db::name('user_wallet')->where(['user_id' => $user_id])->find(); if (!$user_waller || $user_waller['coin'] < $bag_gift_price) { return ['code' => 0, 'msg' => '用户金币不足', 'data' => null]; } - - $room = db::name('vs_room') - ->field('id,room_name,is_open_blind_box_turntable,xlh_periods') - ->where(['id' => $room_id]) - ->find(); - $bag_data = db::name("vs_gift_bag") - ->field('id,name,ext,periods') - ->where('id', $gift_bag_id) - ->find(); - // 3. 检查巡乐会状态 $pan_xlh = db::name('vs_room_pan_xlh') ->order('id', 'desc') @@ -1189,7 +1183,13 @@ class BlindBoxTurntableGiftDrawWorld extends Model $total_processed += $current_batch; } catch (\Exception $e) { db::rollback(); - Log::record('巡乐会抽奖失败: ' . $e->getMessage(),"infos"); + $key = 'xlh_draw_gift_errors_' . date('Y-m-d-H-i-s'); + $errorData = [ + 'user_id' => $user_id, + 'gift_bag_id' => $gift_bag_id, + 'room_id' => $room_id, + ]; + $this->redis->setex($key, 86400 * 7, $e->getMessage(). ' ' .json_encode($errorData)); return ['code' => 0, 'msg' => "抽奖中,请稍等...", 'data' => null]; } } @@ -1254,7 +1254,7 @@ class BlindBoxTurntableGiftDrawWorld extends Model // 8. 处理推送消息 if ($is_zhong_jiang == 1) { - $this->handlePrizeNotification($user_id,$gift_id, $room_id, $pan_xlh_num, $end_time, $room['room_name'],$ext['locking_condition']['locking_gift_id']); + $this->handlePrizeNotification($user_id,$gift_id, $room_id, $pan_xlh_num, $end_time,$ext['locking_condition']['locking_gift_id']); } // 9. 构建返回结果 @@ -1353,29 +1353,35 @@ class BlindBoxTurntableGiftDrawWorld extends Model /** * 巡乐会抽奖-处理中奖通知 */ - private function handlePrizeNotification($user_id,$gift_id, $room_id, $pan_xlh_num, $end_time, $room_name,$locking_gift_id) + private function handlePrizeNotification($user_id,$gift_id, $room_id, $pan_xlh_num, $end_time,$locking_gift_id) { $FromUserInfo = db::name('user')->field('nickname,avatar')->where(['id' => $user_id])->find(); $gift_info = db::name('vs_gift')->field('gift_name')->where(['gid' => $gift_id])->find(); $locking_gift = db::name('vs_gift')->field('gift_name')->where(['gid' => $locking_gift_id])->find(); + $room_data = db::name('vs_room')->field('room_name,user_id')->where(['id' => $room_id])->find(); + $room_user = db::name('user')->where('id',$room_data['user_id'])->field('nickname,avatar')->find(); //锁定礼物 $text = [ 'gift_num' => $pan_xlh_num, 'FromUserInfo' => $FromUserInfo, 'end_time' => $end_time, - 'text' => $FromUserInfo['nickname'] . ' 在 ' . $room_name . ' 房间巡乐会中 获得' . $gift_info['gift_name'] . '礼物 x 1' + 'text' => $FromUserInfo['nickname'] . ' 在 ' . ' 巡乐会活动中 获得' . $gift_info['gift_name'] . '礼物 x 1' ]; model('Chat')->sendMsg(1057, $room_id, $text); //推送礼物横幅 - $text = $FromUserInfo['nickname'] . ' 在 ' . $room_name.' 房间巡乐会锁定礼物'.$locking_gift['gift_name'].' x ' .$pan_xlh_num ; + $text = $FromUserInfo['nickname'] .' 巡乐会活动中锁定礼物'.$locking_gift['gift_name'].' x ' .$pan_xlh_num ; $push = new Push(0, $room_id); $text_list_new = [ 'text' => $text, 'room_id' => $room_id, - 'from_type' => 1 + 'from_type' => 4, + 'gift_num' => $pan_xlh_num, + 'FromUserInfo' => $FromUserInfo, + 'end_time' => $end_time, + 'room_user' => $room_user ]; $push->xunlehui($text_list_new); }