盲盒转盘代码优化
This commit is contained in:
@@ -610,55 +610,11 @@ class GiveGift extends Model
|
||||
|
||||
//送给一人礼物的总价格(扣除用户的数额)
|
||||
$gift_price = $gift_info['gift_price'] * $num;
|
||||
|
||||
$roomId = 0;
|
||||
if($from_type == 2 || $from_type == 3 || $from_type == 6){
|
||||
$roomId = $from_id;
|
||||
}
|
||||
//金币购买送礼 1金币购买 2送背包礼物
|
||||
if ($type == 1) {
|
||||
if(!isset($ext['is_draw_gift']) || $ext['is_draw_gift'] != 1){// 非盲盒转盘
|
||||
//送给所有人的总价格
|
||||
$all_gift_price = $gift_info['gift_price'] * $num * count($toarray);
|
||||
//判断是否有足够的金币
|
||||
$user_waller = db::name('user_wallet')->where(['user_id'=>$uid])->find();
|
||||
if ($user_waller['coin'] < $all_gift_price) {
|
||||
return ['code' => 0, 'msg' => '用户金币不足', 'data' => null];
|
||||
}
|
||||
//扣除用户金币并记录日志
|
||||
$wallet_update = $this -> change_user_cion_or_earnings_log($uid,$all_gift_price,$from_id,1,10,'用户金币购买礼物');
|
||||
if(!$wallet_update){
|
||||
return ['code' => 0, 'msg' => '扣除用户金币失败', 'data' => null];
|
||||
}
|
||||
//用户财富等级更新
|
||||
$user_level = model('Level')->user_level_data_update($uid,$all_gift_price,1,$roomId);
|
||||
if(!$user_level){
|
||||
return ['code' => 0, 'msg' => '用户等级更新失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//背包礼物是否充足
|
||||
$user_gift_pack = db::name('vs_user_gift_pack')->where(['user_id'=>$uid,'gid'=>$gid])->find();
|
||||
if (empty($user_gift_pack)) {
|
||||
return ['code' => 0, 'msg' => '用户背包礼物不足', 'data' => null];
|
||||
}
|
||||
if ($user_gift_pack['num'] < $num * count($toarray)) {
|
||||
return ['code' => 0, 'msg' => '用户背包礼物不足', 'data' => null];
|
||||
}
|
||||
//扣除背包礼物并记录日志
|
||||
if($from_type == 1 || $from_type == 2 || $from_type == 3 || $from_type == 6){//1聊天送礼物 2房间语聊送礼 3直播送礼 4动态打赏 5系统任务
|
||||
$packType = 3;//1系统赠送2礼包获得3礼物赠送4系统扣除,5动态打赏
|
||||
$remark = '聊天或房间礼物赠送';
|
||||
}elseif ($from_type == 4){
|
||||
$packType = 5;
|
||||
$remark = '动态打赏';
|
||||
}else{
|
||||
$packType = -1;
|
||||
}
|
||||
$gift_pack = $this -> change_user_gift_pack_log($packType,$uid,$gid,$num * count($toarray),$remark);
|
||||
if(!$gift_pack){
|
||||
return ['code' => 0, 'msg' => '扣除用户背包礼物失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//循环送礼
|
||||
$gift_total = 0;
|
||||
@@ -668,45 +624,11 @@ class GiveGift extends Model
|
||||
$gift_user_data[]['user_id'] = $to_id;
|
||||
$gift_box1 = [];
|
||||
$gift_box = [];
|
||||
//查询礼物是否是盲盒
|
||||
if($gift_info['label'] == 2){//趣味礼物(盲盒)
|
||||
$gift_price_box = 0;
|
||||
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){
|
||||
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
|
||||
}
|
||||
$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){
|
||||
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){
|
||||
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;
|
||||
}else{
|
||||
$gift_total += $gift_price;
|
||||
//收礼记录行为日志
|
||||
$give_gift = $this -> change_user_give_gift_log($uid,$gid,$gift_price,$num,$to_id,$from_type,$type,$from_id,$pit_number);
|
||||
if(!$give_gift){
|
||||
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
|
||||
}
|
||||
$gift_total += $gift_price;
|
||||
//收礼记录行为日志
|
||||
$give_gift = $this -> change_user_give_gift_log($uid,$gid,$gift_price,$num,$to_id,$from_type,$type,$from_id,$pit_number);
|
||||
if(!$give_gift){
|
||||
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
|
||||
}
|
||||
$gift_user_data[$k]['gift_price'] = $gift_price;
|
||||
|
||||
@@ -905,150 +827,6 @@ class GiveGift extends Model
|
||||
model('Chat')->sendMsg(1015,$roomPKinfo['room_id_b'],$text);
|
||||
}
|
||||
}
|
||||
//推送礼物特效
|
||||
if(!isset($ext['is_draw_gift']) || $ext['is_draw_gift'] != 1){// 非盲盒转盘 推送
|
||||
if($gift_info['label'] == 2){
|
||||
//循环开出来的盲盒,相同的礼物只推送一次,消息推送为$FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' .$gift_inf['gift_name'].' x 多少';
|
||||
if($gift_box){
|
||||
// 统计相同礼物的数量
|
||||
$giftCount = [];
|
||||
foreach ($gift_box as $key=>$gv) {
|
||||
$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();
|
||||
if (isset($giftCount[$gv['gift_id']])) {
|
||||
$giftCount[$gv['gift_id']]['count']++;
|
||||
} else {
|
||||
$giftCount[$gv['gift_id']] = [
|
||||
'gift_info' => $gift_info,
|
||||
'count' => 1
|
||||
];
|
||||
}
|
||||
$gift_box[$key]['gift_name'] = $gift_info['gift_name'];
|
||||
}
|
||||
|
||||
// 构建文字消息内容
|
||||
$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,
|
||||
'GiftInfos' => array_values($gift_box),
|
||||
'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
|
||||
];
|
||||
|
||||
// 聊天室推送礼物特效消息
|
||||
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,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
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 = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfo' => $ToUserInfo,
|
||||
'GiftInfo' => $gift_info,
|
||||
'GiftNum' => $num,
|
||||
'text' => $text
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
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($gift_info['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'] . $gift_info['gift_name'] . 'X' . $num;
|
||||
$text_list_new[] = [
|
||||
'text' => $text,
|
||||
'gift_picture' => $gift_info['base_image'],
|
||||
'room_id' => $from_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $gift_info['gift_name'],
|
||||
'roomId' => $from_id,
|
||||
'number' => $num,
|
||||
];
|
||||
$push->giftBanner($text_list_new);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//直播间送礼物 每日任务
|
||||
model('DailyTasks')->tasks_complete($uid,3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user