停车场管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

157 lines
5.5 KiB

<?php
namespace App\Http\Controllers\Admin;
use App\Models\AdminFloor;
use App\Models\ParkingPattern;
use App\Models\ParkingPatternSpace;
use App\Models\ParkingSpace;
use App\Models\ParkingSpaceType;
use App\Services\AdminMenuService;
use App\Services\ApiResponseService;
use App\Services\EventCalendarService;
use App\Services\OperationLogService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class IndexController extends BaseController
{
/**
* 构造函数
* @param ApiResponseService $responseService
*/
public function __construct(ApiResponseService $responseService)
{
parent::__construct($responseService);
}
//
public function index(Request $request): JsonResponse
{
try {
$data = [];
$building_floor = $request->get('building_floor', '');
$floorModel = AdminFloor::query();
if ($building_floor) {
$floorModel->where('building_floor', $building_floor);
}
// 获取当前模式下的车位编号
$targetMode = EventCalendarService::targetModel();
$pattern_id = $targetMode['pattern_id'];
$spaceIds = ParkingPatternSpace::getParkingSpaceIds($pattern_id);
// 获取楼层
$statusArr = [0, 1];
$floorData = $floorModel->select(['id', 'name'])->get()->toArray();
foreach ($floorData as $item) {
$floor_id = $item['id'];
$floor_name = $item['name'];
$sum_count = ParkingSpace::query()->where('floor_id', $floor_id)
->whereIn('status', $statusArr)->whereIn('id', $spaceIds)
->count();
$vacant_count = ParkingSpace::query()->where(
'floor_id',
$floor_id
)->where('status', 0)->whereIn('id', $spaceIds)->count();
$repair_count = ParkingSpace::query()->where(
'floor_id',
$floor_id
)->where('status', 2)->whereIn('id', $spaceIds)
->count();
// 获取当前模式 楼层车位类型
$typeData = [];
$spaceTypeIds = ParkingSpace::query()->where(
'floor_id',
$floor_id
)->wherein('status', $statusArr)->whereIn('id', $spaceIds)
->pluck('space_type_id');
if ($spaceTypeIds) {
$typeData = ParkingSpaceType::query()->whereIn(
'id',
$spaceTypeIds
)->select(['id', 'name'])->get()->toArray();
}
$type_list = [];
foreach ($typeData as $typeItem) {
$spaceWhere = [
'floor_id' => $floor_id,
'space_type_id' => $typeItem['id']
];
$type_count = ParkingSpace::query()->where($spaceWhere)
->whereIn('status', $statusArr)
->whereIn('id', $spaceIds)
->count();
$type_list[] = [
'count' => $type_count,
'name' => $typeItem['name']
];
}
$data[] = [
'floor_name' => $floor_name,
'sum_count' => $sum_count,
'vacant_count' => $vacant_count,
'parking_space_type_list' => $type_list,
'repair_count' => $repair_count
];
}
return $this->responseService->success($data);
} catch (Exception $e) {
$m_prefix = __('exception.get_data_failed');
return $this->responseService->systemError(
$m_prefix . ':' . $e->getMessage()
);
}
}
public function parkingSpaceStatistics()
{
try {
$targetMode = EventCalendarService::targetModel();
$pattern_id = $targetMode['pattern_id'];
$spaceIds = ParkingPatternSpace::getParkingSpaceIds($pattern_id);
$sum = 0;
$use_sum = 0;
if ($spaceIds) {
$sum = ParkingSpace::query()->whereIn('status', [0, 1])
->whereIn('id', $spaceIds)->count();
$use_sum = ParkingSpace::query()->where('status', 1)->whereIn(
'id',
$spaceIds
)->count();
}
$date['proportion'] = get_ratio($sum, $use_sum);
return $this->responseService->success($date);
} catch (Exception $e) {
$m_prefix = __('exception.get_data_failed');
return $this->responseService->systemError(
$m_prefix . ':' . $e->getMessage()
);
}
}
public function menu(): JsonResponse
{
try {
$data = (new AdminMenuService(
new OperationLogService()
))->getUserMenuTreeList(
$this->adminUserId
);
return $this->responseService->success($data);
} catch (Exception $e) {
$m_prefix = __('exception.get_data_failed');
return $this->responseService->systemError(
$m_prefix . ':' . $e->getMessage()
);
}
}
}