2025-10-20 10:02:41 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\cron\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use app\common\controller\Push;
|
|
|
|
|
|
use think\Cache;
|
|
|
|
|
|
use think\Db;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 定时任务,每秒执行的方法
|
|
|
|
|
|
*/
|
|
|
|
|
|
class RoomPan
|
|
|
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 运行函数
|
|
|
|
|
|
*/
|
|
|
|
|
|
function index()
|
|
|
|
|
|
{
|
|
|
|
|
|
echo "巡乐会礼物发放开始:\n";
|
|
|
|
|
|
$this->xlh_gift_send();//拍卖房结束提醒
|
|
|
|
|
|
echo "礼物发放结束 \n";
|
|
|
|
|
|
|
|
|
|
|
|
echo "盲盒转盘礼物补发:\n";
|
|
|
|
|
|
$this->blind_box_turntable_gift_send();//盲盒转盘礼物补发
|
|
|
|
|
|
echo "盲盒转盘礼物补发结束 \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 盲盒转盘礼物推送补发
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function blind_box_turntable_gift_send(){
|
2025-10-30 00:22:09 +08:00
|
|
|
|
$blind_box_turntable = Db::name('vs_blind_box_turntable_log')->where(['is_sued'=>0,'createtime'=>['>=',time()-60*30]])->limit(1000)->select();
|
2025-10-20 10:02:41 +08:00
|
|
|
|
if(empty($blind_box_turntable)){
|
|
|
|
|
|
echo "没有需要发放的礼物 \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
echo "开始发放".count($blind_box_turntable)." \n";
|
|
|
|
|
|
foreach ($blind_box_turntable as $k => $v) {
|
2025-10-30 00:22:09 +08:00
|
|
|
|
$blind_box_turntable_results_log = Db::name('vs_blind_box_turntable_results_log')->where('tid',$v['id'])->select();
|
2025-10-20 10:02:41 +08:00
|
|
|
|
if(empty($blind_box_turntable_results_log)){
|
|
|
|
|
|
echo $v['id']." 没有需要发放的礼物 \n";
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2025-10-30 00:16:46 +08:00
|
|
|
|
$room_id = $blind_box_turntable_results_log['gift_user_room_id'];
|
2025-10-20 10:02:41 +08:00
|
|
|
|
$room_name = Db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->value('room_name');
|
|
|
|
|
|
$FromUserInfo = Db::name('user')->where(['id'=>$v['user_id']])->find();
|
|
|
|
|
|
$FromUserInfo['user_id'] = $FromUserInfo['id'];
|
2025-10-24 22:21:17 +08:00
|
|
|
|
$FromUserInfo['icon'][0] = model('api/UserData')->user_wealth_icon($v['user_id']);//财富图标
|
|
|
|
|
|
$FromUserInfo['icon'][1] = model('api/UserData')->user_charm_icon($v['user_id']);//魅力图标
|
|
|
|
|
|
$FromUserInfo['chat_bubble'] = model('api/Decorate')->user_decorate_detail($v['user_id'],9);//聊天气泡
|
2025-10-20 10:02:41 +08:00
|
|
|
|
$user_nickname = $FromUserInfo['nickname'];
|
2025-10-24 22:21:17 +08:00
|
|
|
|
$userGiftMap = [];
|
2025-10-20 10:02:41 +08:00
|
|
|
|
foreach ($blind_box_turntable_results_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();
|
2025-10-24 22:21:17 +08:00
|
|
|
|
$text_message = $user_nickname . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $value['count']."\n";
|
2025-10-20 10:02:41 +08:00
|
|
|
|
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'],
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
2025-10-24 22:21:17 +08:00
|
|
|
|
|
|
|
|
|
|
$userId = $value['gift_user_id'];
|
|
|
|
|
|
if (!isset($userGiftMap[$userId])) {
|
|
|
|
|
|
$userGiftMap[$userId] = [
|
|
|
|
|
|
'userInfo' => $ToUserInfo,
|
|
|
|
|
|
'gifts' => []
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
$userGiftMap[$userId]['gifts'][] = [
|
|
|
|
|
|
'gift_id' => $draw_gift['gid'],
|
|
|
|
|
|
'gift_name' => $draw_gift['gift_name'],
|
|
|
|
|
|
'count' => $value['count'],
|
|
|
|
|
|
'play_image' => $draw_gift['play_image'],
|
|
|
|
|
|
'base_image' => $draw_gift['base_image']
|
|
|
|
|
|
];
|
2025-10-20 10:02:41 +08:00
|
|
|
|
}
|
2025-10-24 22:21:17 +08:00
|
|
|
|
|
|
|
|
|
|
// 为每个用户单独推送消息
|
|
|
|
|
|
foreach($userGiftMap as $userId => $userData) {
|
|
|
|
|
|
$userInfo = $userData['userInfo'];
|
|
|
|
|
|
$gifts = $userData['gifts'];
|
|
|
|
|
|
|
|
|
|
|
|
// 构建用户专属文本消息,接收者名字只出现一次
|
|
|
|
|
|
$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('api/UserData')->user_wealth_icon($userInfo['user_id']);
|
|
|
|
|
|
$userInfo['icon'][1] = model('api/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');
|
|
|
|
|
|
|
|
|
|
|
|
$userText = [
|
|
|
|
|
|
'FromUserInfo' => $FromUserInfo,
|
|
|
|
|
|
'ToUserInfo' => $userInfo,
|
|
|
|
|
|
'GiftInfos' => array_values($gifts),
|
|
|
|
|
|
'text' => $userTextMessage
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
// 聊天室推送系统消息给每个用户
|
|
|
|
|
|
model('api/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('api/Chat')->sendMsg(1005,$room_id,$effectData);
|
|
|
|
|
|
}
|
2025-10-20 10:02:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
$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' => '房间心动值变化'
|
|
|
|
|
|
];
|
|
|
|
|
|
//聊天室推送系统消息
|
2025-10-24 22:21:17 +08:00
|
|
|
|
model('api/Chat')->sendMsg(1028,$room_id,$text1);
|
2025-10-20 10:02:41 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
if(!empty($text_list_new)){
|
|
|
|
|
|
//推送礼物横幅
|
|
|
|
|
|
$push = new Push($v['user_id'], $room_id);
|
|
|
|
|
|
$push->giftBanner($text_list_new);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
db::name('vs_blind_box_turntable_log')->where('id', $v['id'])->update(['is_sued' => 1, 'updatetime' => time()]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 巡乐会结束 礼物发放 【定时脚本】
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function xlh_gift_send(){
|
|
|
|
|
|
$xlh_list = db::name('vs_room_pan_xlh')->where(['send_time'=>0,'end_time'=>['<=',time()]])->select();
|
|
|
|
|
|
if(empty($xlh_list)){
|
|
|
|
|
|
echo "没有需要发放的礼物 \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach ($xlh_list as $key=>$value){
|
|
|
|
|
|
try{
|
|
|
|
|
|
if($value['user_id'] == 0){
|
|
|
|
|
|
echo "第.".$value['periods']." 巡乐会结束 没有中奖用户 \n";
|
|
|
|
|
|
$res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([
|
|
|
|
|
|
'send_time' => time()
|
|
|
|
|
|
]);
|
|
|
|
|
|
// db::name("vs_room")->where('id',$value['room_id'])->update([
|
|
|
|
|
|
// 'xlh_periods_num' => 0
|
|
|
|
|
|
// ]);
|
|
|
|
|
|
Cache::set("xlh_periods_num", 0, 0);
|
|
|
|
|
|
//推送礼物横幅
|
|
|
|
|
|
$text = "本轮巡乐会已结束,请大家重新开始下一轮巡乐会";
|
|
|
|
|
|
$push = new Push(0, $value['room_id']);
|
|
|
|
|
|
$text_list_new = [
|
|
|
|
|
|
'text' => $text,
|
|
|
|
|
|
'room_id' => $value['room_id'],
|
|
|
|
|
|
'from_type' => 104
|
|
|
|
|
|
];
|
|
|
|
|
|
$push->xunlehui($text_list_new);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
//发放
|
|
|
|
|
|
//抽中礼物落包
|
|
|
|
|
|
$res = [];
|
|
|
|
|
|
$res = model('api/UserGiftPack')->change_user_gift_pack($value['user_id'],$value['gift_id'],$value['num'],model('UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖发放");
|
|
|
|
|
|
if ($res['code'] != 1) {
|
|
|
|
|
|
echo $res['msg']."\n";
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
echo "巡乐会中奖礼物发放成功 用户Id:".$value['user_id']."\n";
|
|
|
|
|
|
//房主礼物落包
|
|
|
|
|
|
$res = [];
|
|
|
|
|
|
//获取房主id
|
|
|
|
|
|
$user_id = db::name('vs_room')->where(['id'=>$value['room_id']])->value('user_id');
|
|
|
|
|
|
$res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$value['homeowner_gift_id'],1,model('UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖后房主礼物发放");
|
|
|
|
|
|
if ($res['code'] != 1) {
|
|
|
|
|
|
echo $res['msg']."\n";
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
echo "巡乐会中奖后房主礼物发放成功 房主Id:".$user_id."\n";
|
|
|
|
|
|
//处理发放记录
|
|
|
|
|
|
$res = [];
|
|
|
|
|
|
$res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([
|
|
|
|
|
|
'send_time' => time()
|
|
|
|
|
|
]);
|
|
|
|
|
|
$xlh_log = db::name('vs_room_pan_xlh_log')->where(['xlh_id'=>$value['id'],'user_id'=>$value['user_id']])->order('id desc')->find();
|
|
|
|
|
|
$res = db::name('vs_room_pan_xlh_log')->where('id',$xlh_log['id'])->update([
|
|
|
|
|
|
'is_send' => 1
|
|
|
|
|
|
]);
|
|
|
|
|
|
if ($res === false) {
|
|
|
|
|
|
echo "处理发放记录失败 \n";
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
Cache::set("xlh_periods_num", 0, 0);
|
|
|
|
|
|
//推送
|
|
|
|
|
|
$FromUserInfo = db::name('user')->field('nickname,avatar')->where(['id'=>$value['user_id']])->find();
|
|
|
|
|
|
$gift_name = db::name('vs_gift')->where(['gid'=>$value['gift_id']])->value('gift_name');
|
|
|
|
|
|
$text = $FromUserInfo['nickname'] . ' 用户在巡乐会中 ' .$gift_name.'礼物 x ' .$value['num']." 已收入背包";
|
|
|
|
|
|
//推送礼物横幅
|
|
|
|
|
|
$push = new Push(0, $value['room_id']);
|
|
|
|
|
|
$text_list_new = [
|
|
|
|
|
|
'text' => $text,
|
|
|
|
|
|
'room_id' => $value['room_id'],
|
|
|
|
|
|
'from_type' => 104
|
|
|
|
|
|
];
|
|
|
|
|
|
$push->xunlehui($text_list_new);
|
|
|
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
echo $e->getMessage()."\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|