gpt4 book ai didi

php - 下单管理逻辑

转载 作者:搜寻专家 更新时间:2023-10-31 20:57:14 24 4
gpt4 key购买 nike

我目前正在尝试形成我下订单的逻辑,如果订单与当前库存相加时超出了容量,则会出现相应的消息。此外,如果有传入订单,则在添加新订单时,它们不能超过与未决传入订单以及当前可用库存相加的容量。但是,我的问题是,无论我投入多少,它都会一直显示我的“下订单库存量已超出容量”。验证消息。我围绕这个功能的逻辑是错误的吗?谢谢。

if(isset($_POST['addBtn'])){  
$brand = $_POST['brand'];
$modelName = $_POST['model_name'];
$session = $_SESSION['username'];
$station = 'At Factory';
$progress = 'Awaiting';
$status = 'Awaiting';
$handler = 'Awaiting';
$request = '-';
$stock = $_POST['stock'];
$incoming = '0';
$date = date('Y-m-j H:i:s', time());
$stock = $_POST['stock'];
$incoming = '0';


$sql2 = "SELECT o.stock,m.current,m.capacity FROM orders o
INNER JOIN models m ON o.model_id=m.model_id
WHERE o.incoming = 0";
$result2 = $conn->query($sql2);
if(!$result2) die($conn->error);
$rows = $result2->num_rows;

$stok = $rows['stock'];
$cu = $rows['current'];
$ca = $rows['capacity'];

if(($stock+$cu)>$ca){
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong id="alert2">Error! </strong>Placed order stock amount has exceeded capacity.
</div>
<?php
}elseif(($stok+$stock+$cu)>$ca){
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong id="alert2">Error! </strong>Pending incoming stocks has exceeded capacity.
</div>
<?php
}else{

$query = "INSERT INTO orders(brand,model_id,station,progress,status,editor,time_ordered,admin,request) VALUES ('".$brand."','".$modelName."','".$station."','".$progress."','".$status."','".$handler."','".$date."','".$session."','".$request."')";
}
}

最佳答案

我相信您的 SQL 中需要另一个 WHERE 子句来根据您的模型选择订单。

例子:

$sql2 = "SELECT SUM(o.stock) as stock_sum, m.current, m.capacity FROM orders o
INNER JOIN models m ON o.model_id=m.model_id
WHERE o.incoming = 0 AND m.model_id = $modelName";

但是如果没有订单可能会出错。例如 $cu 和 $ca 可能是空的,因为您是通过加入订单和模型来获得这些值的。

一个很好的建议是使用单独的 SQL 来检索股票总和,并使用另一个 SQL 来检索模型详细信息。

关于php - 下单管理逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55585077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com