Bläddra i källkod

fleat: order edit update

igb 3 veckor sedan
förälder
incheckning
1bb59db532
2 ändrade filer med 243 tillägg och 74 borttagningar
  1. 9 6
      order_details.php
  2. 234 68
      system/country.php

+ 9 - 6
order_details.php

@@ -293,14 +293,17 @@ if (!empty($id) && is_numeric($id)) {
         </div>
     </div>
 
-    <?php if (!empty($order['notes'])): ?>
-        <div class="notes-section">
-            <h2>订单备注</h2>
-            <div>
+    <div class="notes-section">
+        <h2>订单备注</h2>
+        <div>
+            <?php if (!empty($order['notes'])): ?>
                 <p><?= nl2br(htmlspecialcharsFix($order['notes'])) ?></p>
-            </div>
+            <?php else: ?>
+                <p><em>无备注</em></p>
+            <?php endif; ?>
         </div>
-    <?php endif; ?>
+    </div>
+
 </div>
 </body>
 </html>

+ 234 - 68
system/country.php

@@ -13,7 +13,107 @@ checklogin("信息管理");
 <script language="javascript" src="js/jquery-1.7.2.min.js"></script>
 <script type="text/javascript" src="js/js.js"></script>
 <script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
-<script type="text/javascript" src="js/Searchproduct.js"></script>
+<script type="text/javascript" src="js/NewSearchproduct.js"></script>
+<style>
+    /* Styles for specification section */
+    .specifications {
+        margin-bottom: 10px;
+        width: 100%;
+    }
+    .specitem {
+        margin-bottom: 8px;
+        padding: 8px 10px;
+        border: 1px solid #e0e0e0;
+        border-radius: 4px;
+        clear: both;
+        overflow: hidden;
+    }
+    .spec-label {
+        display: inline-block;
+        margin-right: 5px;
+        font-weight: normal;
+    }
+    .spec-input {
+        width: 120px;
+        padding: 4px;
+        margin-right: 10px;
+        border: 1px solid #ccc;
+        border-radius: 3px;
+    }
+    .spec-small-input {
+        width: 80px;
+        padding: 4px;
+        margin-right: 10px;
+        border: 1px solid #ccc;
+        border-radius: 3px;
+    }
+    .required {
+        color: red;
+        margin-left: 2px;
+    }
+    .specdelete {
+        float: right;
+        cursor: pointer;
+        color: red;
+        font-weight: bold;
+        margin-right: 5px;
+    }
+    #specificationlist {
+        max-height: 300px;
+        overflow-y: auto;
+        border: 1px solid #ddd;
+        margin-top: 5px;
+        display: none;
+        background-color: white;
+        z-index: 999;
+        position: absolute;
+        width: 100%;
+        left: 0;
+        right: 0;
+        box-shadow: 0 3px 8px rgba(0,0,0,0.25);
+        box-sizing: border-box;
+    }
+    #specificationlist ul {
+        list-style: none;
+        padding: 0;
+        margin: 0;
+    }
+    #specificationlist li {
+        padding: 8px 10px;
+        cursor: pointer;
+        border-bottom: 1px solid #eee;
+    }
+    #specificationlist li:hover {
+        background-color: #f0f0f0;
+    }
+    .product-header {
+        margin-top: 10px;
+        padding: 8px;
+        background: #f5f5f5;
+        font-weight: bold;
+        border-radius: 4px;
+        border: 1px solid #ddd;
+    }
+    /* 增加搜索相关样式 */
+    .productinput {
+        position: relative;
+        width: 100%;
+        max-width: 90%;
+    }
+    .fastsearch {
+        width: 100%;
+        padding: 8px;
+        border: 1px solid #ddd;
+        border-radius: 4px;
+        box-sizing: border-box;
+    }
+    .category-tag {
+        color: #777;
+        font-size: 12px;
+        font-style: italic;
+        margin-left: 5px;
+    }
+</style>
 </head>
 <body>
 <div id="man_zone">
@@ -27,11 +127,59 @@ if ($act == "save") {
         $isedit = true;
     }
 
-    $productIds = $_POST['productId'] ?? [];
-    $nums = $_POST['num'] ?? [];
-    $prices = $_POST['price'] ?? [];
     $countryName = $_POST['countryName'] ?? '';
     $countryCode = $_POST['countryCode'] ?? '';
+    
+    // 验证国家和区号不能为空
+    if (trim($countryName) === '') {
+        echo "<script>alert('错误:国家名称不能为空!');history.back();</script>";
+        exit;
+    }
+    
+    if (trim($countryCode) === '') {
+        echo "<script>alert('错误:区号不能为空!');history.back();</script>";
+        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 "<script>alert('错误:产品 [".$zeroProductName."] 的规格 [".$zeroSpecName."] 售价不能为0或空白!');history.back();</script>";
+        exit;
+    }
 
     if ($isedit) {
         $sql = "UPDATE country SET 
@@ -41,19 +189,21 @@ if ($act == "save") {
             WHERE id = $id";
         $conn->query($sql);
         
-        // Delete all existing prices for this area
-        $conn->query("DELETE FROM price WHERE AreaId=$id");
+        // 删除该国家的所有产品规格价格
+        $conn->query("DELETE FROM product_country_price WHERE country_id=$id");
         
-        // Only process if we have product IDs
-        if (!empty($productIds) && is_array($productIds)) {
-            for ($i = 0; $i < count($productIds); $i++) {
-                if (isset($nums[$i]) && isset($prices[$i])) {
-                    $numVal = empty($nums[$i]) ? 0 : floatval($nums[$i]);
-                    $priceVal = empty($prices[$i]) ? 0 : $conn->real_escape_string($prices[$i]);
-                    $productId = intval($productIds[$i]);
+        // 处理规格价格数据
+        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) {
-                        $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES ($productId, $id, $numVal, '$priceVal')";
+                    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);
                     }
                 }
@@ -75,16 +225,18 @@ if ($act == "save") {
         $conn->query($sql);
         $id = $conn->insert_id;
         
-        // Only process if we have product IDs
-        if (!empty($productIds) && is_array($productIds)) {
-            for ($i = 0; $i < count($productIds); $i++) {
-                if (isset($nums[$i]) && isset($prices[$i])) {
-                    $numVal = empty($nums[$i]) ? 0 : floatval($nums[$i]);
-                    $priceVal = empty($prices[$i]) ? 0 : $conn->real_escape_string($prices[$i]);
-                    $productId = intval($productIds[$i]);
+        // 处理规格价格数据
+        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) {
-                        $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES ($productId, $id, $numVal, '$priceVal')";
+                    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);
                     }
                 }
@@ -128,78 +280,86 @@ if ($act == "add" || $act == "edit") {
         <tbody>
             <tr>
                 <th width="8%">国家</th>
-                <td><input type="text" id="countryName" name="countryName" value="<?= htmlspecialcharsFix($countryName) ?>" class="txt1" /><input type="hidden" name="id" value="<?= $id ?>" /></td>
+                <td><input type="text" id="countryName" name="countryName" value="<?= htmlspecialcharsFix($countryName) ?>" class="txt1" required /><input type="hidden" name="id" value="<?= $id ?>" /></td>
             </tr>
             <tr>
                 <th width="8%">区号</th>
-                <td><input type="text" id="countryCode" name="countryCode" value="<?= htmlspecialcharsFix($countryCode) ?>" class="txt1" /></td>
+                <td><input type="text" id="countryCode" name="countryCode" value="<?= htmlspecialcharsFix($countryCode) ?>" class="txt1" required /></td>
             </tr>
             <tr>
                 <th width="8%">更新日期</th>
                 <td><?= $addtime ?></td>
             </tr>           
+            <!-- 新增: 产品规格价格管理 -->
             <tr>
-                <th width="8%">售价管理</th>
+                <th width="8%">规格价格管理</th>
                 <td>
-                <div class="prowapper">             
+                <div class="specifications">
                     <?php
                     if (!empty($id) && $id > 0) {
-                        $sql = "SELECT p.id, p.ProductName, p.ProductImg, p.unit, p.category_id, pc.name as categoryName 
-                                FROM products p 
-                                LEFT JOIN product_categories pc ON p.category_id = pc.id 
-                                WHERE p.id IN (SELECT productId FROM price WHERE AreaId = $id)";
+                        // 只获取已经添加过的规格价格,而不是所有规格
+                        $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()) {
-                                // 准备分类显示
-                                $categoryDisplay = !empty($row['categoryName']) ? ' <span style="color:#888;font-size:12px;">['.$row['categoryName'].']</span>' : '';
+                                // 显示产品名称,每个产品只显示一次
+                                if ($current_product != $row['id']) {
+                                    $current_product = $row['id'];
+                                    $categoryDisplay = !empty($row['categoryName']) ? ' <span style="color:#888;font-size:12px;">['.$row['categoryName'].']</span>' : '';
+                                    echo '<div class="product-header" style="margin-top:10px;padding:5px;background:#f5f5f5;font-weight:bold;">
+                                        '.htmlspecialcharsFix($row['ProductName']).$categoryDisplay.'
+                                    </div>';
+                                }
+                                
+                                // 设置默认值
+                                $price = isset($row['price']) ? $row['price'] : '';
+                                $moq = isset($row['min_order_quantity']) ? $row['min_order_quantity'] : '1';
                             ?>
-                                <div class="proitem">
-                                    <div class="prodelet"></div>
-                                    <div class="proname"><?= htmlspecialcharsFix($row['ProductName']) ?><?= $categoryDisplay ?></div>
-                                    <div class="propic"><img src="<?= htmlspecialcharsFix($row['ProductImg']) ?>"></div>      
-                                    <div class="proprice">
-                                        <?php
-                                        $sql2 = "SELECT num, price FROM price WHERE productId = {$row['id']} AND AreaId = $id ORDER BY num ASC";
-                                        $result2 = $conn->query($sql2);
-                                        while ($row2 = $result2->fetch_assoc()) {
-                                        ?>
-                                            <div class="priceitem">
-                                                <input type="hidden" name="productId[]" value="<?= $row['id'] ?>">
-                                                <label>≥</label>
-                                                <input type="number" autocomplete="off" class="txt3 num" name="num[]" value="<?= $row2['num'] ?>">
-                                                <label class='unit'><?= htmlspecialcharsFix($row['unit']) ?></label>
-                                                <label>售价</label>
-                                                <input type="text" class="txt3 price" autocomplete="off" name="price[]" value="<?= $row2['price'] ?>">
-                                                <label>RMB</label>
-                                                <span class="additem"></span>
-                                                <span class="delitem"></span>
-                                                <span class="note"></span>
-                                            </div>
-                                        <?php
-                                        }
-                                        ?>
-                                    </div>      
+                                <div class="specitem">
+                                    <div class="specdelete" style="float:right;cursor:pointer;color:red;">✕</div>
+                                    <input type="hidden" name="spec_product_id[]" value="<?= $row['id'] ?>">
+                                    <input type="hidden" name="spec_id[]" value="<?= $row['specification_id'] ?>">
+                                    
+                                    <span class="spec-label">规格:</span>
+                                    <span class="spec-name"><?= htmlspecialcharsFix($row['spec_name']) ?></span>
+                                    
+                                    <span class="spec-label" style="margin-left:15px;">起订数量:</span>
+                                    <input type="number" class="spec-small-input" name="spec_moq[]" value="<?= $moq ?>">
+                                    <span class="unit"><?= htmlspecialcharsFix($row['unit']) ?></span>
+                                    
+                                    <span class="spec-label" style="margin-left:15px;">售价:</span>
+                                    <input type="text" class="spec-small-input" name="spec_price[]" value="<?= $price ?>" required min="0.01">
+                                    <span>RMB</span>
                                 </div>
                             <?php
                             }
                         } else {
-                            echo "<p>该地区暂无产品价格设置</p>";
+                            echo "<p>该地区暂无产品规格价格设置,请使用下方的搜索功能添加</p>";
                         }
                     } else {
-                        echo "<p>添加产品后可管理产品价格</p>";
+                        echo "<p>添加产品后可管理产品规格价格</p>";
                     }
                     ?>
-                </div>                  
+                </div>
                 </td>
             </tr>
             <tr>
-                <th width="8%">产品添加</th>
-                <td class="productinput">
-                    <input type="text" id="productSearch" class="fastsearch">
-                    <div id="productlist" class="productlist"><ul></ul></div>
+                <th width="8%">添加规格价格</th>
+                <td>
+                    <div class="productinput">
+                        <input type="text" id="specificationSearch" class="fastsearch" placeholder="搜索产品">
+                        <div id="specificationlist" class="productlist"><ul></ul></div>
+                    </div>
                 </td>
-            </tr>          
+            </tr>
             <tr>
                 <th></th>
                 <td>
@@ -228,6 +388,10 @@ if ($act == "postchk") {
         $ids = implode(',', array_map('intval', $_POST['chkbox']));
         $sql = "DELETE FROM country WHERE id IN ($ids)";
         $conn->query($sql);
+        
+        // 删除相关的产品规格价格
+        $sql = "DELETE FROM product_country_price WHERE country_id IN ($ids)";
+        $conn->query($sql);
     }
     
     header("Location: ?Keys=$keys&Ord=$ord&Page=$page");
@@ -389,6 +553,8 @@ $hrefstr = "?keys=$keys";
 $('.click-open-iframe').galpop({
     contentType: 'iframe',
 });
+
+// 规格搜索和添加功能已移至 js/NewSearchproduct.js
 </script>
 </body>
 </html>