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; } }