Files
yusheng-php/application/cron/controller/FriendEnd.php
2025-12-02 11:31:51 +08:00

115 lines
4.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\cron\controller;
use think\Cache;
use think\Db;
class FriendEnd
{
/*
* 运行函数
*/
function index()
{
echo "清除交友房过期未结束数据开始:\n";
$this->clearFriendingEndRoom();//清除交友房过期未结束数据
echo "清除结束 \n";
echo "清除私密小屋过期数据开始:\n";
$this->clear_room_end();//清除私密小屋过期数据
echo "清除私密小屋过期数据结束 \n";
echo "查询在线状态:\n";
$this->online_status();
echo "\n";
}
//查询在线状态
protected function online_status()
{
$user_list = db::name('vs_xintiao')->select();
if($user_list){
foreach ($user_list as &$value){
if(time() - $value['updatetime'] >= 183){//2秒刷新一次加上用户多 三分钟补偿3秒
//断线
db::name('user')->where('id',$value['user_id'])->update(['is_online'=>0]);
//是否在房间内
$room_id = db::name('vs_room_visitor')->where('user_id',$value['user_id'])->order('id desc')->value('room_id');
if($room_id){
$text['text'] = '掉线!';
$text['user_id'] = $value['user_id'];
$text['type'] = 2;
model('Chat')->sendMsg(1058,$room_id,$text);
//拍卖位互娱交友过程中1-6号麦位签约过程中签约麦位不能退出房间 则推送离线
// $auction_user_id = Cache::get('auction_user_'.$room_id);
// $roomInfoStep = db::name('vs_room')->where(['id' => $room_id])->value('step');
// $room_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $value['user_id']])->find();
// $vs_room_sign = db::name('vs_room_sign')->where(['room_id' => $room_id, 'sign_user_id' => $value['user_id'],'sign_type'=>1])->find();
// if($auction_user_id == $value['user_id']
// || ($roomInfoStep == 2 && in_array($room_pit['pit_number'],[1,2,3,4,5,6]))
// || $vs_room_sign)
// {
//
// }else{//其他退出房间
// model('api/Room')->quit_room($value['user_id'],$room_id,$value['user_id']);
// }
}
}else{
$is_online = db::name('user')->where('id',$value['user_id'])->value('is_online');
if($is_online == 1){
//在线
continue;
}else{
//在线
db::name('user')->where('id',$value['user_id'])->update(['is_online'=>1]);
//是否在房间内
$room_id = db::name('vs_room_visitor')->where('user_id',$value['user_id'])->order('id desc')->value('room_id');
if($room_id){
$text['text'] = '重新上线!';
$text['user_id'] = $value['user_id'];
$text['type'] = 1;
model('Chat')->sendMsg(1058,$room_id,$text);
}
}
}
}
}
}
//清除交友房过期未结束数据
public function clearFriendingEndRoom()
{
//清除交友房过期数据
$room_list = db::name('vs_room')->where(['type_id'=>7])->whereIn('step', [2,3])
->field(['id','step'])->select();
if(!empty($room_list)){
foreach ($room_list as $room) {
//查询交友信息
$friending_info = db::name('vs_user_friending')->where('room_id', $room['id'])->where('status', 1)->order('id', 'desc')->find();
if($friending_info){
//判断结束时间是否到期
if($friending_info['end_time'] <= time() || $room['step'] == 3){
model('Friend')->end_friend(0,$room['id'],$friending_info['id'],1);
}
}
}
}
}
//清除私密小屋过期数据
public function clear_room_end()
{
$room_list = db::name('vs_room_cp_movie')->where(['status' => 1,'type'=>1,'time_day' =>['<',time()]])->select();
if(!empty($room_list)){
foreach ($room_list as $room) {
model('Friend')->outRoom(0,$room['room_id']);
}
}
}
}