时间订单清单

我正在下订单。在某些时段(10:00-11:00、11:30-12:30、13:00-14:000),只能订购一定数量的物品。如果达到最大数量,则应禁用订购选项。我通过ajax列出项目,以便在时间变化时根据可用性进行加载。 我已经尝试了很多方法,但是不能。

产品

+--+------+--------+-----+-----+
|id|name  |quantity|input|price|
+--+------+--------+-----+-----+
|3 |Item 1|2       |item1|500  |
|4 |Item 2|4       |item2|1000 |
+--+------+--------+-----+-----+

命令

+--+------+----------+----------+--------+----------+---------+-----+-----+
|id|number|date      |time_start|time_end|first_name|last_name|email|phone|
+--+------+----------+----------+--------+----------+---------+-----+-----+
|1 |0     |2020-05-18|11:30:00  |12:30:00|          |         |     |     |
|2 |0     |2020-05-18|13:00:00  |14:00:00|          |         |     |     |
|3 |0     |2020-05-19|11:30:00  |12:30:00|          |         |     |     |
|4 |0     |2020-05-19|13:00:00  |14:00:00|          |         |     |     |
+--+------+----------+----------+--------+----------+---------+-----+-----+

order_items

+--+--------+----------+------------+--------+
|id|order_id|product_id|product_name|quantity|
+--+--------+----------+------------+--------+
|1 |1       |3         |Item 1      |1       |
|2 |2       |4         |Item 2      |1       |
|3 |3       |3         |Item 1      |2       |
|4 |4       |4         |Item 2      |4       |
+--+--------+----------+------------+--------+

SELECT i.id as id, i.product_id as product_id, SUM(ifnull(i.quantity, 0)) as quantity_order, p.name
as name, p.price as price, p.quantity as quantity,
p.input as input, o.time_start as time_start, o.time_end as time_end
FROM product p
LEFT JOIN order_items i ON p.id = i.product_id
LEFT JOIN orders o on o.id = i.order_id
WHERE (`o`.`date` = '2020-05-18') AND (`o`.`time_start` = '11:30:00') AND (`o`.`time_end` = '12:30:00') or
i.product_id IS NULL or i.id 
GROUP BY p.id, o.time_start, o.time_end

foreach ($products as $product) {
  if($product->quantity <= $product->quantity_order && $product->time_start == $time->time_start) {
  echo $product->name . "out of stock";
 } else {
      echo $product->name . "<input type="number">";
        }
}
评论