feat: Implement payment proof upload for orders, add payment method selection API, and seed bank transfer payment options.
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Admin\ProductResource;
|
||||
use App\Models\Product;
|
||||
use App\Repositories\Admin\Product\AdminProductRepositoryInterface;
|
||||
use App\Models\Os;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -44,6 +45,9 @@ class ProductController extends Controller
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy sản phẩm.'], 404);
|
||||
}
|
||||
|
||||
// Load operatingSystems relationship (product_os table)
|
||||
$product->load('operatingSystems');
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => new ProductResource($product),
|
||||
@@ -105,11 +109,13 @@ class ProductController extends Controller
|
||||
'product_categories_id' => 'nullable|integer|exists:product_categories,id',
|
||||
'product_type' => 'nullable|string',
|
||||
'is_active' => 'boolean',
|
||||
'setup_fee' => 'nullable|numeric|min:0',
|
||||
'cpu' => 'nullable|numeric|min:0',
|
||||
'ram' => 'nullable|numeric|min:0',
|
||||
'disk' => 'nullable|numeric|min:0',
|
||||
'bandwidth' => 'nullable|numeric|min:0',
|
||||
'setup_fee' => 'nullable|numeric|min:0',
|
||||
'cpu' => 'nullable|numeric|min:0',
|
||||
'ram' => 'nullable|numeric|min:0',
|
||||
'disk' => 'nullable|numeric|min:0',
|
||||
'bandwidth' => 'nullable|numeric|min:0',
|
||||
'os_ids' => 'nullable|array',
|
||||
'os_ids.*' => 'integer|exists:os,id',
|
||||
]);
|
||||
|
||||
if (isset($validated['name']) && $validated['name'] !== $product->name) {
|
||||
@@ -121,8 +127,17 @@ class ProductController extends Controller
|
||||
$validated['product_type'] = $category?->type;
|
||||
}
|
||||
|
||||
// Handle OS associations via product_os table
|
||||
$osIds = $validated['os_ids'] ?? null;
|
||||
unset($validated['os_ids']);
|
||||
|
||||
$product->update($validated);
|
||||
|
||||
// Sync OS associations in product_os table
|
||||
if ($osIds !== null) {
|
||||
$product->operatingSystems()->sync($osIds);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Cập nhật sản phẩm thành công.',
|
||||
@@ -151,7 +166,7 @@ class ProductController extends Controller
|
||||
$product = Product::find($id);
|
||||
|
||||
if (!$product) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy sản phẩm.'], 404);
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy sản phờng trình.'], 404);
|
||||
}
|
||||
|
||||
$osList = $product->osVersions()
|
||||
@@ -171,4 +186,49 @@ class ProductController extends Controller
|
||||
'data' => $osList,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getOsList(): JsonResponse
|
||||
{
|
||||
$osList = Os::with('osGroup')
|
||||
->where('status', 1)
|
||||
->get()
|
||||
->map(fn($os) => [
|
||||
'id' => $os->id,
|
||||
'name' => $os->name,
|
||||
'version' => $os->version,
|
||||
'os_group_name' => $os->osGroup?->name,
|
||||
'template_id' => $os->template_id,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $osList,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getOperatingSystems(int $id): JsonResponse
|
||||
{
|
||||
$product = Product::find($id);
|
||||
|
||||
if (!$product) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy sản phẩm.'], 404);
|
||||
}
|
||||
|
||||
$osList = $product->operatingSystems()
|
||||
->with('osGroup')
|
||||
->where('status', 1)
|
||||
->get()
|
||||
->map(fn($os) => [
|
||||
'id' => $os->id,
|
||||
'name' => $os->name,
|
||||
'version' => $os->version,
|
||||
'os_group_name' => $os->osGroup?->name,
|
||||
'template_id' => $os->template_id,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $osList,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user