2025-08-28 18:44:56 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\cron\controller;
|
|
|
|
|
|
|
2025-08-29 14:17:42 +08:00
|
|
|
|
use app\common\controller\Push;
|
2025-10-13 14:59:37 +08:00
|
|
|
|
use think\Cache;
|
2025-08-28 18:44:56 +08:00
|
|
|
|
use think\Db;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 定时任务,每秒执行的方法
|
|
|
|
|
|
*/
|
|
|
|
|
|
class RoomPan
|
|
|
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 运行函数
|
|
|
|
|
|
*/
|
|
|
|
|
|
function index()
|
|
|
|
|
|
{
|
2025-09-01 16:14:03 +08:00
|
|
|
|
echo "巡乐会礼物发放开始:\n";
|
2025-08-28 18:44:56 +08:00
|
|
|
|
$this->xlh_gift_send();//拍卖房结束提醒
|
|
|
|
|
|
echo "礼物发放结束 \n";
|
|
|
|
|
|
|
|
|
|
|
|
echo "盲盒转盘礼物补发:\n";
|
|
|
|
|
|
$this->blind_box_turntable_gift_send();//盲盒转盘礼物补发
|
|
|
|
|
|
echo "盲盒转盘礼物补发结束 \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2025-09-16 16:39:57 +08:00
|
|
|
|
* 盲盒转盘礼物推送补发
|
2025-08-28 18:44:56 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public function blind_box_turntable_gift_send(){
|
2025-09-16 16:39:57 +08:00
|
|
|
|
$blind_box_turntable = db('vs_blind_box_turntable_log')->where(['is_sued'=>0,'createtime'=>['>=',time()-60*30]])->limit(1000)->select();
|
|
|
|
|
|
if(empty($blind_box_turntable)){
|
2025-08-28 18:44:56 +08:00
|
|
|
|
echo "没有需要发放的礼物 \n";
|
|
|
|
|
|
}
|
2025-09-16 16:39:57 +08:00
|
|
|
|
echo "开始发放".count($blind_box_turntable)." \n";
|
|
|
|
|
|
foreach ($blind_box_turntable as $k => $v) {
|
2025-09-16 18:08:15 +08:00
|
|
|
|
$blind_box_turntable_results_log = db('vs_blind_box_turntable_results_log')->where('tid',$v['id'])->select();
|
2025-09-16 16:39:57 +08:00
|
|
|
|
if(empty($blind_box_turntable_results_log)){
|
|
|
|
|
|
echo $v['id']." 没有需要发放的礼物 \n";
|
2025-08-28 18:44:56 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2025-09-16 16:39:57 +08:00
|
|
|
|
$room_id = $v['room_id'];
|
|
|
|
|
|
$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();
|
2025-10-13 15:59:17 +08:00
|
|
|
|
$FromUserInfo['user_id'] = $FromUserInfo['id'];
|
2025-09-19 16:13:41 +08:00
|
|
|
|
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
|
|
|
|
|
|
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
|
2025-09-16 16:39:57 +08:00
|
|
|
|
$user_nickname = $FromUserInfo['nickname'];
|
|
|
|
|
|
$textMessage = $user_nickname;
|
|
|
|
|
|
$text_message = $user_nickname;
|
|
|
|
|
|
foreach ($blind_box_turntable_results_log as $key => $value) {
|
2025-09-16 20:23:45 +08:00
|
|
|
|
$ToUserInfo = Db::name('user')->where(['id' => $value['gift_user_id']])->field('id as user_id,nickname,avatar,sex')->find();
|
2025-09-16 16:39:57 +08:00
|
|
|
|
$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'];
|
2025-09-19 16:13:41 +08:00
|
|
|
|
$gift_names[] = $draw_gift['gift_name'];
|
2025-09-16 16:39:57 +08:00
|
|
|
|
|
|
|
|
|
|
$text_message = $text_message . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $value['count']."\n";
|
2025-09-16 18:08:15 +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-09-16 20:23:45 +08:00
|
|
|
|
$ToUserInfosList[$value['gift_user_id']] = $ToUserInfo;
|
|
|
|
|
|
}
|
2025-09-19 16:44:26 +08:00
|
|
|
|
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');//魅力
|
2025-09-16 20:23:45 +08:00
|
|
|
|
$ToUserInfos[] = $userInfo;
|
2025-09-16 16:39:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
$text = [
|
2025-09-16 18:08:15 +08:00
|
|
|
|
'FromUserInfo' => $FromUserInfo,
|
2025-09-16 20:23:45 +08:00
|
|
|
|
'ToUserInfos' => $ToUserInfos,
|
2025-09-16 16:39:57 +08:00
|
|
|
|
'GiftInfo' => [
|
|
|
|
|
|
'play_image' => implode(',',$play_image),
|
2025-09-19 16:13:41 +08:00
|
|
|
|
'gift_name' => implode(',',$gift_names),
|
2025-09-16 16:39:57 +08:00
|
|
|
|
],
|
2025-09-23 19:04:11 +08:00
|
|
|
|
'text' => rtrim($textMessage, "\n")
|
2025-09-16 16:39:57 +08:00
|
|
|
|
];
|
|
|
|
|
|
//聊天室推送系统消息
|
|
|
|
|
|
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{
|
2025-09-16 18:08:15 +08:00
|
|
|
|
if(!empty($text_list_new)){
|
2025-09-16 16:39:57 +08:00
|
|
|
|
//推送礼物横幅
|
|
|
|
|
|
$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()]);
|
2025-08-28 18:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 巡乐会结束 礼物发放 【定时脚本】
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function xlh_gift_send(){
|
2025-09-22 09:28:10 +08:00
|
|
|
|
$xlh_list = db::name('vs_room_pan_xlh')->where(['send_time'=>0,'end_time'=>['<=',time()]])->select();
|
2025-08-28 18:44:56 +08:00
|
|
|
|
if(empty($xlh_list)){
|
|
|
|
|
|
echo "没有需要发放的礼物 \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach ($xlh_list as $key=>$value){
|
2025-09-01 16:14:03 +08:00
|
|
|
|
try{
|
2025-09-03 18:16:12 +08:00
|
|
|
|
if($value['user_id'] == 0){
|
|
|
|
|
|
echo "第.".$value['periods']." 巡乐会结束 没有中奖用户 \n";
|
|
|
|
|
|
$res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([
|
|
|
|
|
|
'send_time' => time()
|
|
|
|
|
|
]);
|
2025-10-13 14:59:37 +08:00
|
|
|
|
// db::name("vs_room")->where('id',$value['room_id'])->update([
|
|
|
|
|
|
// 'xlh_periods_num' => 0
|
|
|
|
|
|
// ]);
|
|
|
|
|
|
Cache::set("xlh_periods_num", 0, 0);
|
2025-09-03 18:16:12 +08:00
|
|
|
|
//推送礼物横幅
|
|
|
|
|
|
$text = "本轮巡乐会已结束,请大家重新开始下一轮巡乐会";
|
|
|
|
|
|
$push = new Push(0, $value['room_id']);
|
|
|
|
|
|
$text_list_new = [
|
|
|
|
|
|
'text' => $text,
|
|
|
|
|
|
'room_id' => $value['room_id'],
|
|
|
|
|
|
'from_type' => 3
|
|
|
|
|
|
];
|
|
|
|
|
|
$push->xunlehui($text_list_new);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2025-09-01 16:14:03 +08:00
|
|
|
|
//发放
|
|
|
|
|
|
//抽中礼物落包
|
|
|
|
|
|
$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;
|
|
|
|
|
|
}
|
|
|
|
|
|
//推送
|
|
|
|
|
|
$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');
|
2025-10-13 17:06:22 +08:00
|
|
|
|
$text = $FromUserInfo['nickname'] . ' 用户在巡乐会中 ' .$gift_name.'礼物 x ' .$value['num']." 已收入背包";
|
2025-09-01 16:14:03 +08:00
|
|
|
|
//推送礼物横幅
|
|
|
|
|
|
$push = new Push(0, $value['room_id']);
|
|
|
|
|
|
$text_list_new = [
|
|
|
|
|
|
'text' => $text,
|
|
|
|
|
|
'room_id' => $value['room_id'],
|
|
|
|
|
|
'from_type' => 3
|
|
|
|
|
|
];
|
|
|
|
|
|
$push->xunlehui($text_list_new);
|
|
|
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
echo $e->getMessage()."\n";
|
2025-08-28 18:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|