Files
portal-api/app/Repositories/Api/ServiceClient/ServiceClientRepository.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

74 lines
2.2 KiB
PHP

<?php
namespace App\Repositories\Api\ServiceClient;
use App\Models\Service;
use App\Repositories\Api\BaseApiRepository;
class ServiceClientRepository extends BaseApiRepository implements ServiceClientRepositoryInterface
{
public function getModel()
{
return Service::class;
}
/**
* Lấy toàn bộ dịch vụ của customer (mọi trạng thái)
*/
public function getActiveServices(int $customerId, ?string $productType = null, ?int $limit = 10)
{
$query = $this->model
->with([
'product.servicePlan',
'addons',
'invoice.order',
'orderItem' => fn($q) => $q->with(['product.servicePlan', 'os.osGroup', 'order']),
])
->where('customer_id', $customerId)
->orderByRaw("FIELD(status, 'active', 'pending', 'suspended', 'expired', 'cancelled', 'terminated')")
->orderBy('started_at', 'desc');
if ($productType) {
$query->where('type', $productType);
}
return $limit === null ? $query->get() : $query->paginate($limit);
}
public function findActiveBySlug(string $slug)
{
return $this->model
->with(['osVersions.osGroup', 'category', 'pricings' => fn ($q) => $q->where('is_active', 1)])
->where('slug', $slug)
->where('is_active', 1)
->first();
}
public function getPricing(int $productId, string $billingCycle)
{
$pricing = $this->model->find($productId)
->pricings()
->where('billing_cycle', $billingCycle)
->where('is_active', 1)
->first();
return $pricing ? $pricing->price : null;
}
public function getDetailService(string $uuid, int $customerId)
{
return $this->model
->with([
'addons',
'orderItem.os.osGroup',
'orderItem.product',
'orderItem.order',
'vmware.ipAddress',
'hostingAccount.server',
])
->where('uuid', $uuid)
->where('customer_id', $customerId)
->first();
}
}