feat: Implement product duplication, bulk product status updates and deletion, add client service console ticket retrieval, and update service resource to expose server_name.

This commit is contained in:
pbao9
2026-03-13 16:28:23 +07:00
parent e0341363f6
commit 0e5832b1fb
5 changed files with 120 additions and 1 deletions
@@ -161,6 +161,65 @@ class ProductController extends Controller
]);
}
public function duplicate(int $id): JsonResponse
{
$product = Product::with('pricings')->find($id);
if (!$product) {
return response()->json(['error' => true, 'message' => 'Không tìm thấy sản phẩm.'], 404);
}
$copy = $product->replicate(['uuid', 'slug']);
$copy->name = $product->name . ' (Copy)';
$copy->slug = \Illuminate\Support\Str::slug($copy->name) . '-' . time();
$copy->is_active = false;
$copy->save();
// Duplicate pricings
foreach ($product->pricings as $pricing) {
$copy->pricings()->create($pricing->only([
'billing_cycle', 'price', 'renewal_price', 'setup_fee',
]));
}
return response()->json([
'error' => false,
'message' => 'Nhân bản sản phẩm thành công.',
'data' => new ProductResource($copy),
], 201);
}
public function bulkUpdateStatus(Request $request): JsonResponse
{
$validated = $request->validate([
'ids' => 'required|array',
'ids.*' => 'integer',
'is_active' => 'required|boolean',
]);
$updated = Product::whereIn('id', $validated['ids'])
->update(['is_active' => $validated['is_active']]);
$label = $validated['is_active'] ? 'kích hoạt' : 'ẩn';
return response()->json([
'error' => false,
'message' => "Đã {$label} {$updated} sản phẩm.",
]);
}
public function bulkDestroy(Request $request): JsonResponse
{
$ids = $request->validate(['ids' => 'required|array', 'ids.*' => 'integer'])['ids'];
$deleted = Product::whereIn('id', $ids)->delete();
return response()->json([
'error' => false,
'message' => "Đã xoá {$deleted} sản phẩm.",
]);
}
public function getOs(int $id): JsonResponse
{
$product = Product::find($id);