alert('错误:国家名称不能为空!');history.back();"; exit; } if (trim($countryCode) === '') { echo ""; exit; } // 规格相关数据 $specProductIds = $_POST['spec_product_id'] ?? []; $specIds = $_POST['spec_id'] ?? []; $specPrices = $_POST['spec_price'] ?? []; $specMoqs = $_POST['spec_moq'] ?? []; // 验证售价不能为0 $hasZeroPrice = false; $zeroProductName = ''; $zeroSpecName = ''; if (!empty($specProductIds) && !empty($specIds) && is_array($specProductIds) && is_array($specIds)) { for ($i = 0; $i < count($specProductIds); $i++) { if (isset($specPrices[$i])) { $price = trim($specPrices[$i]); if ($price === '' || $price === '0' || floatval($price) <= 0) { // 查询产品和规格名称 $productId = intval($specProductIds[$i]); $specId = intval($specIds[$i]); $nameQuery = "SELECT p.ProductName, ps.spec_name FROM products p JOIN product_specifications ps ON p.id = ps.product_id WHERE p.id = $productId AND ps.id = $specId"; $nameResult = $conn->query($nameQuery); if ($nameResult && $nameRow = $nameResult->fetch_assoc()) { $zeroProductName = $nameRow['ProductName']; $zeroSpecName = $nameRow['spec_name']; } $hasZeroPrice = true; break; } } } } if ($hasZeroPrice) { echo ""; exit; } if ($isedit) { $sql = "UPDATE country SET countryName = '" . $conn->real_escape_string($countryName) . "', countryCode = '" . $conn->real_escape_string($countryCode) . "', addtime = NOW() WHERE id = $id"; $conn->query($sql); // 删除该国家的所有产品规格价格 $conn->query("DELETE FROM product_country_price WHERE country_id=$id"); // 处理规格价格数据 if (!empty($specProductIds) && !empty($specIds) && is_array($specProductIds) && is_array($specIds)) { for ($i = 0; $i < count($specProductIds); $i++) { if (isset($specPrices[$i]) && isset($specMoqs[$i]) && isset($specIds[$i])) { $productId = intval($specProductIds[$i]); $specId = intval($specIds[$i]); $specPrice = $conn->real_escape_string($specPrices[$i]); $specMoq = empty($specMoqs[$i]) ? 1 : intval($specMoqs[$i]); if ($productId > 0 && $specId > 0) { $sql = "INSERT INTO product_country_price (country_id, product_id, specification_id, price, min_order_quantity, addtime) VALUES ($id, $productId, $specId, '$specPrice', $specMoq, NOW())"; $conn->query($sql); } } } } $page = $_GET['Page'] ?? ''; $keys = urlencode($_GET['Keys'] ?? ''); $ord = urlencode($_GET['Ord'] ?? ''); header("Location: ?keys=$keys&Ord=$ord&Page=$page"); exit; } else { // For new country, include countryName and countryCode $sql = "INSERT INTO country (countryName, countryCode, addtime) VALUES ( '" . $conn->real_escape_string($countryName) . "', '" . $conn->real_escape_string($countryCode) . "', NOW() )"; $conn->query($sql); $id = $conn->insert_id; // 处理规格价格数据 if (!empty($specProductIds) && !empty($specIds) && is_array($specProductIds) && is_array($specIds)) { for ($i = 0; $i < count($specProductIds); $i++) { if (isset($specPrices[$i]) && isset($specMoqs[$i]) && isset($specIds[$i])) { $productId = intval($specProductIds[$i]); $specId = intval($specIds[$i]); $specPrice = $conn->real_escape_string($specPrices[$i]); $specMoq = empty($specMoqs[$i]) ? 1 : intval($specMoqs[$i]); if ($productId > 0 && $specId > 0) { $sql = "INSERT INTO product_country_price (country_id, product_id, specification_id, price, min_order_quantity, addtime) VALUES ($id, $productId, $specId, '$specPrice', $specMoq, NOW())"; $conn->query($sql); } } } } header("Location: ?"); exit; } } if ($act == "add" || $act == "edit") { $id = $_GET['id'] ?? ''; $isedit = false; $countryCode = ''; $countryName = ''; $addtime = ''; if ($id != "" && is_numeric($id)) { $isedit = true; $sql = "SELECT * FROM country WHERE id = $id"; $result = $conn->query($sql); $row = $result->fetch_assoc(); if ($row) { $countryCode = $row['countryCode']; $countryName = $row['countryName']; $addtime = $row['addtime']; } else { $isedit = false; } } $page = $_GET['Page'] ?? ''; $keys = urlencode($_GET['Keys'] ?? ''); $ord = urlencode($_GET['Ord'] ?? ''); $hrefstr = "?keys=$keys&Ord=$ord&Page=$page"; ?>
国家
区号
更新日期
规格价格管理
0) { // 只获取已经添加过的规格价格,而不是所有规格 $sql = "SELECT p.id, p.ProductName, p.unit, ps.id as specification_id, ps.spec_name, pcp.price, pcp.min_order_quantity, pc.name as categoryName FROM product_country_price pcp JOIN products p ON pcp.product_id = p.id JOIN product_specifications ps ON pcp.specification_id = ps.id LEFT JOIN product_categories pc ON p.category_id = pc.id WHERE pcp.country_id = $id ORDER BY p.ProductName, ps.sort_order"; $result = $conn->query($sql); if ($result && $result->num_rows > 0) { $current_product = 0; while ($row = $result->fetch_assoc()) { // 显示产品名称,每个产品只显示一次 if ($current_product != $row['id']) { $current_product = $row['id']; $categoryDisplay = !empty($row['categoryName']) ? ' ['.$row['categoryName'].']' : ''; echo '
'.htmlspecialcharsFix($row['ProductName']).$categoryDisplay.'
'; } // 设置默认值 $price = isset($row['price']) ? $row['price'] : ''; $moq = isset($row['min_order_quantity']) ? $row['min_order_quantity'] : '1'; ?>
规格: 起订数量: 售价: RMB
该地区暂无产品规格价格设置,请使用下方的搜索功能添加

"; } } else { echo "

添加产品后可管理产品规格价格

"; } ?>
添加规格价格
    query($sql); // 删除相关的产品规格价格 $sql = "DELETE FROM product_country_price WHERE country_id IN ($ids)"; $conn->query($sql); } header("Location: ?Keys=$keys&Ord=$ord&Page=$page"); exit; } // Main list view $keys = $_GET['Keys'] ?? ''; $keyscode = $keys; $ord = $_GET['Ord'] ?? ''; $page = $_GET['Page'] ?? ''; $sql = "SELECT * FROM country WHERE countryName LIKE '%$keyscode%' OR countryCode LIKE '%$keyscode%' ORDER BY id DESC"; $result = $conn->query($sql); $results = []; while($row = $result->fetch_assoc()) { $results[] = $row; } $totalRecords = count($results); $pageSize = 20; $totalPages = ceil($totalRecords / $pageSize); if ($page == "") $page = 1; if ($page == "end") $page = $totalPages; if (!is_numeric($page) || $page < 1) $page = 1; $page = (int)$page; if ($page > $totalPages) $page = $totalPages; $start = ($page - 1) * $pageSize; $currentPageRecords = array_slice($results, $start, $pageSize); $keys = urlencode($keys); $ord = urlencode($ord); $hrefstr = "?keys=$keys"; ?>
    序号 国家 区号 操作
    修改
    Sorry,当前暂无信息
    Sorry,没有找到""相关的信息,点击返回
    1) { $pageName = "?Keys=$keys&Ord=$ord&"; $pagelen = 3; if ($page > 1) { echo "首页"; echo "上一页"; } if ($pagelen * 2 + 1 >= $totalPages) { $startPage = 1; $endPage = $totalPages; } else { if ($page <= $pagelen + 1) { $startPage = 1; $endPage = $pagelen * 2 + 1; } else { $startPage = $page - $pagelen; $endPage = $page + $pagelen; } if ($page + $pagelen > $totalPages) { $startPage = $totalPages - $pagelen * 2; $endPage = $totalPages; } } for ($i = $startPage; $i <= $endPage; $i++) { if ($i == $page) { echo "$i"; } else { echo "$i"; } } if ($page < $totalPages) { if ($totalPages - $page > $pagelen) { echo "...$totalPages"; } echo "下一页"; echo "尾页"; } echo ""; } ?>