feat: add GeneratesUniqueSlug class for unique slug generation
feat: create PostCategoryFactory for generating post category data feat: create PostFactory for generating post data feat: add retry_requested_at column to services table feat: add vcenter provisioning fields to products table feat: add module_host_id to os table feat: create email_notification_templates table for email templates feat: add scenario and format fields to template table feat: add admin fields to transactions table fix: update ticket table columns and types feat: add uuid to ticket table and backfill existing records fix: make ticket_reply user_id nullable feat: create notifications table for user notifications fix: make ticket uuid nullable feat: create post_categories table for blog categories feat: create posts table for blog posts feat: add invoice email template for PDF generation
This commit is contained in:
@@ -14,10 +14,12 @@ use App\Http\Requests\Api\Order\PayOrderRequest;
|
||||
use App\Http\Requests\Api\Order\StoreOrderRequest;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceItem;
|
||||
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderItem;
|
||||
use App\Models\Product;
|
||||
use App\Models\Service;
|
||||
use App\Models\VirtualMachines;
|
||||
use App\Repositories\Api\Order\OrderRepository;
|
||||
use App\Services\ActivityLogger;
|
||||
use App\Services\Api\Order\OrderService;
|
||||
@@ -57,6 +59,35 @@ class OrderController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /v1/orders/check-server-name?name=xxx
|
||||
* Kiểm tra tên server đã tồn tại chưa (order_items, services, module_vmware, virtual_machines)
|
||||
*/
|
||||
public function checkServerName(Request $request): JsonResponse
|
||||
{
|
||||
$name = trim($request->query('name', ''));
|
||||
|
||||
if ($name === '') {
|
||||
return response()->json(['available' => false, 'message' => 'Tên server không được để trống.']);
|
||||
}
|
||||
|
||||
$exists =
|
||||
OrderItem::where('server_name', $name)->exists() ||
|
||||
Service::where('server_name', $name)->exists() ||
|
||||
ModuleVmware::where('name', $name)->exists() ||
|
||||
ModuleVmware::where('hostname', $name)->exists() ||
|
||||
VirtualMachines::where('name', $name)->exists();
|
||||
|
||||
if ($exists) {
|
||||
return response()->json([
|
||||
'available' => false,
|
||||
'message' => 'Tên server này đã được sử dụng, vui lòng chọn tên khác.',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json(['available' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /v1/client/orders — customer's order list
|
||||
*/
|
||||
@@ -97,7 +128,7 @@ class OrderController extends Controller
|
||||
{
|
||||
try {
|
||||
$order = Order::query()
|
||||
->with(['invoice', 'orderItems.product', 'customer'])
|
||||
->with(['invoice', 'orderItems.product', 'orderItems.service', 'customer'])
|
||||
->where('customer_id', $request->user()->id)
|
||||
->where('id', $id)
|
||||
->first();
|
||||
@@ -227,6 +258,7 @@ class OrderController extends Controller
|
||||
{
|
||||
try {
|
||||
$order = Order::where('id', $id)
|
||||
->with(['invoice', 'orderItems.service'])
|
||||
->where('customer_id', $request->user()->id)
|
||||
->first();
|
||||
|
||||
@@ -238,6 +270,26 @@ class OrderController extends Controller
|
||||
return $this->error('Đơn hàng chưa được thanh toán.');
|
||||
}
|
||||
|
||||
$paidAt = $order->invoice->paid_at ? Carbon::parse($order->invoice->paid_at) : null;
|
||||
if (!$paidAt || $paidAt->diffInMinutes(now()) < 180) {
|
||||
return $this->error('Vui lòng chờ khoảng 3 tiếng sau khi thanh toán mới có thể khởi tạo lại dịch vụ.');
|
||||
}
|
||||
|
||||
$service = $order->orderItems->first()?->service;
|
||||
if (!$service || (int) $service->customer_id !== (int) $request->user()->id) {
|
||||
return $this->error('Không tìm thấy dịch vụ hợp lệ để khởi tạo lại.');
|
||||
}
|
||||
|
||||
if ($service->status !== 'pending') {
|
||||
return $this->error('Dịch vụ đã được khởi tạo hoặc không ở trạng thái chờ.');
|
||||
}
|
||||
|
||||
if ($service->retry_requested_at) {
|
||||
return $this->error('Dịch vụ đã được yêu cầu khởi tạo lại một lần. Vui lòng liên hệ kỹ thuật qua mailto:kythuat@tgs.com.vn');
|
||||
}
|
||||
|
||||
$service->update(['retry_requested_at' => now()]);
|
||||
|
||||
RetryProvisioningOrchestrator::dispatch($order->id, $request->user()->id);
|
||||
|
||||
$this->activityLogger->log(
|
||||
@@ -302,7 +354,6 @@ class OrderController extends Controller
|
||||
'order.orderItems.product',
|
||||
'order.vmWare.ipAddress',
|
||||
'order.vmWare.os',
|
||||
'invoiceItems',
|
||||
'customer',
|
||||
'attachments',
|
||||
])
|
||||
@@ -691,6 +742,13 @@ class OrderController extends Controller
|
||||
'server_name' => $item->server_name,
|
||||
'os_id' => $item->os_id,
|
||||
'price' => (float) $item->price,
|
||||
'service' => $item->service ? [
|
||||
'id' => $item->service->id,
|
||||
'status' => $item->service->status,
|
||||
'status_text' => $item->service->status_label,
|
||||
'retry_requested_at' => $this->isoDate($item->service->retry_requested_at),
|
||||
'can_retry_provisioning' => $this->canRetryProvisioning($item->service),
|
||||
] : null,
|
||||
'product' => $item->product ? [
|
||||
'id' => $item->product->id,
|
||||
'uuid' => $item->product->uuid,
|
||||
@@ -737,6 +795,24 @@ class OrderController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
private function canRetryProvisioning(Service $service): bool
|
||||
{
|
||||
if ($service->status !== 'pending') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($service->retry_requested_at) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$paidAt = $service->invoice?->paid_at;
|
||||
if (!$paidAt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Carbon::parse($paidAt)->diffInMinutes(now()) >= 180;
|
||||
}
|
||||
|
||||
private function formatInvoiceDetail(Invoice $invoice): array
|
||||
{
|
||||
$order = $invoice->order;
|
||||
@@ -780,15 +856,15 @@ class OrderController extends Controller
|
||||
'disk' => $firstItem->product?->disk,
|
||||
],
|
||||
] : null,
|
||||
'items' => ($invoice->relationLoaded('invoiceItems') ? $invoice->invoiceItems : collect())->map(fn($item) => [
|
||||
'id' => $item->id,
|
||||
'type' => $item->type,
|
||||
'description' => $item->description,
|
||||
'months' => $item->months,
|
||||
'quantity' => $item->quantity,
|
||||
'unit_price' => (float) $item->unit_price,
|
||||
'total_price' => (float) $item->total_price,
|
||||
])->all(),
|
||||
'items' => $order ? $order->orderItems->map(fn($item) => [
|
||||
'id' => $item->id,
|
||||
'product_name' => $item->product?->name,
|
||||
'server_name' => $item->server_name,
|
||||
'billing_cycle' => $item->billing_cycle,
|
||||
'price' => (float) $item->price,
|
||||
'months' => $item->months,
|
||||
'os_id' => $item->os_id,
|
||||
])->values()->all() : [],
|
||||
'attachments' => ($invoice->relationLoaded('attachments') ? $invoice->attachments : collect())->map(fn($a) => [
|
||||
'id' => $a->id,
|
||||
'filename' => $a->filename,
|
||||
|
||||
Reference in New Issue
Block a user