|
|
|
@ -5,7 +5,10 @@ namespace App\Http\Controllers\Admin; |
|
|
|
use App\Exceptions\CustomException; |
|
|
|
use App\Models\AdminFloor; |
|
|
|
use App\Models\AdminFloorRegion; |
|
|
|
use App\Models\Parking; |
|
|
|
use App\Models\ParkingSpace; |
|
|
|
use App\Services\AdminFloorService; |
|
|
|
use App\Services\AdminTranslationService; |
|
|
|
use App\Services\ApiResponseService; |
|
|
|
use Exception; |
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
@ -51,12 +54,58 @@ class FloorController extends BaseController |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($request->has('name')) { |
|
|
|
$name = $request->input('name'); |
|
|
|
if ($name) { |
|
|
|
$query->where('name', 'like', "%{$name}%"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($request->has('create_start_time') |
|
|
|
&& $request->has( |
|
|
|
'create_end_time' |
|
|
|
) |
|
|
|
) { |
|
|
|
$create_start_time = $request->input('create_start_time'); |
|
|
|
$create_end_time = $request->input('create_end_time'); |
|
|
|
if ($create_start_time && $create_end_time) { |
|
|
|
$query->whereBetween('created_at', [ |
|
|
|
$create_start_time . ' 00:00:00', |
|
|
|
$create_end_time . ' 23:59:59' |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 分页 |
|
|
|
$page = $request->input('page', 1); |
|
|
|
$perPage = $request->input('per_page', 10); |
|
|
|
|
|
|
|
$statusArr = AdminFloorService::getStatus(); |
|
|
|
$total = $query->count(); |
|
|
|
$items = $query->latest()->forPage($page, $perPage)->get(); |
|
|
|
$items = $query->latest()->forPage($page, $perPage)->get()->each( |
|
|
|
function ($item) use($statusArr) { |
|
|
|
$item['name'] |
|
|
|
= AdminTranslationService::getTranslationTypeName( |
|
|
|
$item['id'], |
|
|
|
4, |
|
|
|
$item['name'] |
|
|
|
); |
|
|
|
$item['parking'] = Parking::getName( |
|
|
|
$item['building_floor'] |
|
|
|
); |
|
|
|
$item['status_str'] = $statusArr[$item['status']]; |
|
|
|
$item['parking_space_count'] = ParkingSpace::query()->where( |
|
|
|
'floor_id', |
|
|
|
$item['id'] |
|
|
|
)->count(); |
|
|
|
$open_time_res = option_time($item['open_time']); |
|
|
|
$item['open_time'] = $open_time_res['time']; |
|
|
|
$item['open_time_str'] = $open_time_res['str']; |
|
|
|
$close_time_res = option_time($item['close_time']); |
|
|
|
$item['close_time'] = $close_time_res['time']; |
|
|
|
$item['close_time_str'] = $close_time_res['str']; |
|
|
|
return $item; |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
return $this->responseService->success([ |
|
|
|
'items' => $items, |
|
|
|
@ -108,13 +157,25 @@ class FloorController extends BaseController |
|
|
|
protected function saveValidator(array $data, int $id = 0): void |
|
|
|
{ |
|
|
|
$rules = [ |
|
|
|
'name' => 'required|max:50', |
|
|
|
'region_data' => 'array' |
|
|
|
'name' => 'required|max:50', |
|
|
|
'open_time' => 'required|size:5', |
|
|
|
'close_time' => 'required|size:5', |
|
|
|
]; |
|
|
|
$messages = [ |
|
|
|
'name.required' => __('validation.admin_floor.n_empty'), |
|
|
|
'name.max' => __('validation.admin_floor.n_max'), |
|
|
|
'region_data.array' => __('validation.admin_floor.r_array') |
|
|
|
'name.required' => __('validation.admin_floor.n_empty'), |
|
|
|
'name.max' => __('validation.admin_floor.n_max'), |
|
|
|
'open_time.required' => __( |
|
|
|
'validation.parking_management.o_empty' |
|
|
|
), |
|
|
|
'open_time.size' => __( |
|
|
|
'validation.parking_management.o_length' |
|
|
|
), |
|
|
|
'close_time.required' => __( |
|
|
|
'validation.parking_management.c_empty' |
|
|
|
), |
|
|
|
'close_time.size' => __( |
|
|
|
'validation.parking_management.c_length' |
|
|
|
) |
|
|
|
]; |
|
|
|
if ($id) { |
|
|
|
$this->validateId($id, AdminFloor::class); |
|
|
|
@ -135,11 +196,11 @@ class FloorController extends BaseController |
|
|
|
try { |
|
|
|
$this->validateId($id, AdminFloor::class); |
|
|
|
$data = [ |
|
|
|
'region_list' => AdminFloorRegion::getFloorRegion($id), |
|
|
|
'region_list' => AdminFloorRegion::getFloorRegion($id), |
|
|
|
'building_floor_list' => get_select_data( |
|
|
|
AdminFloorService::getBuildingFloor() |
|
|
|
), |
|
|
|
'item' => AdminFloorService::getFloorData($id) |
|
|
|
'item' => AdminFloorService::getFloorData($id) |
|
|
|
]; |
|
|
|
return $this->responseService->success($data); |
|
|
|
} catch (Exception $e) { |
|
|
|
|