diff --git a/app/Services/EventCalendarService.php b/app/Services/EventCalendarService.php index 06461db..9c79c90 100644 --- a/app/Services/EventCalendarService.php +++ b/app/Services/EventCalendarService.php @@ -61,14 +61,17 @@ class EventCalendarService extends BaseService $end_time = get_datetime('datetime', strtotime($data['end_time'])); // 活动开始时间不能在已有活动时间内 - $where = [ - ['pattern_id', '=', $data['pattern_id']], - ['start_time', '>=', $start_time], - ['end_time', '<=', $start_time] - ]; - if (EventCalendar::query()->whereIn('status', [0, 1])->where($where) - ->exists() - ) { + $exists = EventCalendar::query()->whereIn('status', [0, 1])->where( + 'pattern_id', + $data['pattern_id'] + ) + ->where(function ($query) use ($start_time) { + $query->whereRaw( + "'{$start_time}' BETWEEN start_time AND end_time" + ); + }) + ->exists(); + if ($exists) { throw new Exception( __('service.event_calendar.pattern_exists') );