You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Controllers/CloudAdminBillingController...

58 lines
1.6 KiB
PHP

<?php
namespace App\Controllers;
use App\Services\Cloud\CloudAccess;
use App\Services\Cloud\CloudAdminBillingService;
use App\Services\Cloud\CloudError;
/** Read-only administrator views over the cloud billing ledger. */
final class CloudAdminBillingController
{
private function actor($request): array
{
$actor = $request->getAttribute('cloud_actor') ?? CloudAccess::actor(false);
if (!($actor['is_admin'] ?? false)) {
throw new CloudError('需要管理员权限', 403);
}
return $actor;
}
private function json($response, array $payload)
{
return $response->withJson($payload)
->withHeader('Cache-Control', 'private, no-store');
}
public function invoices($request, $response)
{
$this->actor($request);
return $this->json($response, CloudAdminBillingService::invoices(
$request->getQueryParams()
));
}
public function invoice($request, $response, $args)
{
$this->actor($request);
return $this->json($response, CloudAdminBillingService::invoice(
(string) ($args['id'] ?? '')
));
}
public function orders($request, $response)
{
$this->actor($request);
return $this->json($response, CloudAdminBillingService::orders(
$request->getQueryParams()
));
}
public function payments($request, $response)
{
$this->actor($request);
return $this->json($response, CloudAdminBillingService::payments(
$request->getQueryParams()
));
}
}