feat(service): đổi sản phẩm của dịch vụ, 2FA bắt buộc, đính kèm campaign mail, thu hồi IP

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-27 14:24:13 +07:00
co-authored by Claude Sonnet 5.5
parent 6315a392c0
commit a6b641015e
13 changed files with 197 additions and 9 deletions
@@ -105,6 +105,7 @@ class ClientAuthService
'email_verify_code' => $code,
'email_verify_code_expired_at' => now()->addMinutes(5),
]);
$client->forceFill(['two_factor_enabled' => true])->save();
$this->sendVerifyEmail($client, $code);
+75
View File
@@ -0,0 +1,75 @@
<?php
namespace App\Services\IpPool;
use App\Models\IpPool;
use App\Models\IpPoolLog;
use App\Models\ModuleIpAddress;
use App\Models\ModuleVmware;
use App\Models\User;
use App\Models\VirtualMachines;
use Illuminate\Support\Facades\DB;
class IpReleaseService
{
/**
* @param array<int, int> $ids
*/
public function release(array $ids, ?string $note, User $admin): int
{
return DB::transaction(function () use ($ids, $note, $admin) {
$pools = IpPool::whereIn('id', $ids)->lockForUpdate()->get();
$count = 0;
foreach ($pools as $pool) {
$mirrors = ModuleIpAddress::where('ip', $pool->ip_address)->get();
$vms = ModuleVmware::where('ip', $pool->ip_address)
->orWhereIn('module_ip_address', $mirrors->pluck('id'))
->get();
if ($pool->status === 'free' && $pool->service_id === null && $vms->isEmpty()) {
continue;
}
$before = $pool->only(['status', 'customer_id', 'customer_name', 'service_name', 'service_id']);
$this->detach($pool, $mirrors->pluck('id')->all(), $vms->pluck('id')->all());
IpPoolLog::record($pool, IpPoolLog::VM_RELEASED, $before['status'], [
'customer_id' => $before['customer_id'],
'customer_name' => $before['customer_name'],
'service_name' => $before['service_name'],
'service_id' => $before['service_id'],
'vm_name' => $vms->pluck('name')->filter()->implode(', ') ?: null,
'user_id' => $admin->id,
'note' => $note ?: 'Giải phóng IP khỏi dịch vụ/VM',
]);
$count++;
}
return $count;
});
}
/**
* @param array<int, int> $mirrorIds
* @param array<int, int> $vmIds
*/
private function detach(IpPool $pool, array $mirrorIds, array $vmIds): void
{
$pool->update([
'status' => 'free',
'service_id' => null,
'customer_id' => null,
'customer_name' => null,
'service_name' => null,
'contact_email' => null,
'contact_cc' => null,
'revoked_at' => now()->toDateString(),
]);
ModuleIpAddress::whereIn('id', $mirrorIds)->update(['status' => 0, 'vm_name' => null]);
ModuleVmware::whereIn('id', $vmIds)->update(['ip' => null, 'module_ip_address' => null]);
VirtualMachines::where('ip_pool_id', $pool->id)
->orWhere('ip', $pool->ip_address)
->update(['ip_pool_id' => null, 'ip' => null]);
}
}
@@ -45,13 +45,11 @@ class VmCredentialsEmailDataBuilder
private function billingLabel(?int $months): string
{
return match ($months) {
1 => 'Hang thang',
3 => '3 Thang',
6 => '6 Thang',
12 => 'Hang nam',
24 => '2 Nam',
default => ($months ?? 0) . ' Thang',
return match (true) {
$months === 1 => 'Hàng tháng',
$months === 12 => 'Hàng năm',
$months > 12 && $months % 12 === 0 => ($months / 12) . ' năm',
default => ($months ?? 0) . ' tháng',
};
}