This commit is contained in:
pbao9
2026-02-11 11:18:35 +07:00
parent d59b2a0840
commit 6b6385f441
27 changed files with 386 additions and 30 deletions
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App\Enums\Client;
enum ClientGender: int
{
case MALE = 0;
case FEMALE = 1;
public function label(): string
{
return match ($this) {
self::MALE => 'Nam',
self::FEMALE => 'Nữ',
};
}
}
+27 -2
View File
@@ -34,8 +34,33 @@ class Handler extends ExceptionHandler
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
$this->renderable(function (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e, $request) {
if (!$request->expectsJson() && !$request->is('v1/*') && !$request->is('api/*')) {
return null;
}
$previous = $e->getPrevious();
if ($previous instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
$modelClass = $previous->getModel();
$pageType = match ($modelClass) {
\App\Models\Product::class => 'service',
\App\Models\Customer::class => 'client',
\App\Models\Post::class => 'post',
default => 'unknown',
};
return response()->json([
'error' => true,
'message' => 'Dữ liệu không tồn tại',
'page_type' => $pageType,
], 404);
}
return response()->json([
'error' => true,
'message' => 'API Route not found',
], 404);
});
}
}
@@ -0,0 +1,45 @@
<?php
namespace App\Http\Controllers\Api\Service;
use App\Http\Controllers\Controller;
use App\Http\Resources\Api\Service\ServiceResource;
use App\Models\Product;
use App\Services\Api\Service\ServiceService;
class ServiceController extends Controller
{
protected $serviceService;
public function __construct(ServiceService $serviceService)
{
$this->serviceService = $serviceService;
}
/**
* Lấy danh sách dịch vụ (sản phẩm) đang hoạt động
*/
public function getService()
{
$services = $this->serviceService->getActiveServices();
return response()->json([
'error' => false,
'message' => 'Lấy dữ liệu thành công',
'page_type' => 'service',
'data' => ServiceResource::collection($services),
]);
}
public function getDetailService(Product $product)
{
$product->load(['osVersions.osGroup', 'category', 'pricings' => fn ($q) => $q->where('is_active', 1)]);
return response()->json([
'error' => false,
'message' => 'Lấy dữ liệu thành công',
'page_type' => 'service',
'data' => new ServiceResource($product),
]);
}
}
@@ -131,7 +131,7 @@ class Datacenter extends Controller
->addColumn(
'action',
function ($d) {
return view('administrator.pages.package.datacenter.datatable.edit', ['row' => $d])->render();
return view('administrator.pages.package.datacenter.datatable.action', ['row' => $d])->render();
}
)
->filterColumn('v_center.host', function ($query, $keyword) {
@@ -25,19 +25,15 @@ class ClientResource extends JsonResource
'phone' => $this->phone,
'address' => $this->address,
'city' => $this->city,
'ward' => $this->ward,
'province' => $this->province,
'active_phone' => 1,
'active_zalo' => 1,
'gender' => $this->gender,
'ward' => $this->ward->name,
'province' => $this->province->name,
'gender' => $this->gender_label,
'date' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : null,
'company' => $this->company ?? '',
'mst' => null,
'avatar' => $this->avatar,
'cmnd_after' => $this->cmnd_after,
'cmnd_before' => $this->cmnd_before,
'cmnd_active' => (bool) $this->identity_number,
'cmnd' => $this->cmnd,
'cmnd_after' => $this->front_identity_number,
'cmnd_before' => $this->back_identity_number,
'cmnd' => $this->identity_number,
'fb_link' => null,
'active_2fa' => 0,
'off_mail_marketing' => $this->off_mail_marketing,
@@ -0,0 +1,49 @@
<?php
namespace App\Http\Resources\Api\Service;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ServiceResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'uuid' => $this->uuid,
'name' => $this->name,
'slug' => $this->slug,
'short_description' => $this->short_description,
'description' => $this->description,
'thumbnail' => $this->thumbnail ? asset($this->thumbnail) : null,
'product_type' => $this->product_type,
'specs' => [
'cpu' => $this->cpu,
'ram' => $this->ram,
'disk' => $this->disk,
'bandwidth' => $this->bandwidth,
'gpu' => $this->gpu
],
'stock' => $this->stock,
'price' => $this->price,
'price_sale' => $this->price_sale,
'group' => $this->category->name,
'os' => $this->osVersions->groupBy('os_group_id')->map(function ($versions) {
$group = $versions->first()->osGroup;
return [
'name' => $group?->name,
'thumbnail' => $group?->thumbnail,
'versions' => $versions->map(fn($os) => [
'version' => $os->version,
'name' => $os->name,
])->values(),
];
})->values(),
];
}
}
+10
View File
@@ -57,6 +57,11 @@ class Customer extends Authenticatable
'first_name',
'last_name',
'point',
'gender_label',
];
protected $casts = [
'gender' => \App\Enums\Client\ClientGender::class,
];
/**
@@ -219,4 +224,9 @@ class Customer extends Authenticatable
{
return $this->belongsTo(Ward::class, 'ward_code', 'code');
}
public function getGenderLabelAttribute()
{
return $this->gender?->label() ?? 'Khác';
}
}
+6
View File
@@ -365,6 +365,12 @@ class RepositoryProvider extends ServiceProvider
\App\Repositories\Api\Client\ClientRepositoryInterface::class,
\App\Repositories\Api\Client\ClientRepository::class
);
// Service API
$this->app->bind(
\App\Repositories\Api\Service\ServiceRepositoryInterface::class,
\App\Repositories\Api\Service\ServiceRepository::class
);
}
/**
@@ -0,0 +1,35 @@
<?php
namespace App\Repositories\Api\Service;
use App\Models\Product;
use App\Repositories\Api\BaseApiRepository;
class ServiceRepository extends BaseApiRepository implements ServiceRepositoryInterface
{
public function getModel()
{
return Product::class;
}
/**
* Lấy danh sách sản phẩm đang hoạt động
*/
public function getActiveServices()
{
return $this->model
->with(['osVersions.osGroup', 'category'])
->where('is_active', 1)
->orderBy('sort_order', 'asc')
->get();
}
public function findActiveBySlug(string $slug)
{
return $this->model
->with(['osVersions.osGroup', 'category', 'pricings' => fn ($q) => $q->where('is_active', 1)])
->where('slug', $slug)
->where('is_active', 1)
->first();
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Repositories\Api\Service;
use App\Repositories\BaseRepositoryInterface;
interface ServiceRepositoryInterface extends BaseRepositoryInterface
{
/**
* Lấy danh sách sản phẩm đang hoạt động
*/
public function getActiveServices();
public function findActiveBySlug(string $slug);
}
@@ -0,0 +1,28 @@
<?php
namespace App\Services\Api\Service;
use App\Repositories\Api\Service\ServiceRepositoryInterface;
class ServiceService
{
protected $serviceRepository;
public function __construct(ServiceRepositoryInterface $serviceRepository)
{
$this->serviceRepository = $serviceRepository;
}
/**
* Lấy danh sách dịch vụ đang hoạt động
*/
public function getActiveServices()
{
return $this->serviceRepository->getActiveServices();
}
public function findActiveBySlug(string $slug)
{
return $this->serviceRepository->findActiveBySlug($slug);
}
}