1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-29 05:41:37 +08:00
koogua 6cd3fb6d6c !2 后台运营统计合并
* 修复hash中前一日统计没有更新的问题
* 增加后台运营统计
2020-10-08 10:07:49 +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();
}
}
}
}