Files
baodev0andClaude Opus 5.5 46aa138eec feat(admin): IP pool allocation, billing exports, service attachments
- IP pool: sheet import (xlsx/csv) matched by address, bulk allocate/revoke
  with notification email (ip_allocated/ip_revoked), ip_pool_logs history.
- Orders/invoices: Excel export on branded template (BrandedReportWriter),
  shared billing filters, order item service info in list responses.
- Web design quote Excel export; activity log export.
- Service attachments with copy-to-invoice; deployment invoice attachments.
- Customer email attachments stored on disk and attached by path.
- Admin password change endpoint; user.fullname backfill migration;
  orders.user_id backfill from logs.
- Disable deploy workflow until CI/CD is set up.
- Ignore stored customer email and service attachment uploads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 19:58:36 +07:00

76 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Admin\Staff;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Repositories\Staff\StaffRepositoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class StaffOnlineController extends Controller
{
private const ONLINE_THRESHOLD_SECONDS = 60;
public function __construct(
private readonly StaffRepositoryInterface $staffRepository
) {}
/**
* GET /api/v1/administrator/staff-online
* Trả về danh sách staff đang online (query từ tbl.user).
*/
public function index(): JsonResponse
{
$onlineSince = fn ($q) => $q->where('last_visited', '>=', time() - self::ONLINE_THRESHOLD_SECONDS);
$users = User::whereHas('staffOnline', $onlineSince)
->with(['staffOnline' => $onlineSince])
->get();
$online = $users->map(fn ($user) => [
'user_id' => $user->id,
'name' => $user->name,
'username' => $user->username,
'email' => $user->email,
'last_visited' => $user->staffOnline?->last_visited,
])->values();
return response()->json([
'error' => false,
'data' => $online,
'total' => $online->count(),
]);
}
/**
* POST /api/v1/administrator/staff-online/ping
* Heartbeat cho JWT admin — cập nhật trạng thái online.
*/
public function ping(Request $request): JsonResponse
{
$userId = $request->user()?->id;
if (!$userId) {
return response()->json(['error' => true, 'message' => 'Unauthenticated'], 401);
}
$record = $this->staffRepository->getFirstBy(['user_id' => $userId]);
if ($record) {
$record->last_visited = time();
$record->save();
} else {
$this->staffRepository->create([
'sessions_id' => 'jwt-' . $userId,
'user_id' => $userId,
'last_visited' => time(),
]);
}
$this->staffRepository->deleteRawTime(self::ONLINE_THRESHOLD_SECONDS);
return response()->json(['error' => false, 'message' => 'OK']);
}
}