新需求: 盲盒转盘开发-转盘抽奖接口开发-抽奖记录接口 -送礼接口调整

This commit is contained in:
2025-08-19 18:09:48 +08:00
parent 2767f64a67
commit 251ffc84a8
4 changed files with 274 additions and 113 deletions

View File

@@ -38,7 +38,7 @@ class GiveGift extends Model
* @return array
* 用户,在房间中,给谁,送了什么礼物,多少个,来源
*/
public function give_gift($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0)
public function give_gift($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0,$ext = [])
{
//送的礼物信息
$gift_info = Db::name('vs_gift')->where(['gid'=>$gid])
@@ -133,22 +133,35 @@ class GiveGift extends Model
//查询礼物是否是盲盒
if($gift_info['label'] == 2){//趣味礼物(盲盒)
$gift_price_box = 0;
for($i = 0; $i < $num; $i++){
$gift_box1[$i] = $this -> open_box($gid,$uid,$to_id,$from_id);
if($gift_box1[$i]['code'] != 1){
Db::rollback();
return ['code' => 0, 'msg' => '盲盒配置有误请联系管理员'.$gift_box1[$i]['msg'], 'data' => null];
}
$gift_box[$i] = $gift_box1[$i]['data'];
//记录一下收礼记录
$give_gift = $this -> change_user_give_gift_log($uid,$gift_box[$i]['gift_id'],$gift_box[$i]['gift_price'],1,$to_id,$from_type,$type,$from_id,$pit_number,2);
if(isset($ext['is_draw_gift']) && $ext['is_draw_gift'] == 1){
//收礼记录行为日志
$give_gift = $this -> change_user_give_gift_log($uid,$ext['gift_id'],$ext['all_gift_price'],$ext['count'],$to_id,$from_type,$type,$from_id,$pit_number,2);
if(!$give_gift){
Db::rollback();
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
}
$gift_box[$i]['give_gift_id'] = $give_gift;
$gift_price_box += $gift_box[$i]['gift_price'];
Log::record("盲盒礼物".json_encode($gift_box1),"info");
$gift_price_box = $ext['all_gift_price'];
$gift_box[0]['gift_id'] = $ext['gift_id'];
$gift_box[0]['gift_price'] = $ext['all_gift_price'];
$gift_box[0]['give_gift_id'] = $give_gift;
}else{
for($i = 0; $i < $num; $i++){
$gift_box1[$i] = $this -> open_box($gid,$uid,$to_id,$from_id);
if($gift_box1[$i]['code'] != 1){
Db::rollback();
return ['code' => 0, 'msg' => '盲盒配置有误请联系管理员'.$gift_box1[$i]['msg'], 'data' => null];
}
$gift_box[$i] = $gift_box1[$i]['data'];
//记录一下收礼记录
$give_gift = $this -> change_user_give_gift_log($uid,$gift_box[$i]['gift_id'],$gift_box[$i]['gift_price'],1,$to_id,$from_type,$type,$from_id,$pit_number,2);
if(!$give_gift){
Db::rollback();
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
}
$gift_box[$i]['give_gift_id'] = $give_gift;
$gift_price_box += $gift_box[$i]['gift_price'];
Log::record("盲盒礼物".json_encode($gift_box1),"info");
}
}
$gift_total += $gift_price_box;
$gift_price = $gift_price_box;
@@ -366,101 +379,146 @@ class GiveGift extends Model
}
//推送礼物特效
if($gift_info['label'] == 2){
//循环开出来的盲盒,相同的礼物只推送一次,消息推送为$FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' .$gift_inf['gift_name'].' x 多少';
if($gift_box){
// 统计相同礼物的数量
$giftCount = [];
foreach ($gift_box as $gv) {
if (isset($giftCount[$gv['gift_id']])) {
$giftCount[$gv['gift_id']]['count']++;
} else {
$giftCount[$gv['gift_id']] = [
'gift_info' => Db::name('vs_gift')->where(['gid'=>$gv['gift_id']])
->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_server')->find(),
'count' => 1
];
}
}
// 构建文字消息内容
$giftTextList = [];
foreach ($giftCount as $giftData) {
$gift_inf = $giftData['gift_info'];
$count = $giftData['count'];
$giftTextList[] = $gift_inf['gift_name'].' X'.$count;
}
// 推送文字消息 (格式: 张三 送给 李四 趣味礼物 礼物名1 X2礼物2 X4)
$textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' . implode('', $giftTextList);
$textData = [
if(isset($ext['is_draw_gift']) && $ext['is_draw_gift'] == 1){
$draw_gift = Db::name('vs_gift')->where(['gid'=>$ext['gift_id']])->find();
$textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 盲盒转盘礼物 ' . $draw_gift['gift_name'].' x ' .$ext['count'];
$text = [
'FromUserInfo' => $FromUserInfo,
'ToUserInfo' => $ToUserInfo,
'GiftInfo' => $draw_gift,
'GiftNum' => $draw_gift['gift_name'],
'text' => $textMessage
];
//聊天室推送系统消息
model('Chat')->sendMsg(1005,$from_id,$text);
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
if($roomtype == 6){
//推送消息
$hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6)
->sum('total_price');
$text1 = [
'room_id' => $from_id,
'hot_value' => $hot_value * 10,
'text' => '房间心动值变化'
];
//聊天室推送系统消息
model('Chat')->sendMsg(1028,$from_id,$text1);
}else{
if($draw_gift['is_public_server'] == 1){
//推送礼物横幅
$push = new Push(UID, $from_id);
$room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name');
$text = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $num;
$text_list_new = [
'text' => $text,
'gift_picture' => $draw_gift['base_image'],
'room_id' => $from_id,
'fromUserName' => $FromUserInfo['nickname'],
'toUserName' => $ToUserInfo['nickname'],
'giftName' => $draw_gift['gift_name'],
'roomId' => $from_id,
'number' => $num,
];
$push->giftBanner($text_list_new);
}
}
}else{
//循环开出来的盲盒,相同的礼物只推送一次,消息推送为$FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' .$gift_inf['gift_name'].' x 多少';
if($gift_box){
// 统计相同礼物的数量
$giftCount = [];
foreach ($gift_box as $gv) {
if (isset($giftCount[$gv['gift_id']])) {
$giftCount[$gv['gift_id']]['count']++;
} else {
$giftCount[$gv['gift_id']] = [
'gift_info' => Db::name('vs_gift')->where(['gid'=>$gv['gift_id']])
->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_server')->find(),
'count' => 1
];
}
}
// 构建文字消息内容
$giftTextList = [];
foreach ($giftCount as $giftData) {
$gift_inf = $giftData['gift_info'];
$count = $giftData['count'];
$giftTextList[] = $gift_inf['gift_name'].' X'.$count;
}
// 推送文字消息 (格式: 张三 送给 李四 趣味礼物 礼物名1 X2礼物2 X4)
$textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' . implode('', $giftTextList);
$textData = [
'FromUserInfo' => $FromUserInfo,
// 'ToUserInfo' => $ToUserInfo,
// 'GiftInfo' => $gift_info,
// 'GiftNum' => $num,
'text' => $textMessage
];
// 聊天室推送文字消息
model('Chat')->sendMsg(1038,$from_id,$textData);
// 循环推送每个礼物的特效消息
foreach ($giftCount as $giftId => $giftData) {
$gift_inf = $giftData['gift_info'];
$count = $giftData['count'];
// 推送礼物特效消息
$effectData = [
'FromUserInfo' => $FromUserInfo,
'ToUserInfo' => $ToUserInfo,
'GiftInfo' => $gift_inf,
'GiftNum' => $count,
'text' => null
'text' => $textMessage
];
// 聊天室推送文字消息
model('Chat')->sendMsg(1038,$from_id,$textData);
// 聊天室推送礼物特效消息
model('Chat')->sendMsg(1005,$from_id,$effectData);
// 循环推送每个礼物特效消息
foreach ($giftCount as $giftId => $giftData) {
$gift_inf = $giftData['gift_info'];
$count = $giftData['count'];
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
if($roomtype == 6){
//推送消息
$hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6)
->sum('total_price');
$text1 = [
'room_id' => $from_id,
'hot_value' => $hot_value * 10,
'text' => '房间心动值变化'
// 推送礼物特效消息
$effectData = [
'FromUserInfo' => $FromUserInfo,
'ToUserInfo' => $ToUserInfo,
'GiftInfo' => $gift_inf,
'GiftNum' => $count,
'text' => null
];
//聊天室推送系统消息
model('Chat')->sendMsg(1028,$from_id,$text1);
//电影房推送结束时间点
$text2 = [
'room_id' => $from_id,
'end_time' => time() + 60 * 60 * 24 * 7,
'text' => '房间结束时间点'
];
model('Chat')->sendMsg(1042,$from_id,$text2);
}else{
if($gift_inf['is_public_server'] == 1){
//推送礼物横幅
$push = new Push(UID, $from_id);
$room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name');
$bannerText = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $gift_inf['gift_name'] . 'X' . $count;
$text_list_new = [
'text' => $bannerText,
'gift_picture' => $gift_inf['base_image'],
// 聊天室推送礼物特效消息
model('Chat')->sendMsg(1005,$from_id,$effectData);
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
if($roomtype == 6){
//推送消息
$hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6)
->sum('total_price');
$text1 = [
'room_id' => $from_id,
'fromUserName' => $FromUserInfo['nickname'],
'toUserName' => $ToUserInfo['nickname'],
'giftName' => $gift_inf['gift_name'],
'roomId' => $from_id,
'number' => $count,
'hot_value' => $hot_value * 10,
'text' => '房间心动值变化'
];
$push->giftBanner($text_list_new);
//聊天室推送系统消息
model('Chat')->sendMsg(1028,$from_id,$text1);
//电影房推送结束时间点
$text2 = [
'room_id' => $from_id,
'end_time' => time() + 60 * 60 * 24 * 7,
'text' => '房间结束时间点'
];
model('Chat')->sendMsg(1042,$from_id,$text2);
}else{
if($gift_inf['is_public_server'] == 1){
//推送礼物横幅
$push = new Push(UID, $from_id);
$room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name');
$bannerText = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $gift_inf['gift_name'] . 'X' . $count;
$text_list_new = [
'text' => $bannerText,
'gift_picture' => $gift_inf['base_image'],
'room_id' => $from_id,
'fromUserName' => $FromUserInfo['nickname'],
'toUserName' => $ToUserInfo['nickname'],
'giftName' => $gift_inf['gift_name'],
'roomId' => $from_id,
'number' => $count,
];
$push->giftBanner($text_list_new);
}
}
}
}
}
}else{
$text = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 礼物 ' .$gift_info['gift_name'].' x ' .$num;
$text = [
@@ -1023,7 +1081,7 @@ class GiveGift extends Model
/*
* 开盲盒
*/
public function open_box($gift_id,$user_id,$gift_user_id,$room_id=0){
public function open_box($gift_id,$user_id,$gift_user_id,$room_id=0,$gift_bag_id=0){
//获取盲盒配置
$bag_list = db::name("vs_gift_bag")->field('id,name,ext,periods')->where(['activities_id'=>4,'status'=>1])->select();
$gift_bag_id = 0;