|
@@ -56,6 +56,49 @@ if (empty($items)) {
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
+// 检查客户国家和产品销售限制
|
|
|
+$customer_query = "SELECT cs_country FROM customer WHERE id = $customer_id LIMIT 1";
|
|
|
+$customer_result = mysqli_query($conn, $customer_query);
|
|
|
+
|
|
|
+if ($customer_result && mysqli_num_rows($customer_result) > 0) {
|
|
|
+ $customer_data = mysqli_fetch_assoc($customer_result);
|
|
|
+ $customer_country = $customer_data['cs_country'];
|
|
|
+
|
|
|
+ if (!empty($customer_country)) {
|
|
|
+ $restricted_products = [];
|
|
|
+
|
|
|
+ foreach ($items as $item) {
|
|
|
+ if (empty($item['product_id'])) continue;
|
|
|
+
|
|
|
+ $product_id = (int)$item['product_id'];
|
|
|
+
|
|
|
+ // 获取产品详情,包括nosale字段
|
|
|
+ $product_query = "SELECT ProductName, nosale FROM products WHERE id = $product_id LIMIT 1";
|
|
|
+ $product_result = mysqli_query($conn, $product_query);
|
|
|
+
|
|
|
+ if ($product_result && mysqli_num_rows($product_result) > 0) {
|
|
|
+ $product_data = mysqli_fetch_assoc($product_result);
|
|
|
+ $nosale_countries = $product_data['nosale'];
|
|
|
+
|
|
|
+ // 检查客户所在国家是否在销售限制列表中
|
|
|
+ if (!empty($nosale_countries)) {
|
|
|
+ $restricted_countries = explode(',', $nosale_countries);
|
|
|
+ if (in_array($customer_country, $restricted_countries)) {
|
|
|
+ $restricted_products[] = $product_data['ProductName'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有限制销售的产品,显示错误并返回
|
|
|
+ if (!empty($restricted_products)) {
|
|
|
+ $restricted_product_names = implode('、', $restricted_products);
|
|
|
+ echo "<script>alert('以下产品不能销售给所选客户所在的国家/地区: {$restricted_product_names}');history.back();</script>";
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 处理保存
|
|
|
if ($isedit) {
|
|
|
|