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.
117 lines
3.9 KiB
117 lines
3.9 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Models\AdminFloor;
|
|
use App\Models\ParkingSpace;
|
|
use App\Models\ParkingSpaceType;
|
|
use App\Services\AdminMenuService;
|
|
use App\Services\ApiResponseService;
|
|
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', 1);
|
|
$pattern_id = $request->get('pattern_id', 1);
|
|
$floorData = AdminFloor::query()->where(
|
|
'building_floor',
|
|
$building_floor
|
|
)->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)
|
|
->count();
|
|
|
|
$vacant_count = ParkingSpace::query()->where(
|
|
['floor_id' => $floor_id, 'status' => 0]
|
|
)->count();
|
|
|
|
$repair_count = ParkingSpace::query()->where(
|
|
['floor_id' => $floor_id, 'status' => 2]
|
|
)->count();
|
|
|
|
$typeData = ParkingSpaceType::getData();
|
|
$type_list = [];
|
|
foreach ($typeData as $typeItem) {
|
|
$spaceWhere = [
|
|
'floor_id' => $floor_id,
|
|
'space_type_id' => $typeItem['id']
|
|
];
|
|
$type_count = ParkingSpace::query()->where($spaceWhere)
|
|
->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(Request $request)
|
|
{
|
|
try {
|
|
$pattern_id = $request->get('pattern_id', 1);
|
|
$sum = ParkingSpace::query()->count();
|
|
$use_sum = ParkingSpace::query()->where('status', 1)->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()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|