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 * @param string $id
* @return JsonResponse * @return JsonResponse
* @throws ValidationException * @throws ValidationException
* @throws CustomException
*/ */
public function end(string $id): JsonResponse public function end(string $id): JsonResponse
{ {
@ -323,12 +324,11 @@ class EventCalendarController extends BaseController
null, null,
__('exception.event_calendar.end_succeeded') __('exception.event_calendar.end_succeeded')
); );
} catch (ValidationException $e) { } catch (ValidationException|CustomException $e) {
throw $e; throw $e;
} catch (Exception $e) { } catch (Exception $e) {
return $this->responseService->systemError( return $this->responseService->systemError(
__('exception.event_calendar.end_failed') . ':' __('exception.event_calendar.end_failed')
. $e->getMessage()
); );
} }
} }

3
app/Services/EventCalendarService.php

@ -2,6 +2,7 @@
namespace App\Services; namespace App\Services;
use App\Exceptions\CustomException;
use App\Models\EventCalendar; use App\Models\EventCalendar;
use App\Models\ParkingPattern; use App\Models\ParkingPattern;
use App\Models\ParkingPatternSpace; use App\Models\ParkingPatternSpace;
@ -191,7 +192,7 @@ class EventCalendarService extends BaseService
$model = EventCalendar::query()->findOrFail($id); $model = EventCalendar::query()->findOrFail($id);
$oldValues = $model->toArray(); $oldValues = $model->toArray();
if ($model['status'] != 1) { if ($model['status'] != 1) {
throw new Exception(__('service.event_calendar.error_end')); throw new CustomException(__('service.event_calendar.error_end'));
} }
$update = [ $update = [
'status' => 2, 'status' => 2,

16
app/Services/ParkingPatternSpaceService.php

@ -164,4 +164,20 @@ class ParkingPatternSpaceService extends BaseService
} }
return []; 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; return;
} }
} }
$model = ParkingSpace::query()->findOrFail($id); $model = ParkingSpace::query()->find($id);
if (!$model) {
return;
}
$oldValues = $model->toArray(); $oldValues = $model->toArray();
// 相同不更新 // 相同不更新
if ($oldValues['space_type_id'] == $type_id) { if ($oldValues['space_type_id'] == $type_id) {
@ -553,6 +556,9 @@ class ParkingSpaceService extends BaseService
$oldValue['floor_id'] $oldValue['floor_id']
); );
// 同步删除模式关联车位
ParkingPatternSpaceService::syncDeleteMapSpace($id);
DB::commit(); DB::commit();
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
@ -584,6 +590,8 @@ class ParkingSpaceService extends BaseService
$id, $id,
$oldValue['floor_id'] $oldValue['floor_id']
); );
// 同步删除模式关联车位
ParkingPatternSpaceService::syncDeleteMapSpace($id);
} }
DB::commit(); DB::commit();

Loading…
Cancel
Save