1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-22 19:44:02 +08:00
koogua a7f197c01b !6 develop->master 1.1.0
* 更新版本号
* 完善后台今日统计,增加权限白名单,增加后台首页菜单,调整后台登录页样式
* Merge branch 'koogua/I1XFCF' of https://gitee.com/koogua/course-tencen…
* 前台学习资料部分完成
* !2 后台运营统计合并
* 后台学习资料部分完成
* Merge branch 'master' into develop
* Merge branch 'master' of https://github.com/xiaochong0302/course-tencent-cloud
* 1.增加changelog.md
* 1.简化部分路由地址
* Merge pull request #2 from xiaochong0302/dependabot/composer/symfony/h…
* Bump symfony/http-foundation from 4.3.4 to 5.1.6
2020-10-08 18:44:06 +08:00

52 lines
1.2 KiB
PHP

<?php
namespace App\Listeners;
use App\Models\Online as OnlineModel;
use App\Models\User as UserModel;
use App\Repos\Online as OnlineRepo;
use App\Traits\Client as ClientTrait;
use Phalcon\Events\Event;
class User extends Listener
{
use ClientTrait;
public function online(Event $event, $source, UserModel $user)
{
$now = time();
if ($now - $user->active_time > 600) {
$user->active_time = $now;
$user->update();
$onlineRepo = new OnlineRepo();
$online = $onlineRepo->findByUserDate($user->id, date('Y-m-d'));
if ($online) {
$online->active_time = $now;
$online->client_type = $this->getClientType();
$online->client_ip = $this->getClientIp();
$online->update();
} else {
$online = new OnlineModel();
$online->user_id = $user->id;
$online->active_time = $now;
$online->client_type = $this->getClientType();
$online->client_ip = $this->getClientIp();
$online->create();
}
}
}
}