Explorar el Código

fleat: system edit products

igb hace 3 semanas
padre
commit
5940ccfef1

+ 67 - 0
system/ajax_get_product_specifications.php

@@ -0,0 +1,67 @@
+<?php
+require_once 'conn.php';
+require_once 'functions.php';
+
+checklogin("信息管理");
+// Get product ID
+$product_id = isset($_POST['product_id']) ? (int)$_POST['product_id'] : 0;
+
+if (empty($product_id)) {
+    echo '<p class="error-message" style="color:red;text-align:center;padding:10px;">无效的产品ID</p>';
+    exit;
+}
+
+// Get all specifications for this product
+$sql = "SELECT ps.id as spec_id, ps.spec_name, ps.sort_order, ps.spec_value, ps.spec_code, 
+        ps.min_order_quantity, p.id as product_id, p.unit  
+        FROM product_specifications ps
+        JOIN products p ON ps.product_id = p.id
+        WHERE ps.product_id = $product_id
+        ORDER BY ps.sort_order, ps.id";
+
+$result = $conn->query($sql);
+$html = '';
+
+if ($result && $result->num_rows > 0) {
+    while ($row = $result->fetch_assoc()) {
+        $product_id = $row['product_id'];
+        $spec_id = $row['spec_id'];
+        $spec_name = htmlspecialcharsFix($row['spec_name']);
+        $spec_value = htmlspecialcharsFix($row['spec_value'] ?? '');
+        $spec_code = htmlspecialcharsFix($row['spec_code'] ?? '');
+        $unit = htmlspecialcharsFix($row['unit']);
+        $min_qty = !empty($row['min_order_quantity']) ? intval($row['min_order_quantity']) : 1;
+        
+        // 构建完整的规格显示文本
+        $spec_display = $spec_name;
+        if (!empty($spec_value)) {
+            $spec_display .= ': ' . $spec_value;
+        }
+        if (!empty($spec_code)) {
+            $spec_display .= ' <span style="font-size:12px;color:#666;">(编码: ' . $spec_code . ')</span>';
+        }
+        
+        $html .= '<div class="specitem">
+            <div class="specdelete" title="删除此规格">✕</div>
+            <input type="hidden" name="spec_product_id[]" value="' . $product_id . '">
+            <input type="hidden" name="spec_id[]" value="' . $spec_id . '">
+            
+            <span class="spec-label">规格:</span>
+            <span class="spec-name">' . $spec_display . '</span>
+            
+            <span class="spec-label" style="margin-left:15px;">起订数量:</span>
+            <input type="number" class="spec-small-input" name="spec_moq[]" value="' . $min_qty . '" min="1">
+            <span class="unit">' . $unit . '</span>
+            
+            <span class="spec-label" style="margin-left:15px;">售价:</span>
+            <input type="text" class="spec-small-input" name="spec_price[]" value="" required min="0.01">
+            <span>RMB</span>
+        </div>';
+    }
+    echo $html;
+} else {
+    echo '<p style="padding:10px; background:#fff3f3; color:#d9534f; text-align:center; margin:10px 0; border-radius:4px;">该产品没有规格信息,请先在产品管理中添加规格</p>';
+}
+
+$conn->close();
+?> 

+ 53 - 0
system/ajax_search_products_for_spec.php

@@ -0,0 +1,53 @@
+<?php
+require_once 'conn.php';
+require_once 'functions.php';
+
+checklogin("信息管理");
+
+// Get search keyword
+$keyword = isset($_POST['keyword']) ? trim($_POST['keyword']) : '';
+
+if (empty($keyword) || strlen($keyword) < 2) {
+    echo '<li class="error-message" style="text-align:center; color:#666; padding:8px;">请输入至少2个字符</li>';
+    exit;
+}
+
+// Search for products matching the keyword
+$sql = "SELECT p.id, p.ProductName, p.unit, pc.name as category_name,
+        (SELECT COUNT(*) FROM product_specifications WHERE product_id = p.id) as spec_count
+        FROM products p
+        LEFT JOIN product_categories pc ON p.category_id = pc.id
+        WHERE p.ProductName LIKE '%".$conn->real_escape_string($keyword)."%'
+        HAVING spec_count > 0
+        ORDER BY p.ProductName
+        LIMIT 20";
+
+$result = $conn->query($sql);
+
+if ($result && $result->num_rows > 0) {
+    while ($row = $result->fetch_assoc()) {
+        $product_id = $row['id'];
+        $product_name = htmlspecialcharsFix($row['ProductName']);
+        $unit = htmlspecialcharsFix($row['unit'] ?? '');
+        $category_name = htmlspecialcharsFix($row['category_name'] ?? '');
+        $spec_count = (int)$row['spec_count'];
+        
+        $unit_display = !empty($unit) ? " <span style=\"color:#666;font-size:12px;\">($unit)</span>" : "";
+        $spec_display = " <span style=\"color:#0066cc;font-size:12px;\">($spec_count 个规格)</span>";
+        
+        echo '<li data-product-id="'.$product_id.'" data-product-name="'.$product_name.'" 
+                data-unit="'.$unit.'" data-category-name="'.$category_name.'">
+                <span class="product-name" style="font-weight:bold;">'.$product_name.'</span>'.$unit_display.$spec_display;
+        
+        if (!empty($category_name)) {
+            echo ' <br><span class="category-tag" style="color:#777;font-size:12px;font-style:italic;">分类: '.$category_name.'</span>';
+        }
+        
+        echo '</li>';
+    }
+} else {
+    echo '<li style="text-align:center; color:#666; padding:10px;">未找到相关产品或产品没有规格</li>';
+}
+
+$conn->close();
+?>