feat: Reorganize database migrations for module snapshots, VMware, and OS groups, and implement customer order creation email notifications.

This commit is contained in:
pbao9
2026-03-12 12:31:52 +07:00
parent 1934be9a19
commit 508d5186db
19 changed files with 350 additions and 195 deletions
@@ -0,0 +1,39 @@
<?php
namespace App\Jobs\Mail\Customer;
use App\Mail\Customer\OrderCreated;
use App\Models\Template;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
class OrderCreatedJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(public readonly array $data) {}
public function handle(): void
{
$template = Template::where('name', 'Order Created')->where('status', 1)->first();
if (!$template) {
Log::warning('OrderCreatedJob: Template "Order Created" not found or inactive.');
return;
}
try {
Mail::to($this->data['customer_email'])->send(new OrderCreated($template, $this->data));
} catch (\Throwable $e) {
Log::error('OrderCreatedJob: Failed to send email. ' . $e->getMessage(), [
'customer_email' => $this->data['customer_email'],
'order_num' => $this->data['order_num'] ?? null,
]);
}
}
}
@@ -14,6 +14,7 @@ use App\Models\ModuleVmware;
use App\Models\ModuleIpAddress;
use App\Models\IpPool;
use App\Models\Log as CustomerLog;
use App\Models\Service;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@@ -255,6 +256,22 @@ class CreateVirtualMachineJob implements ShouldQueue
AssignIPJob::dispatch($vmId, $moduleVmware->id, $moduleIpAddress->ip)
->delay(now()->addMinutes(5));
// Lưu Service record để track dịch vụ của khách hàng
Service::create([
'customer_id' => $customer->id,
'product_id' => $this->item->product_id,
'order_item_id' => $this->item->id,
'invoice_id' => $invoice?->id,
'vm_id' => $vmId,
'server_name' => $serverName,
'status' => 'active',
'auto_renew' => false,
'started_at' => now(),
'expires_at' => $this->item->months > 0
? now()->addMonths($this->item->months)
: null,
]);
} catch (\Exception $e) {
Log::error('❌ Lỗi khi lưu dữ liệu VM và IP address: ' . $e->getMessage(), [
'vmware_id' => $vmId,