diff --git a/app/Imports/EventCalendarImport.php b/app/Imports/EventCalendarImport.php index 24f85e7..d33d546 100644 --- a/app/Imports/EventCalendarImport.php +++ b/app/Imports/EventCalendarImport.php @@ -5,6 +5,7 @@ namespace App\Imports; use App\Models\EventCalendar; use App\Models\ParkingPattern; use App\Services\AdminTranslationService; +use App\Services\EventCalendarService; use App\Services\OperationLogService; use Maatwebsite\Excel\Concerns\ToModel; @@ -14,12 +15,14 @@ class EventCalendarImport implements ToModel protected OperationLogService $logService; protected int $index = 0; protected array $error = []; + protected EventCalendarService $service; public function __construct(string $user_id) { $this->user_id = $user_id; $this->logService = new OperationLogService(); $this->logService->menuTitle = 'event_calendar'; + $this->service = new EventCalendarService($this->logService); } /** @@ -121,6 +124,14 @@ class EventCalendarImport implements ToModel $model = EventCalendar::query()->create($create); $this->logService->logCreated($model, 'event_calendar.import'); + + $newValue = $model->toArray(); + $this->service->nowChangeMode( + $save_start_time, + $save_end_time, + $newValue['id'], + $this->user_id + ); } protected function validateDate($datetime) diff --git a/app/Services/EventCalendarService.php b/app/Services/EventCalendarService.php index 0d9b55a..c9513c0 100644 --- a/app/Services/EventCalendarService.php +++ b/app/Services/EventCalendarService.php @@ -76,6 +76,13 @@ class EventCalendarService extends BaseService $this->logService->logCreated($model, 'event_calendar.create'); + $newValue = $model->toArray(); + $this->nowChangeMode( + $start_time, + $end_time, + $newValue['id'], + $user_id + ); DB::commit(); return $model; } catch (Exception $e) { @@ -155,6 +162,13 @@ class EventCalendarService extends BaseService 'event_calendar.update' ); + $newValue = $model->toArray(); + $this->nowChangeMode( + $newValue['start_time'], + $newValue['end_time'], + $newValue['id'], + $newValue['admin_user_id'] + ); DB::commit(); return $model; } catch (Exception $e) { @@ -216,6 +230,7 @@ class EventCalendarService extends BaseService } } + // 手动切换模式 public function changeModel($data, $user_id) { try { @@ -418,4 +433,18 @@ class EventCalendarService extends BaseService AdminNoticeService::addChangeModeNotice($pattern_id, $user_id); } } + + // 当前时间在活动时间内,立即运行模式 + public function nowChangeMode($start, $end, $id, $user_id) + { + $now_times = time(); + $start_times = strtotime($start); + $end_times = strtotime($end); + $exists = EventCalendar::query()->where('status', 1)->exists(); + if ($start_times <= $now_times && $end_times >= $now_times + && !$exists + ) { + $this->updateStatus($id, $user_id, 1, true); + } + } }