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

39 lines
1.1 KiB
PHP

<?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 = [];
$watch = Redis::get('CRM:USER:ONLINE:WATCH:'.$data->id);
if (empty($data->start_work_time)){
$item['start_work_time'] = $nowTime;
}
if (($nowTime - $watch) > 0 && ($nowTime - $watch) <= 6*60){
$item['end_work_time'] = $nowTime;
}
Log::warning('watchIsWork',['data'=>$item]);
if (!empty($item)){
try {
Admins::where('id', $data->id)->update($item);
} catch (DbException $e) {
Log::error('watchIsWork',['error'=>$e]);
continue;
}
}
}
echo "========watchIsWork end======\n";
return;
}
}