更新
This commit is contained in:
416
application/api/model/BlindBoxTurntableGift.php
Normal file
416
application/api/model/BlindBoxTurntableGift.php
Normal file
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use app\common\controller\Push;
|
||||
use think\Cache;
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use think\Session;
|
||||
/*
|
||||
* 盲盒转盘
|
||||
* 2025-08-16
|
||||
*/
|
||||
class BlindBoxTurntableGift extends Model
|
||||
{
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = true;
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $table = 'fa_vs_gift';
|
||||
|
||||
//获取奖池礼物列表
|
||||
public function get_gift_list($gift_bag_id,$room_id)
|
||||
{
|
||||
$box = db::name('vs_gift_bag')->where('id',$gift_bag_id)->find();
|
||||
$gifts = db::name('vs_gift_bag_detail')->where('gift_bag_id',$gift_bag_id)->order("id desc")->select();
|
||||
$gift_list = [];
|
||||
foreach ($gifts as $key => $value) {
|
||||
$gift_data = db::name('vs_gift')->where('gid',$value['foreign_id'])->where('delete_time',0)->find();
|
||||
if($gift_data){
|
||||
$gift_list[$key]['number'] = $key;
|
||||
$gift_list[$key]['gift_id'] = $gift_data['gid'];
|
||||
$gift_list[$key]['gift_name'] = $gift_data['gift_name'];
|
||||
$gift_list[$key]['base_image'] = $gift_data['base_image'];
|
||||
$gift_list[$key]['play_image'] = $gift_data['play_image'];
|
||||
$gift_list[$key]['gift_price'] = $gift_data['gift_price'];
|
||||
}
|
||||
}
|
||||
$ext = json_decode($box['ext'],true);
|
||||
$box_gift = Db::name('vs_gift')->where('gid',$ext['gift_id'])->find();
|
||||
|
||||
//巡乐会
|
||||
$is_xlh = 0;
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id',13)->find();
|
||||
$xlh_ext = json_decode($xlh_box['ext'],true);
|
||||
$xlh = [];
|
||||
if($xlh_ext['inlet_bag_id'] == $box['id']){
|
||||
$is_xlh = 1;
|
||||
$xlh['waiting_start_num'] = $xlh_ext['open_condition']['waiting_start_num'];//等待开奖次数
|
||||
$xlh['start_num'] = $xlh_ext['open_condition']['start_num'];//开始开奖次数
|
||||
//当前抽奖次数
|
||||
$xlh['current_num'] = Cache::get("xlh_periods_num") ?? 0;
|
||||
//状态
|
||||
if($xlh['current_num'] >= $xlh_ext['open_condition']['start_num']){
|
||||
$xlh['status'] = 1;//状态 1:巡乐会开始 2:即将开始开始 0:等待开始
|
||||
} elseif($xlh['current_num'] >= $xlh_ext['open_condition']['waiting_start_num'] && $xlh['current_num'] < $xlh_ext['open_condition']['start_num']){
|
||||
$xlh['status'] = 2;//状态 1:巡乐会开始 2:即将开始开始 0:等待开始
|
||||
}else{
|
||||
$xlh['status'] = 0;
|
||||
}
|
||||
}
|
||||
$result_data = [
|
||||
'title' => $box['name'],
|
||||
'rule_url' => get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$box["id"],
|
||||
'box_price' => $box_gift['gift_price'],
|
||||
'is_xlh' => $is_xlh,
|
||||
'xlh_data' => $xlh,
|
||||
'gift_list' => $gift_list,
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $result_data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 礼物特效播放
|
||||
*/
|
||||
public function gift_send($send_id){
|
||||
try{
|
||||
$blind_box_turntable = db('vs_blind_box_turntable_log')->where(['id'=>$send_id,'is_sued'=>0])->find();
|
||||
if(!$blind_box_turntable){
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => null];
|
||||
}
|
||||
$room_id = $blind_box_turntable['room_id'];
|
||||
$blind_box_turntable_log = db('vs_blind_box_turntable_results_log')->where(['tid'=>$send_id])->select();
|
||||
if(!$blind_box_turntable_log){
|
||||
return ['code' => 0, 'msg' => '数据不存在','data' => null];
|
||||
}
|
||||
$room_name = Db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->value('room_name');
|
||||
$FromUserInfo = Db::name('user')->where(['id'=>$blind_box_turntable['user_id']])->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($blind_box_turntable['user_id']);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($blind_box_turntable['user_id']);//魅力图标
|
||||
$user_nickname = $FromUserInfo['nickname'];
|
||||
$textMessage = $user_nickname;
|
||||
$text_message = [];
|
||||
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();
|
||||
$textMessage = $textMessage . ' 送给 ' . $ToUserInfo['nickname']. ' 盲盒转盘礼物 ' . $draw_gift['gift_name'].' x ' .$value['count']."\n";
|
||||
$play_image[] = $draw_gift['play_image'];
|
||||
$gift_names[] = $draw_gift['gift_name'];
|
||||
|
||||
$text_message = $user_nickname . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $value['count']."\n";
|
||||
if($draw_gift['is_public_server'] == 1) {
|
||||
$text_list_new[] = [
|
||||
'text' => $text_message,
|
||||
'gift_picture' => $draw_gift['base_image'],
|
||||
'room_id' => $room_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $draw_gift['gift_name'],
|
||||
'roomId' => $room_id,
|
||||
'number' => $value['count'],
|
||||
];
|
||||
}
|
||||
$ToUserInfosList[$value['gift_user_id']] = $ToUserInfo;
|
||||
|
||||
}
|
||||
foreach($ToUserInfosList as &$userInfo) {
|
||||
$userInfo['icon'][0] = model('UserData')->user_wealth_icon($userInfo['user_id']);//财富图标
|
||||
$userInfo['icon'][1] = model('UserData')->user_charm_icon($userInfo['user_id']);//魅力图标
|
||||
$userInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $userInfo['user_id'],'room_id' => $room_id])->value('charm');//魅力
|
||||
$ToUserInfos[] = $userInfo;
|
||||
}
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfos' => $ToUserInfos,
|
||||
'GiftInfo' => [
|
||||
'play_image' => implode(',',$play_image),
|
||||
'gift_name' => implode(',',$gift_names),
|
||||
],
|
||||
'text' => rtrim($textMessage, "\n")
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1005,$room_id,$text);
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $room_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息
|
||||
$hot_value = db::name('vs_give_gift')->where('from_id', $room_id)->where('from',6)
|
||||
->sum('total_price');
|
||||
$text1 = [
|
||||
'room_id' => $room_id,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1028,$room_id,$text1);
|
||||
}else{
|
||||
if(!empty($text_list_new)){
|
||||
//推送礼物横幅
|
||||
$push = new Push($blind_box_turntable['user_id'], $room_id);
|
||||
$push->giftBanner($text_list_new);
|
||||
}
|
||||
}
|
||||
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];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取用户抽奖记录
|
||||
*/
|
||||
public function get_user_record($gift_bag_id,$user_id=0,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['b.gift_bag_id'] = $gift_bag_id;
|
||||
if($user_id > 0){
|
||||
$where['b.user_id'] = $user_id;
|
||||
}
|
||||
$list = db('vs_blind_box_turntable_results_log')
|
||||
->alias('a')
|
||||
->join('vs_blind_box_turntable_log b','b.id = a.tid','left')
|
||||
->join('user c','a.gift_user_id = c.id','left')
|
||||
->join('vs_gift d','d.gid = a.gift_id','left')
|
||||
->field('a.gift_id,a.count,a.gift_user_id,a.createtime,c.nickname,d.gift_name as gift_name,d.base_image')
|
||||
->where($where)
|
||||
->order('a.createtime desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
/*
|
||||
* 获取全服抽奖记录
|
||||
*/
|
||||
public function get_all_record($gift_bag_id,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['b.gift_bag_id'] = $gift_bag_id;
|
||||
$where['d.gift_bag_id'] = $gift_bag_id;
|
||||
$where['d.is_world_show'] = 1;
|
||||
$list = db('vs_blind_box_turntable_results_log')
|
||||
->alias('a')
|
||||
->join('vs_blind_box_turntable_log b','b.id = a.tid','left')
|
||||
->join('user c','b.user_id = c.id','left')
|
||||
->join('vs_gift_bag_detail d','d.foreign_id = a.gift_id','left')
|
||||
->join('vs_gift e','e.gid = a.gift_id','left')
|
||||
->field('a.gift_id,a.count,b.user_id,a.createtime,c.nickname,d.name as gift_name,e.base_image')
|
||||
->where($where)
|
||||
->order('a.createtime desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
/*
|
||||
* 巡乐会
|
||||
*/
|
||||
public function xlh_gift_list($room_id){
|
||||
$gift_bag_id = 13;
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id',$gift_bag_id)->find();
|
||||
$xlh_ext = json_decode($xlh_box['ext'],true);
|
||||
$gifts = db::name('vs_gift_bag_detail')->where('gift_bag_id',$gift_bag_id)->order("id desc")->select();
|
||||
$gift_list = [];
|
||||
foreach ($gifts as $key => $value) {
|
||||
$gift_data = db::name('vs_gift')->where('gid',$value['foreign_id'])->where('delete_time',0)->find();
|
||||
if($gift_data){
|
||||
$gift_list[$key]['number'] = $key;
|
||||
$gift_list[$key]['gift_id'] = $gift_data['gid'];
|
||||
$gift_list[$key]['gift_name'] = $gift_data['gift_name'];
|
||||
$gift_list[$key]['base_image'] = $gift_data['base_image'];
|
||||
$gift_list[$key]['play_image'] = $gift_data['play_image'];
|
||||
$gift_list[$key]['gift_price'] = $gift_data['gift_price'];
|
||||
}
|
||||
}
|
||||
//房主信息
|
||||
// $room_user = db::name('user')->where('id',$room_data['user_id'])->find();
|
||||
//房主礼物
|
||||
$room_user_gift = db::name('vs_gift')->where('gid',$xlh_ext['locking_condition']['give_homeowner_gift_id'])->find();
|
||||
//巡乐会主礼物
|
||||
$xlh_main_gift = db::name('vs_gift')->where('gid',$xlh_ext['locking_condition']['locking_gift_id'])->find();
|
||||
//中奖用户
|
||||
$pan_xlh = db::name('vs_room_pan_xlh')->where(['send_time'=>0,'end_time'=>['>',time()]])->order('id desc')->find();
|
||||
$xlh_periods_num = Cache::get("xlh_periods_num") ?? 0;
|
||||
if(empty($pan_xlh)){
|
||||
if($xlh_periods_num >= $xlh_ext['open_condition']['start_num']){
|
||||
$xlh_periods = Cache::get("this_xlh_periods") ?? 0;
|
||||
$pan_xlh_id = db::name('vs_room_pan_xlh')->insertGetId([
|
||||
'room_id' => $room_id,
|
||||
'gift_id' => $xlh_ext['locking_condition']['locking_gift_id'],
|
||||
'homeowner_gift_id' => $xlh_ext['locking_condition']['give_homeowner_gift_id'],
|
||||
'periods' => $xlh_periods+1,
|
||||
'num' => 0,
|
||||
'end_time' => time() + $xlh_ext['locking_time']['end_time'] * 60,
|
||||
'createtime' => time()
|
||||
]);
|
||||
Cache::set("this_xlh_periods", $xlh_periods+1, 0);//修改巡乐会期数
|
||||
$pan_xlh = db::name('vs_room_pan_xlh')->where(['id'=>$pan_xlh_id])->find();
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '巡乐会已结束', 'data' => null];
|
||||
}
|
||||
}
|
||||
$xlh_user_data= null;
|
||||
$room_user_data = null;
|
||||
if($pan_xlh && $pan_xlh['user_id']){
|
||||
$xlh_user = db::name('user')->where('id',$pan_xlh['user_id'])->find();
|
||||
$xlh_user_data = [
|
||||
'user_id' => $xlh_user['id'],
|
||||
'nickname' => $xlh_user['nickname'],
|
||||
'avatar' => $xlh_user['avatar'],
|
||||
];
|
||||
if($pan_xlh['room_id']){
|
||||
$room_data = db::name('vs_room')->field('xlh_periods,xlh_periods_num,user_id')-> where('id',$pan_xlh['room_id'])->find();
|
||||
$room_user = db::name('user')->where('id',$room_data['user_id'])->find();
|
||||
$room_user_data = [
|
||||
'user_id' => $room_user['id'],
|
||||
'nickname' => $room_user['nickname'],
|
||||
'avatar' => $room_user['avatar'],
|
||||
];
|
||||
}
|
||||
}
|
||||
//$gift_list 按gift_price 升序排序
|
||||
usort($gift_list, function($a, $b) {
|
||||
return $a['gift_price'] - $b['gift_price'];
|
||||
});
|
||||
|
||||
$result_data = [
|
||||
'title' => $xlh_box['name'],
|
||||
'rule_url' => get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$xlh_box["id"],
|
||||
'box_price' => $xlh_ext['xlh_box_price'],
|
||||
'xlh_end_time' =>$pan_xlh['end_time']??0,
|
||||
'give_homeowner_gift' => [
|
||||
'gift_id' => $room_user_gift['gid'],
|
||||
'gift_name' => $room_user_gift['gift_name'],
|
||||
'gift_price' => $room_user_gift['gift_price'],
|
||||
'base_image' => $room_user_gift['base_image'],
|
||||
],
|
||||
'homeowner_user' => $room_user_data,
|
||||
'locking_gift' => [
|
||||
'gift_id' => $xlh_main_gift['gid'],
|
||||
'gift_name' => $xlh_main_gift['gift_name'],
|
||||
'gift_price' => $xlh_main_gift['gift_price'],
|
||||
'base_image' => $xlh_main_gift['base_image'],
|
||||
'gift_num' => $pan_xlh['num']??0
|
||||
],
|
||||
'xlh_user' => $xlh_user_data,
|
||||
'gift_list' => $gift_list,
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $result_data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会抽奖记录
|
||||
*/
|
||||
public function xlh_get_user_record($user_id,$room_id,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['a.gift_bag_id'] = 13;
|
||||
$where['a.user_id'] = $user_id;
|
||||
$list = db('vs_gift_bag_receive_pan_log')
|
||||
->alias('a')
|
||||
->join('vs_room_pan_xlh b','b.id = a.parent_id','left')
|
||||
->join('vs_gift c','c.gid = a.gift_id','left')
|
||||
->field('a.gift_id,a.num as count,a.createtime,c.gift_name as gift_name,c.base_image')
|
||||
->where($where)
|
||||
->order('a.createtime desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会榜单
|
||||
*/
|
||||
public function xlh_ranking($room_id,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['a.gift_bag_id'] = 13;
|
||||
$where['e.is_world_show'] = 1;
|
||||
$list = db('vs_gift_bag_receive_pan_log')
|
||||
->alias('a')
|
||||
->join('vs_room_pan_xlh b','b.id = a.parent_id','left')
|
||||
->join('vs_gift c','c.gid = a.gift_id','left')
|
||||
->join('fa_user d','d.id = a.user_id','left')
|
||||
->join('vs_gift_bag_detail e','e.foreign_id = a.gift_id','left')
|
||||
->field('a.gift_id,a.num as count,a.createtime,c.gift_name,c.base_image,d.nickname')
|
||||
->where($where)
|
||||
->order('a.createtime desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取用户当前房间的巡乐会信息
|
||||
*/
|
||||
public function get_user_xlh_info($room_id){
|
||||
$gift_bag_id = 13;
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id',$gift_bag_id)->find();
|
||||
$xlh_ext = json_decode($xlh_box['ext'],true);
|
||||
$xlh_data = db('vs_room_pan_xlh')->where(["send_time"=>0,"end_time"=>[">",time()]])->field('id,room_id,periods,end_time')->order('periods desc')->find();
|
||||
//寻乐会状态
|
||||
$xlh_status = 0;
|
||||
// 状态
|
||||
$xlh_periods_num = Cache::get("xlh_periods_num") ?? 0;
|
||||
if($xlh_periods_num >= $xlh_ext['open_condition']['start_num']){
|
||||
$xlh_status = 1;//状态 1:巡乐会开始 2:即将开始 0:等待开始
|
||||
} elseif($xlh_periods_num >= $xlh_ext['open_condition']['waiting_start_num'] && $xlh_periods_num < $xlh_ext['open_condition']['start_num']){
|
||||
$xlh_status = 2;//状态 1:巡乐会开始 2:即将开始开始 0:等待开始
|
||||
}else{
|
||||
$xlh_status = 0;//未开始
|
||||
}
|
||||
return [
|
||||
'activities_name' => $xlh_box['name'],
|
||||
'icon' => null,
|
||||
'xlh_status'=>$xlh_status,
|
||||
'end_time'=>$xlh_data['end_time'] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会榜单
|
||||
*
|
||||
*/
|
||||
public function xlh_ranking_list($room_id,$page=1,$page_size=12){
|
||||
$gift_bag_id = 13;
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id',$gift_bag_id)->find();
|
||||
$xlh_ext = json_decode($xlh_box['ext'],true);
|
||||
$pan_xlh = db::name('vs_room_pan_xlh')
|
||||
->order('id desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
$list = [];
|
||||
foreach ($pan_xlh as $key=>$value){
|
||||
$list[$key]['periods'] = "第".$value['periods']."期";
|
||||
if(!empty($value['user_id'])){
|
||||
$list[$key]['nickname'] = db::name('user')->where(['id'=>$value['user_id']])->value('nickname');
|
||||
}else{
|
||||
$list[$key]['nickname'] = "无";
|
||||
}
|
||||
if(!empty($value['gift_id'])){
|
||||
$gift_data = db::name('vs_gift')->field('gift_name,base_image')->where(['gid'=>$value['gift_id']])->find();
|
||||
$list[$key]['gift_name'] = 'x '.$value['num'].' '.$gift_data['gift_name'];
|
||||
$list[$key]['base_image'] = $gift_data['base_image']??"";
|
||||
}else{
|
||||
$gift_data = db::name('vs_gift')->field('gift_name,base_image')->where(['gid'=>$xlh_ext['locking_condition']['locking_gift_id']])->find();
|
||||
$list[$key]['gift_name'] = 'x 0 '.$gift_data['gift_name'];
|
||||
$list[$key]['base_image'] = $gift_data['base_image']??"";
|
||||
}
|
||||
$list[$key]['createtime'] = $value['send_time'] ? date('Y-m-d H:i:s',$value['send_time']) : '' ;
|
||||
}
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '成功',
|
||||
'data' => $list
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user