Files
baodev0andClaude Sonnet 5.5 b44a88bb52 feat(service): huỷ dịch vụ, SSL, đổi mật khẩu hosting, lịch sử thanh toán theo hình thức
- Lịch sử thanh toán hoá đơn trả thêm `method` (tự động gia hạn / số dư / admin / chuyển khoản / hoàn tiền), bỏ đuôi `(method)` khỏi ghi chú
- `DnsServer::panelUrl()` = https://<domain>/ dùng cho email cấp hosting và nút Plesk của khách
- Order item trả thêm `uuid`/`type` của dịch vụ để FE dẫn tới trang quản lý
- Yêu cầu huỷ dịch vụ, chứng chỉ SSL, lịch sử gia hạn, đổi mật khẩu hosting cho khách

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 16:40:24 +07:00

85 lines
2.5 KiB
PHP

<?php
namespace App\Repositories\Api\ServiceClient;
use App\Support\ProductBillingCycles;
use App\Support\ServiceGroup;
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, ?string $group = null)
{
$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);
}
if ($group) {
$query->whereHas('product', fn ($products) => ServiceGroup::constrain($products, $group));
}
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)
{
$product = $this->model->find($productId);
if (!ProductBillingCycles::allows($product->product_type, $billingCycle)) {
return null;
}
$pricing = $product->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();
}
}