update
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -44,6 +44,11 @@ class ClientRegisterRequest extends FormRequest
|
||||
'min:6',
|
||||
'confirmed'
|
||||
],
|
||||
|
||||
'trial_config' => [
|
||||
'nullable',
|
||||
'string',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\Admin;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class TrialRegistrationRequest extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public array $data) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '[ADMIN] Yêu cầu dùng thử Cloud VPS - ' . ($this->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 [];
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user