SELECT companies name companies logo IFNULL FROM_UNIXTIME UNIX_TIMESTA

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
SELECT
companies.name,
companies.logo,
IFNULL(FROM_UNIXTIME(UNIX_TIMESTAMP(CURDATE()) + comp_worktime.stime, "%H:%i"), '00:00') as work_begin,
IFNULL(FROM_UNIXTIME(UNIX_TIMESTAMP(CURDATE()) + comp_worktime.stime + ROUND(3600 * comp_worktime.etime, 0), "%H:%i"), '00:00') as work_end,
IF (
IFNULL(MIN(minsum.sum), 0) > IFNULL(MIN(city_delivery.minsumm), 0),
IFNULL(MIN(minsum.sum), 0),
IFNULL(MIN(city_delivery.minsumm), 0)
) as sum_min,
IF (
IFNULL(MAX(minsum.sum), 0) < IFNULL(MAX(city_delivery.minsumm), 0),
IFNULL(MAX(minsum.sum), 0),
IFNULL(MAX(city_delivery.minsumm), 0)
) as sum_max,
companies.paycard,
IFNULL(CONVERT(GROUP_CONCAT(DISTINCT taxonomy_terms.id, ':', taxonomy_terms.name SEPARATOR ';') USING 'utf8'), '') as kitchen
FROM
companies LEFT JOIN comp_worktime ON (
comp_worktime.day = DATE_FORMAT(CURDATE(), '%w')
AND
UNIX_TIMESTAMP()
BETWEEN
UNIX_TIMESTAMP(CURDATE()) + comp_worktime.stime
AND
UNIX_TIMESTAMP(CURDATE()) + comp_worktime.stime + ROUND(3600 * comp_worktime.etime, 0)
AND
companies.id = comp_worktime.cid
) JOIN comp_tags ON (
comp_tags.cid = companies.id
) LEFT JOIN minsum ON (
minsum.group = comp_tags.tid
AND
minsum.company_id = companies.id
) JOIN city_delivery ON (
companies.id = city_delivery.cid
) JOIN districts ON (
city_delivery.district = districts.id
) JOIN goods_main ON (
goods_main.cid = comp_tags.cid
AND
goods_main.gid = comp_tags.tid
AND
goods_main.active > 0
) JOIN taxonomy_terms ON (
taxonomy_terms.id = goods_main.gid
)
WHERE
companies.id = 123
LIMIT
1