Refactor order payment process and enhance invoice details
- Updated `payOrder` method in `OrderControllerRefactor` to accept `orderNum` instead of `id` for better clarity and functionality. - Implemented `findByOrderNum` method in `OrderRepository` to retrieve orders based on order number and customer ID. - Enhanced `InvoiceDetailResource` to include VMware details and removed unnecessary fields. - Added `service_plan_id` to `ProductResource` and updated the `Product` model to establish a relationship with `ServicePlan`. - Created `ServicePlan` and `ServicePlanPlesk` models along with their respective controllers and migrations for managing hosting service plans. - Updated API routes to include endpoints for managing service plans. - Modified email templates to standardize support phone number across various customer communications.
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Hosting;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServicePlan;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ServicePlanController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$plans = ServicePlan::with('plesk')->orderBy('title')->get();
|
||||
|
||||
return response()->json(['error' => false, 'data' => $plans]);
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$plan = ServicePlan::with('plesk')->find($id);
|
||||
|
||||
if (!$plan) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy gói hosting.'], 404);
|
||||
}
|
||||
|
||||
return response()->json(['error' => false, 'data' => $plan]);
|
||||
}
|
||||
|
||||
public function store(Request $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',
|
||||
'plesk_plan_name' => 'nullable|string|max:255',
|
||||
'note' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$plan = ServicePlan::create([
|
||||
'title' => $validated['title'],
|
||||
'vcpu' => $validated['vcpu'],
|
||||
'ram' => $validated['ram'],
|
||||
'disk' => $validated['disk'],
|
||||
'domain' => $validated['domain'],
|
||||
]);
|
||||
|
||||
$this->savePlesk($plan, $validated);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Tạo gói hosting thành công.',
|
||||
'data' => $plan->load('plesk'),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$plan = ServicePlan::find($id);
|
||||
|
||||
if (!$plan) {
|
||||
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',
|
||||
'plesk_plan_name' => 'nullable|string|max:255',
|
||||
'note' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$plan->update([
|
||||
'title' => $validated['title'],
|
||||
'vcpu' => $validated['vcpu'],
|
||||
'ram' => $validated['ram'],
|
||||
'disk' => $validated['disk'],
|
||||
'domain' => $validated['domain'],
|
||||
]);
|
||||
|
||||
$this->savePlesk($plan, $validated);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Cập nhật gói hosting thành công.',
|
||||
'data' => $plan->fresh('plesk'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$plan = ServicePlan::find($id);
|
||||
|
||||
if (!$plan) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy gói hosting.'], 404);
|
||||
}
|
||||
|
||||
$plan->delete();
|
||||
|
||||
return response()->json(['error' => false, 'message' => 'Xoá gói hosting thành công.']);
|
||||
}
|
||||
|
||||
private function savePlesk(ServicePlan $plan, array $data): void
|
||||
{
|
||||
if (empty($data['plesk_plan_name'])) {
|
||||
$plan->plesk()->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
$plan->plesk()->updateOrCreate(
|
||||
['service_plan_id' => $plan->id],
|
||||
['plesk_plan_name' => $data['plesk_plan_name'], 'note' => $data['note'] ?? null]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user