diff --git a/application/api/model/BlindBoxTurntableGift.php b/application/api/model/BlindBoxTurntableGift.php index f339622..bd7afe2 100644 --- a/application/api/model/BlindBoxTurntableGift.php +++ b/application/api/model/BlindBoxTurntableGift.php @@ -91,7 +91,7 @@ class BlindBoxTurntableGift extends Model $FromUserInfo['chat_bubble'] = model('Decorate')->user_decorate_detail($blind_box_turntable['user_id'],9);//聊天气泡 $user_nickname = $FromUserInfo['nickname']; $userGiftMap = []; - $giftCount = []; + $ToUserInfo = []; foreach ($blind_box_turntable_log as $key => $value) { $ToUserInfo = Db::name('user')->where(['id' => $value['gift_user_id']])->field('id as user_id,nickname,avatar,sex')->find(); $draw_gift = Db::name('vs_gift')->where(['gid'=>$value['gift_id']])->find(); @@ -117,19 +117,12 @@ class BlindBoxTurntableGift extends Model ]; } $userGiftMap[$userId]['gifts'][] = [ + 'gift_id' => $draw_gift['gid'], 'gift_name' => $draw_gift['gift_name'], 'count' => $value['count'], - 'play_image' => $draw_gift['play_image'] + 'play_image' => $draw_gift['play_image'], + 'base_image' => $draw_gift['base_image'] ]; - // 统计相同礼物的数量 - if (isset($giftCount[$value['gift_id']])) { - $giftCount[$value['gift_id']]['count']++; - } else { - $giftCount[$value['gift_id']] = [ - 'gift_info' => $draw_gift, - 'count' => 1 - ]; - } } // 为每个用户单独推送消息 @@ -140,8 +133,15 @@ class BlindBoxTurntableGift extends Model // 构建用户专属文本消息,接收者名字只出现一次 $userTextMessage = $user_nickname . ' 送给 ' . $userInfo['nickname']; // 添加该用户收到的所有礼物 + $giftCount = []; foreach ($gifts as $gift) { $userTextMessage .= ' 盲盒转盘礼物 ' . $gift['gift_name'].' x ' .$gift['count']; + // 统计相同礼物的数量 + $giftCount[] = [ + 'gift_info' => $gift, + 'count' => $gift['count'] + ]; + } $userInfo['icon'][0] = model('UserData')->user_wealth_icon($userInfo['user_id']); @@ -157,24 +157,26 @@ class BlindBoxTurntableGift extends Model // 聊天室推送系统消息给每个用户 model('Chat')->sendMsg(1038,$room_id,$userText); + + foreach ($giftCount as $giftData) { + $gift_inf = $giftData['gift_info']; + $count = $giftData['count']; + + // 推送礼物特效消息 + $effectData = [ + 'FromUserInfo' => $FromUserInfo, + 'ToUserInfo' => $userInfo, + 'GiftInfo' => $gift_inf, + 'gift_num' => $count, + 'text' => null + ]; + + // 聊天室推送礼物特效消息 + model('Chat')->sendMsg(1005,$room_id,$effectData); + } } // 循环推送每个礼物的特效消息 - foreach ($giftCount as $giftId => $giftData) { - $gift_inf = $giftData['gift_info']; - $count = $giftData['count']; - // 推送礼物特效消息 - $effectData = [ - 'FromUserInfo' => $FromUserInfo, - 'ToUserInfo' => $ToUserInfo, - 'GiftInfo' => $gift_inf, - 'gift_num' => $count, - 'text' => null - ]; - - // 聊天室推送礼物特效消息 - model('Chat')->sendMsg(1005,$room_id,$effectData); - } $roomtype = Db::name('vs_room')->where(['id' => $room_id])->value('type_id'); if($roomtype == 6){ @@ -198,7 +200,7 @@ class BlindBoxTurntableGift extends Model db::name('vs_blind_box_turntable_log')->where('id', $send_id)->update(['is_sued' => 1, 'updatetime' => time()]); return ['code' => 1, 'msg' => '成功', 'data' => null]; } catch (\Exception $e) { - return ['code' => 0, 'msg' => "网络请求错误,请重试!", 'data' => null]; + return ['code' => 0, 'msg' => "网络请求错误,请重试!".$e->getMessage(), 'data' => null]; } }