diff --git a/app/Http/Controllers/Admin/EventCalendarController.php b/app/Http/Controllers/Admin/EventCalendarController.php index 59ed926..7761d72 100644 --- a/app/Http/Controllers/Admin/EventCalendarController.php +++ b/app/Http/Controllers/Admin/EventCalendarController.php @@ -313,6 +313,7 @@ class EventCalendarController extends BaseController * @param string $id * @return JsonResponse * @throws ValidationException + * @throws CustomException */ public function end(string $id): JsonResponse { @@ -323,12 +324,11 @@ class EventCalendarController extends BaseController null, __('exception.event_calendar.end_succeeded') ); - } catch (ValidationException $e) { + } catch (ValidationException|CustomException $e) { throw $e; } catch (Exception $e) { return $this->responseService->systemError( - __('exception.event_calendar.end_failed') . ':' - . $e->getMessage() + __('exception.event_calendar.end_failed') ); } } diff --git a/app/Services/EventCalendarService.php b/app/Services/EventCalendarService.php index bbba294..0d9b55a 100644 --- a/app/Services/EventCalendarService.php +++ b/app/Services/EventCalendarService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Exceptions\CustomException; use App\Models\EventCalendar; use App\Models\ParkingPattern; use App\Models\ParkingPatternSpace; @@ -191,7 +192,7 @@ class EventCalendarService extends BaseService $model = EventCalendar::query()->findOrFail($id); $oldValues = $model->toArray(); if ($model['status'] != 1) { - throw new Exception(__('service.event_calendar.error_end')); + throw new CustomException(__('service.event_calendar.error_end')); } $update = [ 'status' => 2, diff --git a/app/Services/ParkingPatternSpaceService.php b/app/Services/ParkingPatternSpaceService.php index 5f8cf56..f6db0a8 100644 --- a/app/Services/ParkingPatternSpaceService.php +++ b/app/Services/ParkingPatternSpaceService.php @@ -164,4 +164,20 @@ class ParkingPatternSpaceService extends BaseService } return []; } + + // 车位删除同步删除已添加的绘制地图 + public static function syncDeleteMapSpace($space_id) + { + $id = ParkingPatternSpace::query()->where([ + 'space_id' => $space_id + ])->value('id'); + if ($id) { + $model = ParkingPatternSpace::query()->findOrFail($id); + $model->delete(); + (new OperationLogService())->logDeleted( + $model, + 'parking_pattern_space.delete' + ); + } + } } diff --git a/app/Services/ParkingSpaceService.php b/app/Services/ParkingSpaceService.php index 2a1f82e..b8b7e9b 100644 --- a/app/Services/ParkingSpaceService.php +++ b/app/Services/ParkingSpaceService.php @@ -425,7 +425,10 @@ class ParkingSpaceService extends BaseService return; } } - $model = ParkingSpace::query()->findOrFail($id); + $model = ParkingSpace::query()->find($id); + if (!$model) { + return; + } $oldValues = $model->toArray(); // 相同不更新 if ($oldValues['space_type_id'] == $type_id) { @@ -553,6 +556,9 @@ class ParkingSpaceService extends BaseService $oldValue['floor_id'] ); + // 同步删除模式关联车位 + ParkingPatternSpaceService::syncDeleteMapSpace($id); + DB::commit(); return true; } catch (Exception $e) { @@ -584,6 +590,8 @@ class ParkingSpaceService extends BaseService $id, $oldValue['floor_id'] ); + // 同步删除模式关联车位 + ParkingPatternSpaceService::syncDeleteMapSpace($id); } DB::commit();