From ac4c1044908678c0828b030c8c6b8dddcfbdd795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Tue, 20 Jan 2026 14:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=90=A5=E4=B8=9A=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/Room.php | 45 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/application/api/model/Room.php b/application/api/model/Room.php index 53d675a8..4d52cd7a 100644 --- a/application/api/model/Room.php +++ b/application/api/model/Room.php @@ -238,29 +238,28 @@ class Room extends Model $list = db::name('vs_room') ->field('id as room_id,room_number,user_id,room_name,room_cover,room_password,today_hot_value as hot_value,label_id,is_show_room,start_time,end_time') ->where($map) - // 营业时间判断(允许全天营业的房间) - ->where(function($query) use ($currentTime) { - // 全天营业的房间(start_time和end_time都为00:00:00) - $query->where(function($q) { - $q->where('start_time', '00:00:00') - ->where('end_time', '00:00:00'); - })->whereOr(function($q) use ($currentTime) { - // 正常时间限制的房间 - $q->where(function($q2) use ($currentTime) { - $q2->where('start_time', '<=', $currentTime) - ->where('end_time', '>=', $currentTime) - ->where('start_time', '<=', 'end_time') - ->where('start_time', '<>', '00:00:00'); // 排除全天营业 - })->whereOr(function($q2) use ($currentTime) { - // 跨天营业 - $q2->where('start_time', '>', 'end_time') - ->where(function($q3) use ($currentTime) { - $q3->where('start_time', '<=', $currentTime) - ->whereOr('end_time', '>=', $currentTime); - }); - }); - }); - }) + // 支持多种全天营业表示方式 + ->whereRaw("( + -- 方式1:开始和结束时间相同(全天营业) + start_time = end_time + + OR + + -- 方式2:传统的00:00:00表示全天营业 + (start_time = '00:00:00' AND end_time = '00:00:00') + + OR + + -- 方式3:正常营业时间段 + ( + start_time != end_time AND + ( + (start_time <= end_time AND CURTIME() BETWEEN start_time AND end_time) + OR + (start_time > end_time AND (CURTIME() >= start_time OR CURTIME() <= end_time)) + ) + ) + )") ->order('sort desc,hot_value desc,id asc') ->page($page, $page_limit) ->select();