'integer', 'account_type' => 'integer', 'belong_id' => 'integer', 'account_id' => 'integer', 'fd' => 'integer', 'status' => 'integer']; public static function list(array $param) { return self::where("status", 1) ->with(["account" => function ($query) { $query->select(["account_id", "username", 'dept_id']); }, "account.dept" => function ($query) { $query->select(["dept_id", "dept_name"]); }]) ->when(isset($param['username']) && $param['username'] != '', function ($q) use ($param) { $q->where('username', 'like', "%{$param['username']}%"); }) ->orderByDesc("online_id") ->select(['session_id', 'username', 'ip', 'ua', 'online_time', 'account_id', 'update_time']) ->paginate((int)$param['limit']); } public static function closeAll(): int { return self::where("status", 1) ->where("online_time", ">", date("Y-m-d H:i:s", time() - 24 * 60 * 60)) ->update(['status' => 0, 'offline_time' => date("Y-m-d H:i:s")]); } public static function leave(string $uuid): int { return self::where('session_id', $uuid) ->update(['status' => 0, 'offline_time' => date("Y-m-d H:i:s")]); } public static function live(string $uuid, int $fd): int { return self::where("session_id", $uuid) ->where("status", 1) ->update(['fd' => $fd, 'update_time' => date("Y-m-d H:i:s")]); } public static function reLive(string $uuid): bool { $online = self::getByUuid($uuid); if ($online['status'] == 0) { return (bool)self::where("session_id", $uuid) ->update(['update_time' => date("Y-m-d H:i:s"), 'status' => 1]); } return true; } public static function getByUuid(string $uuid) { return self::where("session_id", $uuid)->first(['status', 'session_id', 'account_id']); } public function account() { return $this->hasOne(Account::class, 'account_id', 'account_id'); } }