travel/service/app/admin/controller/WatchController.php

44 lines
1.2 KiB
PHP
Raw Normal View History

2024-06-25 18:30:50 +08:00
<?php
namespace app\admin\controller;
use app\model\Admins;
use support\Log;
use support\Redis;
use think\db\exception\DbException;
class WatchController extends base
{
public static function watchIsWork()
{
$nowTime = time();
$datas = Admins::order('create_time desc')->select();
foreach ($datas as $data) {
$item = [];
2024-06-26 15:38:38 +08:00
//set admin/index/isWork
2024-06-25 18:30:50 +08:00
$watch = Redis::get('CRM:USER:ONLINE:WATCH:'.$data->id);
2024-06-26 15:38:38 +08:00
//记录下线时间
if (!empty($watch) && ($nowTime - $watch) > 6*60){
$item['end_work_time'] = $watch + 5*60;
2024-06-25 18:30:50 +08:00
}
2024-06-26 15:38:38 +08:00
//实时更新在线时间
if (($nowTime - $watch) <= 6*60){
$item['last_work_time'] = $nowTime;
2024-06-25 18:30:50 +08:00
}
2024-06-26 15:38:38 +08:00
//记录当天第一次上线时间 start_work_time admin/login/index
2024-06-25 18:30:50 +08:00
if (!empty($item)){
try {
Admins::where('id', $data->id)->update($item);
} catch (DbException $e) {
Log::error('watchIsWork',['error'=>$e]);
continue;
}
}
}
return;
}
}