From a588175a9e75fc22659197d8db78626bf5bb65bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Wed, 14 Jan 2026 14:06:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=81=E7=9B=B2=E7=9B=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/SendGift.php | 58 ++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/application/api/model/SendGift.php b/application/api/model/SendGift.php index 6d3bcb19..3662394e 100644 --- a/application/api/model/SendGift.php +++ b/application/api/model/SendGift.php @@ -270,6 +270,7 @@ class SendGift extends Model $receive_gift_total = 0;//收礼人收到的礼物总值 $gift_box = [];//开出的盲盒 $gift_box_str = ''; + $gift_box_map = []; //查询礼物是否是盲盒 if($gift_info['label'] == 2){//趣味礼物(盲盒) @@ -281,17 +282,36 @@ class SendGift extends Model return ['code' => 0, 'msg' => '网络错误-3', 'data' => null]; } $gift_box[$i] = $gift_box1[$i]['data']; + //礼物整合 - $gift_box_str .= $gift_box[$i]['gift_name'] . 'x' . $gift_box[$i]['num'].'/'; + $gift_id = $gift_box[$i]['gift_id']; + $gift_name = $gift_box[$i]['gift_name']; + + if(isset($gift_box_map[$gift_id])){ + // 如果礼物ID已存在,数量加1 + $gift_box_map[$gift_id]['count']++; + }else{ + // 如果礼物ID不存在,添加新项 + $gift_box_map[$gift_id] = [ + 'name' => $gift_name, + 'count' => 1 + ]; + } + //开出的礼物价值 $receive_gift_total += $gift_box[$i]['gift_price']; - - Log::record("送礼开出盲盒礼物信息:".json_encode($gift_box1),"info"); } - $gift_box_str = substr($gift_box_str,0,-1);//去掉最后一个/ + if(!empty($gift_box_map)){ + //拼接礼物字符串 (娃哈哈 * 2 / 娃哈哈1 * 1)这种格式 + $gift_box_str_parts = []; + foreach($gift_box_map as $gift_id => $gift_info_data){ + $gift_box_str_parts[] = $gift_info_data['name'] . ' * ' . $gift_info_data['count']; + } + $gift_box_str = implode(' / ', $gift_box_str_parts); + } + }else{ $receive_gift_total = $gift_price; - } //计算收礼人得益 //1聊天送礼物 2房间语聊送礼 3直播送礼 4动态打赏 99房主收益 98主持人收益 @@ -769,7 +789,6 @@ class SendGift extends Model $gift_user_data[]['user_id'] = $to_uid; $receive_gift_total = 0;//收礼人收到的礼物总值 $gift_box = [];//开出的盲盒 - $give_gift = 0;//送礼记录表ID(雪花ID) //送礼 开启事务 Db::startTrans(); @@ -801,12 +820,30 @@ class SendGift extends Model $gift_box[$i] = $gift_box1[$i]['data']; //开出的礼物价值 $receive_gift_total += $gift_box[$i]['gift_price']; + //礼物整合 - $gift_box_str .= $gift_box[$i]['gift_name'] . 'x' . $gift_box[$i]['num'].'/'; - Log::record("送礼开出盲盒礼物信息:".json_encode($gift_box1),"info"); + $gift_id = $gift_box[$i]['gift_id']; + $gift_name = $gift_box[$i]['gift_name']; + + if(isset($gift_box_map[$gift_id])){ + // 如果礼物ID已存在,数量加1 + $gift_box_map[$gift_id]['count']++; + }else{ + // 如果礼物ID不存在,添加新项 + $gift_box_map[$gift_id] = [ + 'name' => $gift_name, + 'count' => 1 + ]; + } + } + if(!empty($gift_box_map)){ + //拼接礼物字符串 (娃哈哈 * 2 / 娃哈哈1 * 1)这种格式 + $gift_box_str_parts = []; + foreach($gift_box_map as $gift_id => $gift_info_data){ + $gift_box_str_parts[] = $gift_info_data['name'] . ' * ' . $gift_info_data['count']; + } + $gift_box_str = implode(' / ', $gift_box_str_parts); } - //去掉最后一个/ - $gift_box_str = substr($gift_box_str,0,strlen($gift_box_str)-1); }else{ $receive_gift_total = $gift_price; } @@ -1418,6 +1455,7 @@ class SendGift extends Model $result_data = [ 'gift_id'=>$gift_bag_detail['foreign_id'], 'gift_price'=>$gift['gift_price'], + 'gift_name'=>$gift['gift_name'], 'is_public_screen'=>$gift['is_public_screen'], ]; return ['code' => 1, 'msg' => '成功', 'data' => $result_data];