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.
90 lines
2.9 KiB
90 lines
2.9 KiB
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\AdminFloor;
|
|
use App\Models\ParkingElectronicMap;
|
|
use App\Models\ParkingSpace;
|
|
|
|
class ParkingElectronicMapService extends BaseService
|
|
{
|
|
|
|
/**
|
|
* 构造函数
|
|
* @param OperationLogService $logService
|
|
*/
|
|
public function __construct(OperationLogService $logService)
|
|
{
|
|
parent::__construct($logService);
|
|
$this->logService = $logService;
|
|
$this->logService->menuTitle = 'draw_map';
|
|
}
|
|
|
|
public function saveModel(array $data)
|
|
{
|
|
$floor_id = $data['floor_id'];
|
|
$space_id = $data['parking_space_id'];
|
|
|
|
$saveData = $where = [
|
|
'floor_id' => $floor_id,
|
|
'space_id' => $space_id
|
|
];
|
|
$res = ParkingElectronicMap::query()->where($where)->get()->toArray();
|
|
$saveData['width'] = $data['width'] ?? '0';
|
|
$saveData['height'] = $data['height'] ?? '0';
|
|
$saveData['coordinate_x'] = $data['coordinate_x'] ?? '';
|
|
$saveData['coordinate_y'] = $data['coordinate_y'] ?? '';
|
|
$saveData['min_width'] = $data['min_width'] ?? '';
|
|
$saveData['min_height'] = $data['min_height'] ?? '';
|
|
$saveData['keep_aspect_ratio'] = $data['keep_aspect_ratio'] ?? '0';
|
|
$saveData['aspect_ratio'] = $data['aspect_ratio'] ?? '';
|
|
if ($res) {
|
|
$saveData['update_at'] = get_datetime();
|
|
$model = ParkingElectronicMap::query()->findOrFail($res[0]['id']);
|
|
$oldValues = $model->toArray();
|
|
$model->update($saveData);
|
|
$this->logService->logUpdated($model, $oldValues, 'map.save');
|
|
} else {
|
|
$saveData['create_at'] = get_datetime();
|
|
$model = ParkingElectronicMap::query()->create($saveData);
|
|
$this->logService->logCreated($model, 'map.save');
|
|
}
|
|
}
|
|
|
|
public function getList($params): array
|
|
{
|
|
$floor_id = $params['floor_id'];
|
|
$where = [
|
|
'floor_id' => $floor_id
|
|
];
|
|
if (isset($params['parking_space_id'])
|
|
&& !empty($params['parking_space_id'])
|
|
) {
|
|
$where['space_id'] = $params['parking_space_id'];
|
|
}
|
|
$columns = [
|
|
'id',
|
|
'floor_id',
|
|
'space_id',
|
|
'width',
|
|
'height',
|
|
'coordinate_x',
|
|
'min_width',
|
|
'min_height',
|
|
'keep_aspect_ratio',
|
|
'aspect_ratio'
|
|
];
|
|
$list = ParkingElectronicMap::query()->where($where)->select($columns)
|
|
->get()->toArray();
|
|
foreach ($list as &$item) {
|
|
$item['floor_name'] = AdminFloor::query()->where('id', $item['floor_id'])
|
|
->value('name');
|
|
$item['parking_space_number'] = ParkingSpace::query()->where(
|
|
'id',
|
|
$item['space_id']
|
|
)->value('number');
|
|
unset($item['floor_id'], $item['space_id']);
|
|
}
|
|
return $list;
|
|
}
|
|
}
|
|
|