It would be easier to check the clock if it was saved in a separate table, something like
shop_working_hours (
shop_id int FK,
day_of_week int,
hours_open time,
hours close time,
PK (shop_id, day_of_week)
)
Thus, the query may look like this:
SELECT s.*
FROM shop s
INNER JOIN shop_working_hours h ON s.id = h.shop_id
WHERE
CASE
WHEN h.hours_close > h.hours_open THEN
h.day_of_week = DAYOFWEEK(NOW()) AND
CAST(NOW() AS time) >= h.hours_open AND CAST(NOW() AS time) < h.hours_close
ELSE
h.day_of_week = DAYOFWEEK(NOW() - 1) AND
CAST(NOW() AS time) >= h.hours_open OR CAST(NOW() AS time) < h.hours_close
END
, , , *_hours_open *_hours_close , shop, , , , , - :
SELECT s.*
FROM shop s
CROSS JOIN (
SELECT 1 AS day_of_week
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
UNION ALL SELECT 7
) h
WHERE
CASE h.day_of_week
WHEN 1 THEN
CASE
WHEN s.mon_hours_close > s.mon_hours_open THEN
h.day_of_week = DAYOFWEEK(NOW()) AND
CAST(NOW() AS time) >= s.mon_hours_open AND
CAST(NOW() AS time) < s.mon_hours_close
ELSE
h.day_of_week = DAYOFWEEK(NOW() - INTERVAL 1 DAY) AND
CAST(NOW() AS time) >= s.mon_hours_open OR
CAST(NOW() AS time) < s.mon_hours_close
END
WHEN 2 THEN
CASE
WHEN s.tue_hours_close > s.tue_hours_open THEN
…
END
…
END