From 8ea0669cb04f3a6ca9b37e3e40c862f060124602 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Tue, 14 Jul 2026 15:20:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=B4=BB=E5=8A=A8=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E7=AB=8B=E5=88=BB=E8=BF=90=E8=A1=8C=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Imports/EventCalendarImport.php | 11 ++++++++++ app/Services/EventCalendarService.php | 29 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) 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); + } + } }