mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-14 20:31:22 +08:00
* 去除无用的auth_url * 修改readme * 修复计划任务生成sitemap.xml失败问题 * 增加课程推荐 * 增加后台刷新首页缓存小工具 * 调整公众号模板消息 * 增加刷新首页推荐课程缓存逻辑 * 更新课程综合评分算法 * 修复在线用户并发重复记录问题 * 增加限制共享帐号功能 * 修复数据迁移中无符号整型问题 * 更新版本为v1.2.3
77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Library\Utils\Lock as LockUtil;
|
|
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)
|
|
{
|
|
$itemId = "user:{$user->id}";
|
|
|
|
$lockId = LockUtil::addLock($itemId);
|
|
|
|
$now = time();
|
|
$clientType = $this->getClientType();
|
|
$clientIp = $this->getClientIp();
|
|
|
|
if ($now - $user->active_time > 600) {
|
|
|
|
$user->active_time = $now;
|
|
|
|
$user->update();
|
|
|
|
$onlineRepo = new OnlineRepo();
|
|
|
|
$records = $onlineRepo->findByUserDate($user->id, date('Y-m-d'));
|
|
|
|
if ($records->count() > 0) {
|
|
|
|
$online = null;
|
|
|
|
foreach ($records as $record) {
|
|
if ($record->client_type == $clientType && $record->client_ip == $clientIp) {
|
|
$online = $record;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($online) {
|
|
$online->active_time = $now;
|
|
$online->update();
|
|
} else {
|
|
$this->createOnline($user->id, $clientType, $clientIp);
|
|
}
|
|
|
|
} else {
|
|
$this->createOnline($user->id, $clientType, $clientIp);
|
|
}
|
|
}
|
|
|
|
LockUtil::releaseLock($itemId, $lockId);
|
|
}
|
|
|
|
protected function createOnline($userId, $clientType, $clientIp)
|
|
{
|
|
$online = new OnlineModel();
|
|
|
|
$online->user_id = $userId;
|
|
$online->client_type = $clientType;
|
|
$online->client_ip = $clientIp;
|
|
$online->active_time = time();
|
|
|
|
$online->create();
|
|
|
|
return $online;
|
|
}
|
|
|
|
} |