- Implemented client access token verification middleware to secure API endpoints. - Updated ServiceController to fetch active hosting services for authenticated users. - Refactored OrderController to ensure order retrieval is customer-specific. - Improved error logging in VmController for unexpected vCenter responses. - Disabled VNPay auto-deposit in TransactionController, switching to manual deposit flow. - Enhanced ServiceClientDetailResource to include Plesk credentials for hosting accounts. - Adjusted VpsServiceResource to dynamically set page type based on product type. - Added logging for PowerShellService to capture errors in RDP port changes. - Provisioning job now resolves service plans and logs relevant information for hosting accounts. - Updated database migrations to add necessary fields for service plans and DNS servers. - Refactored Service and ServicePlan models to establish relationships with hosting accounts and DNS servers.
101 lines
3.4 KiB
PHP
101 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Api\Order;
|
|
|
|
use App\Enums\Invoice\InvoiceStatus;
|
|
use App\Enums\Order\OrderStatus;
|
|
use App\Models\Order;
|
|
use App\Models\OrderItem;
|
|
use App\Repositories\Api\BaseApiRepository;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
class OrderRepository extends BaseApiRepository implements OrderRepositoryInterface
|
|
{
|
|
public function getModel(): string
|
|
{
|
|
return Order::class;
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// createItem
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function createItem(int $orderId, array $data): OrderItem
|
|
{
|
|
$addons = $data['addons'] ?? [];
|
|
unset($data['addons']);
|
|
|
|
return OrderItem::create(
|
|
array_merge(['order_id' => $orderId], $data, ['addons_meta' => !empty($addons) ? $addons : null]),
|
|
);
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// processPayment
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function processPayment(Order $order, string $method): Order
|
|
{
|
|
$order->update([
|
|
'status' => OrderStatus::ACTIVE->value,
|
|
'payment_method' => $method,
|
|
]);
|
|
|
|
if ($order->invoice) {
|
|
$order->invoice->update([
|
|
'status' => InvoiceStatus::PAID->value,
|
|
'payment_method' => $method,
|
|
'paid_at' => now(),
|
|
]);
|
|
}
|
|
|
|
return $order->fresh(['orderItems', 'invoice', 'customer']);
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// hasPendingOrder
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function hasPendingOrder(int $customerId): bool
|
|
{
|
|
return $this->model->where('customer_id', $customerId)->where('status', OrderStatus::PENDING->value)->exists();
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// findByOrderNum
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function findByOrderNum(string $orderNum, int $customerId): ?Order
|
|
{
|
|
return $this->model->where('order_num', $orderNum)->where('customer_id', $customerId)->first();
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// findForCustomer
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function findForCustomer(int $id, int $customerId): ?Order
|
|
{
|
|
return $this->model->where('id', $id)->where('customer_id', $customerId)->first();
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// getOrders
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function getOrders(int $customerId, array $filters): LengthAwarePaginator
|
|
{
|
|
$query = $this->model->where('customer_id', $customerId);
|
|
|
|
if (!empty($filters['total_price'])) {
|
|
$query->where('total', $filters['total_price']);
|
|
}
|
|
|
|
if (!empty($filters['pending']) && filter_var($filters['pending'], FILTER_VALIDATE_BOOLEAN)) {
|
|
$query->where('status', OrderStatus::PENDING->value);
|
|
}
|
|
|
|
return $query->orderByDesc('created_at')->paginate(10);
|
|
}
|
|
}
|