diff --git a/app/Http/Controllers/Api/Client/ClientController.php b/app/Http/Controllers/Api/Client/ClientController.php index 0624ac5..9a0718f 100644 --- a/app/Http/Controllers/Api/Client/ClientController.php +++ b/app/Http/Controllers/Api/Client/ClientController.php @@ -190,7 +190,14 @@ class ClientController extends Controller */ public function register(ClientRegisterRequest $request) { - $result = $this->authService->registerClient($request->validated()); + $data = $request->validated(); + + if (!empty($data['trial_config'])) { + $decoded = json_decode((string) $data['trial_config'], true); + $data['trial_config'] = is_array($decoded) ? $decoded : null; + } + + $result = $this->authService->registerClient($data); $client = $result['client']; $this->activityLogger->logAuth('register', 'customer', $client->id, $client->email); diff --git a/app/Http/Requests/Api/Client/ClientRegisterRequest.php b/app/Http/Requests/Api/Client/ClientRegisterRequest.php index af60c6a..a390ed0 100644 --- a/app/Http/Requests/Api/Client/ClientRegisterRequest.php +++ b/app/Http/Requests/Api/Client/ClientRegisterRequest.php @@ -44,6 +44,11 @@ class ClientRegisterRequest extends FormRequest 'min:6', 'confirmed' ], + + 'trial_config' => [ + 'nullable', + 'string', + ], ]; } diff --git a/app/Http/Services/Telegram.php b/app/Http/Services/Telegram.php index 7d94096..490556f 100644 --- a/app/Http/Services/Telegram.php +++ b/app/Http/Services/Telegram.php @@ -84,6 +84,26 @@ class Telegram return $this->SendMessage($msg); } + public function SendTrialRegistration($client, array $trialConfig = []) + { + $msg = "🧪 Khách hàng vừa đăng ký dùng thử Cloud VPS!\n"; + $msg .= "--------------------------------\n"; + $msg .= "👤 Tên: {$client->fullname}\n"; + $msg .= "📧 Email: {$client->email}\n"; + $msg .= "📱 SĐT: {$client->phone}\n"; + $msg .= "--------------------------------\n"; + $msg .= "🖥️ CPU: " . ($trialConfig['cpu'] ?? '-') . "\n"; + $msg .= "💾 RAM: " . ($trialConfig['ram'] ?? '-') . "\n"; + $msg .= "💽 SSD: " . ($trialConfig['ssd'] ?? '-') . "\n"; + $msg .= "🧠 Hệ điều hành: " . ($trialConfig['os'] ?? '-') . "\n"; + if (!empty($trialConfig['other'])) { + $msg .= "📝 Yêu cầu khác: {$trialConfig['other']}\n"; + } + $msg .= "🕒 Thời gian: " . Carbon::now()->format('d/m/Y H:i:s'); + + return $this->SendMessage($msg); + } + public function SendManualDepositPendingApproval($customer, $transaction) { $msg = "🔔 Yêu cầu nạp tiền chờ duyệt!\n"; diff --git a/app/Mail/Admin/TrialRegistrationRequest.php b/app/Mail/Admin/TrialRegistrationRequest.php new file mode 100644 index 0000000..d1ae662 --- /dev/null +++ b/app/Mail/Admin/TrialRegistrationRequest.php @@ -0,0 +1,36 @@ +data['customer_name'] ?? 'N/A'), + ); + } + + public function content(): Content + { + return new Content( + view: 'emails.admin.trial-registration-request', + with: $this->data, + ); + } + + public function attachments(): array + { + return []; + } +} diff --git a/app/Services/Api/Client/ClientAuthService.php b/app/Services/Api/Client/ClientAuthService.php index 624732a..9f0b903 100644 --- a/app/Services/Api/Client/ClientAuthService.php +++ b/app/Services/Api/Client/ClientAuthService.php @@ -2,9 +2,12 @@ namespace App\Services\Api\Client; +use App\Http\Services\Telegram; +use App\Mail\Admin\TrialRegistrationRequest as TrialRegistrationRequestMail; use App\Mail\Customer\VerifyAccount as VerifyAccountMail; use App\Mail\Customer\Welcome as WelcomeMail; use App\Models\RefreshToken; +use App\Models\Setting; use App\Repositories\Api\Client\ClientRepositoryInterface; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; @@ -85,9 +88,50 @@ class ClientAuthService $this->sendVerifyEmail($client, $code); + if (!empty($data['trial_config'])) { + $this->notifyAdminTrialRegistration($client, $data['trial_config']); + } + return ['client' => $client]; } + /** + * Báo admin (email + Telegram) khi khách hàng đăng ký dùng thử Cloud VPS. + */ + protected function notifyAdminTrialRegistration($client, array $trialConfig): void + { + try { + $setting = Setting::where('key', 'setting')->first(); + $settingValue = $setting ? json_decode((string) $setting->value, true) : []; + $adminEmail = $settingValue['admin_email'] ?? null; + + if ($adminEmail) { + Mail::to($adminEmail)->send(new TrialRegistrationRequestMail([ + 'company_name' => $settingValue['company'] ?? config('app.name', 'Portal Admin'), + 'customer_name' => $client->fullname, + 'customer_email' => $client->email, + 'customer_phone' => $client->phone, + 'cpu' => $trialConfig['cpu'] ?? null, + 'ram' => $trialConfig['ram'] ?? null, + 'ssd' => $trialConfig['ssd'] ?? null, + 'os' => $trialConfig['os'] ?? null, + 'other' => $trialConfig['other'] ?? null, + 'created_at' => now()->format('d/m/Y H:i:s'), + ])); + } else { + Log::warning('Trial registration admin email not sent: admin_email not configured.', [ + 'customer_id' => $client->id, + ]); + } + } catch (\Throwable $e) { + Log::warning('Send trial registration admin email failed: ' . $e->getMessage(), [ + 'customer_id' => $client->id, + ]); + } + + (new Telegram())->SendTrialRegistration($client, $trialConfig); + } + /** * Xác thực OTP — kích hoạt tài khoản, trả về token. */ diff --git a/resources/views/emails/admin/trial-registration-request.blade.php b/resources/views/emails/admin/trial-registration-request.blade.php new file mode 100644 index 0000000..7c6c37c --- /dev/null +++ b/resources/views/emails/admin/trial-registration-request.blade.php @@ -0,0 +1,96 @@ + + + + + + Yêu cầu dùng thử Cloud VPS + + + +
+
+
+
🧪
+

Yêu cầu dùng thử Cloud VPS

+

{{ $created_at ?? now()->format('d/m/Y H:i:s') }}

+
+ +
+ + + + + + + + + + + + + + +
Họ tên{{ $customer_name ?? 'N/A' }}
Email{{ $customer_email ?? 'N/A' }}
Số điện thoại{{ $customer_phone ?? 'N/A' }}
+ + + + + + + + + + + + + + + + + + + + @if(!empty($other)) + + + + + @endif + + + + +
CPU{{ $cpu ?: '-' }}
RAM{{ $ram ?: '-' }}
SSD{{ $ssd ?: '-' }}
Hệ điều hành{{ $os ?: '-' }}
Yêu cầu khác{{ $other }}
Trạng tháiChờ khởi tạo
+ +
+ Vui lòng vào trang quản trị để khởi tạo VPS dùng thử theo cấu hình khách hàng yêu cầu. +
+
+ + +
+
+ +