|
@@ -60,6 +60,62 @@ if (empty($items)) {
|
|
|
if ($isedit) {
|
|
|
|
|
|
//价格判断,不能低于指导价
|
|
|
+ $price_error = false;
|
|
|
+ $error_product_name = '';
|
|
|
+ $error_min_price = 0;
|
|
|
+ $error_current_price = 0;
|
|
|
+
|
|
|
+ foreach ($items as $item) {
|
|
|
+ if (empty($item['product_id'])) continue;
|
|
|
+
|
|
|
+ $product_id = (int)$item['product_id'];
|
|
|
+ $quantity = (int)$item['quantity'];
|
|
|
+ $unit_price = (float)$item['unit_price'];
|
|
|
+
|
|
|
+ // 查询产品名称,用于错误提示
|
|
|
+ $product_query = "SELECT ProductName FROM products WHERE id = $product_id";
|
|
|
+ $product_result = mysqli_query($conn, $product_query);
|
|
|
+
|
|
|
+ // 检查产品是否存在
|
|
|
+ if (mysqli_num_rows($product_result) === 0) {
|
|
|
+ echo "<script>alert(\"订单中包含不存在的产品(ID: {$product_id}),请检查订单数据\");history.back();</script>";
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ $product_row = mysqli_fetch_assoc($product_result);
|
|
|
+ $product_name = $product_row['ProductName'];
|
|
|
+
|
|
|
+ // 查询该产品在价格表中的最低价格要求
|
|
|
+ // 根据产品ID和数量查找最接近但不超过当前订单数量的价格记录
|
|
|
+ $price_query = "SELECT * FROM price
|
|
|
+ WHERE productId = $product_id
|
|
|
+ AND num <= $quantity
|
|
|
+ ORDER BY num DESC
|
|
|
+ LIMIT 1";
|
|
|
+
|
|
|
+ $price_result = mysqli_query($conn, $price_query);
|
|
|
+
|
|
|
+ if (mysqli_num_rows($price_result) > 0) {
|
|
|
+ $price_row = mysqli_fetch_assoc($price_result);
|
|
|
+ $min_price = (float)$price_row['price'];
|
|
|
+
|
|
|
+ // 如果单价低于指导价,标记错误
|
|
|
+ if ($unit_price < $min_price) {
|
|
|
+ $price_error = true;
|
|
|
+ $error_product_name = $product_name;
|
|
|
+ $error_min_price = $min_price;
|
|
|
+ $error_current_price = $unit_price;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果价格低于指导价,显示错误并返回
|
|
|
+ if ($price_error) {
|
|
|
+ $error_message = "产品 {$error_product_name} 的价格 ({$error_current_price}) 低于指导价 ({$error_min_price})";
|
|
|
+ echo "<script>alert(\"{$error_message}\");history.back();</script>";
|
|
|
+ exit;
|
|
|
+ }
|
|
|
|
|
|
// 更新订单基本信息
|
|
|
$sql = "UPDATE orders SET
|
|
@@ -115,9 +171,61 @@ if ($isedit) {
|
|
|
} else {
|
|
|
|
|
|
//价格判断,不能低于指导价
|
|
|
+ $price_error = false;
|
|
|
+ $error_product_name = '';
|
|
|
+ $error_min_price = 0;
|
|
|
+ $error_current_price = 0;
|
|
|
+
|
|
|
foreach ($items as $item) {
|
|
|
-
|
|
|
-
|
|
|
+ if (empty($item['product_id'])) continue;
|
|
|
+
|
|
|
+ $product_id = (int)$item['product_id'];
|
|
|
+ $quantity = (int)$item['quantity'];
|
|
|
+ $unit_price = (float)$item['unit_price'];
|
|
|
+
|
|
|
+ // 查询产品名称,用于错误提示
|
|
|
+ $product_query = "SELECT ProductName FROM products WHERE id = $product_id";
|
|
|
+ $product_result = mysqli_query($conn, $product_query);
|
|
|
+
|
|
|
+ // 检查产品是否存在
|
|
|
+ if (mysqli_num_rows($product_result) === 0) {
|
|
|
+ echo "<script>alert(\"订单中包含不存在的产品(ID: {$product_id}),请检查订单数据\");history.back();</script>";
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ $product_row = mysqli_fetch_assoc($product_result);
|
|
|
+ $product_name = $product_row['ProductName'];
|
|
|
+
|
|
|
+ // 查询该产品在价格表中的最低价格要求
|
|
|
+ // 根据产品ID和数量查找最接近但不超过当前订单数量的价格记录
|
|
|
+ $price_query = "SELECT * FROM price
|
|
|
+ WHERE productId = $product_id
|
|
|
+ AND num <= $quantity
|
|
|
+ ORDER BY num DESC
|
|
|
+ LIMIT 1";
|
|
|
+
|
|
|
+ $price_result = mysqli_query($conn, $price_query);
|
|
|
+
|
|
|
+ if (mysqli_num_rows($price_result) > 0) {
|
|
|
+ $price_row = mysqli_fetch_assoc($price_result);
|
|
|
+ $min_price = (float)$price_row['price'];
|
|
|
+
|
|
|
+ // 如果单价低于指导价,标记错误
|
|
|
+ if ($unit_price < $min_price) {
|
|
|
+ $price_error = true;
|
|
|
+ $error_product_name = $product_name;
|
|
|
+ $error_min_price = $min_price;
|
|
|
+ $error_current_price = $unit_price;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果价格低于指导价,显示错误并返回
|
|
|
+ if ($price_error) {
|
|
|
+ $error_message = "产品 {$error_product_name} 的价格 ({$error_current_price}) 低于指导价 ({$error_min_price})";
|
|
|
+ echo "<script>alert(\"{$error_message}\");history.back();</script>";
|
|
|
+ exit;
|
|
|
}
|
|
|
|
|
|
// 创建新订单
|