Browse Source

结束活动优化,车位删除同步删除模式关联车位

master
wanghongjun 3 weeks ago
parent
commit
bea8bba97a
  1. 6
      app/Http/Controllers/Admin/EventCalendarController.php
  2. 3
      app/Services/EventCalendarService.php
  3. 16
      app/Services/ParkingPatternSpaceService.php
  4. 10
      app/Services/ParkingSpaceService.php

6
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')
);
}
}

3
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,

16
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'
);
}
}
}

10
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();

Loading…
Cancel
Save