feat: email gửi tay/nhắc gia hạn, gói hosting, sửa dữ liệu sản phẩm

- Gửi email theo template cho 1 khách, tab lịch sử email, nhắc gia hạn dịch vụ hàng loạt
- Mail lưu from/bcc/sent_by; mẫu MARKETING và mẫu cũ trong TemplateSeeder
- Gói hosting: giới hạn, trạng thái, lấy plan Plesk qua CLI gateway
- Backfill payment_method và ngày đơn hàng còn thiếu
- Bổ sung field CPU/RAM/Disk/Băng thông cho loại sản phẩm vps và cloud

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-09 11:32:05 +07:00
co-authored by Claude Opus 5.5
parent 8651dde6b1
commit 30898ea46f
59 changed files with 1771 additions and 108 deletions
@@ -3,15 +3,17 @@
namespace App\Http\Controllers\Api\Admin\Hosting;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Hosting\ServicePlanRequest;
use App\Models\DnsServer;
use App\Models\ServicePlan;
use App\Services\Plesk\PleskServicePlanService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ServicePlanController extends Controller
{
public function index(): JsonResponse
{
$plans = ServicePlan::with('plesk', 'dnsServer')->orderBy('title')->get();
$plans = ServicePlan::with('plesk', 'dnsServer')->orderBy('sort_order')->orderBy('title')->get();
return response()->json(['error' => false, 'data' => $plans]);
}
@@ -27,29 +29,11 @@ class ServicePlanController extends Controller
return response()->json(['error' => false, 'data' => $plan]);
}
public function store(Request $request): JsonResponse
public function store(ServicePlanRequest $request): JsonResponse
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'vcpu' => 'required|integer|min:0',
'ram' => 'required|integer|min:0',
'disk' => 'required|integer|min:0',
'domain' => 'required|integer|min:0',
'dns_manager_server_id' => 'nullable|integer|exists:dns_manager_servers,id',
'plesk_plan_name' => 'nullable|string|max:255',
'note' => 'nullable|string',
]);
$plan = ServicePlan::create($request->planAttributes());
$plan = ServicePlan::create([
'title' => $validated['title'],
'vcpu' => $validated['vcpu'],
'ram' => $validated['ram'],
'disk' => $validated['disk'],
'domain' => $validated['domain'],
'dns_manager_server_id' => $validated['dns_manager_server_id'] ?? null,
]);
$this->savePlesk($plan, $validated);
$this->savePlesk($plan, $request->validated());
return response()->json([
'error' => false,
@@ -58,7 +42,7 @@ class ServicePlanController extends Controller
], 201);
}
public function update(Request $request, int $id): JsonResponse
public function update(ServicePlanRequest $request, int $id): JsonResponse
{
$plan = ServicePlan::find($id);
@@ -66,27 +50,9 @@ class ServicePlanController extends Controller
return response()->json(['error' => true, 'message' => 'Không tìm thấy gói hosting.'], 404);
}
$validated = $request->validate([
'title' => 'required|string|max:255',
'vcpu' => 'required|integer|min:0',
'ram' => 'required|integer|min:0',
'disk' => 'required|integer|min:0',
'domain' => 'required|integer|min:0',
'dns_manager_server_id' => 'nullable|integer|exists:dns_manager_servers,id',
'plesk_plan_name' => 'nullable|string|max:255',
'note' => 'nullable|string',
]);
$plan->update($request->planAttributes());
$plan->update([
'title' => $validated['title'],
'vcpu' => $validated['vcpu'],
'ram' => $validated['ram'],
'disk' => $validated['disk'],
'domain' => $validated['domain'],
'dns_manager_server_id' => $validated['dns_manager_server_id'] ?? null,
]);
$this->savePlesk($plan, $validated);
$this->savePlesk($plan, $request->validated());
return response()->json([
'error' => false,
@@ -108,6 +74,23 @@ class ServicePlanController extends Controller
return response()->json(['error' => false, 'message' => 'Xoá gói hosting thành công.']);
}
public function pleskPlans(int $serverId, PleskServicePlanService $plans): JsonResponse
{
$server = DnsServer::find($serverId);
if (!$server || !$server->servesHosting()) {
return response()->json(['error' => true, 'message' => 'Server không hỗ trợ hosting.'], 404);
}
$names = $plans->names($server);
if ($names === null) {
return response()->json(['error' => true, 'message' => 'Không lấy được danh sách plan từ Plesk.'], 502);
}
return response()->json(['error' => false, 'data' => $names]);
}
private function savePlesk(ServicePlan $plan, array $data): void
{
if (empty($data['plesk_plan_name'])) {