Files
yusheng-php/application/cron/controller/DaySeconds.php

65 lines
1.7 KiB
PHP
Raw Permalink 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\Db;
/*
* 定时任务,每秒执行的方法
*/
class DaySeconds
{
/*
* 运行函数
*/
function index()
{
echo "清除房间热度值:\n";
$this->clear_room_today_hot_value();//0点以后房间热度值清零
echo "\n";
echo "清除房间离线超24小时的用户\n";
$this->clear_room_offline_user();//0点以后清除房间离线超24小时用户
echo "\n";
}
/*
* 0点以后清除房间离线超24小时用户
* 配置:定时脚本每天 0点 执行
* 配置:
*/
public function clear_room_offline_user() {
$room = db::name('vs_room_visitor')->where(['is_online' => 2])->select();
if($room){
foreach ($room as $value) {
$time = time() - $value['updatetime'];
if($time > 86400){
model('api/Room')->quit_room($value['user_id'], $value['room_id'],$value['user_id']);
}
}
}
}
/*
* 0点以后房间热度值清零
* 配置:定时脚本每天 0点 执行
* 配置:
*/
public function clear_room_today_hot_value() {
$where = [];
$where['delete_time'] = 0;
$where['is_show_room'] = 1;
$room = db::name('vs_room')->where($where)->select();
echo date('Y-m-d H:i:s').' 开始清零:'.count($room)."\n";
foreach ($room as $key => $value) {
$data = [
'today_hot_value' => 0,
];
db::name('vs_room')->where(['id' => $value['id']])->update($data);
}
echo date('Y-m-d H:i:s').' 完成'."\n";
die;
}
}