Files
portal-api/app/Services/Api/ServiceClient/ServiceClientService.php
T
baodev0andClaude Opus 5.5 c5115b52dd feat: nạp tiền thủ công mã 30 phút, gia hạn trừ số dư, đồng bộ domain từ Plesk
- Nạp tiền: mã thanh toán sống 30 phút (ManualDepositDraft), khôi phục/huỷ mã, lệnh dọn mã hết hạn; total_pending chỉ tính giao dịch đã nộp chứng từ, admin duyệt/từ chối/xoá giao dịch
- Gia hạn dịch vụ: phát hành invoice gia hạn trên order gốc và trừ số dư ngay
- Đồng bộ domain từ Plesk theo server, ServiceOrderRecorder tạo order/invoice cho dịch vụ admin dựng
- Danh sách dịch vụ trả field theo loại (service_plan, dns_records_count), đếm dịch vụ theo loại

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 23:07:51 +07:00

76 lines
2.4 KiB
PHP

<?php
namespace App\Services\Api\ServiceClient;
use App\Models\DnsDomain;
use App\Models\Service;
use App\Repositories\Api\ServiceClient\ServiceClientRepositoryInterface;
class ServiceClientService
{
protected $serviceClientRepository;
public function __construct(ServiceClientRepositoryInterface $serviceClientRepository)
{
$this->serviceClientRepository = $serviceClientRepository;
}
/**
* Lấy danh sách dịch vụ đang hoạt động
*/
public function getActiveServices(int $customerId, ?string $productType = null, ?int $limit = 10)
{
return $this->serviceClientRepository->getActiveServices($customerId, $productType, $limit);
}
/**
* @return array{vps: int, server: int, hosting: int, domain: int}
*/
public function countByType(int $customerId): array
{
$counts = Service::query()
->where('customer_id', $customerId)
->whereNotIn('status', ['cancelled', 'terminated'])
->selectRaw('type, COUNT(*) as total')
->groupBy('type')
->pluck('total', 'type');
return [
'vps' => (int) $counts->get('vps', 0),
'server' => (int) $counts->get('server', 0),
'hosting' => (int) $counts->get('hosting', 0),
'domain' => (int) $counts->get('domain', 0),
];
}
/**
* @param iterable<Service> $services
*/
public function attachDnsRecordCounts(iterable $services, int $customerId): void
{
$counts = DnsDomain::query()
->withCount('ns')
->whereHas('customer', fn ($query) => $query->where('customers.id', $customerId))
->get(['id', 'domain_name'])
->mapWithKeys(fn (DnsDomain $domain) => [
mb_strtolower(trim($domain->domain_name)) => (int) $domain->ns_count,
]);
foreach ($services as $service) {
if ($service->type === 'domain') {
$service->setAttribute('dns_records_count', $counts->get(mb_strtolower(trim((string) $service->server_name))));
}
}
}
public function findActiveBySlug(string $slug)
{
return $this->serviceClientRepository->findActiveBySlug($slug);
}
public function getDetailService(string $uuid, int $customerId)
{
return $this->serviceClientRepository->getDetailService($uuid, $customerId);
}
}