9 Commits 094661c790 ... aa3d1b471c

Author SHA1 Message Date
  igb aa3d1b471c fleat: products admin rebate 1 week ago
  igb 0d7cc7f428 fleat: customer add 1 week ago
  igb f3a317a107 fleat: customer add 1 week ago
  igb 9762d5ba71 fleat: customer add 1 week ago
  igb bd27786bc7 fleat: customer add relationship 1 week ago
  igb b179089165 fleat: customer add relationship 1 week ago
  igb 23a8b3b085 fleat: update order 1 week ago
  igb 3369d9366a fleat: update text 1 week ago
  igb e7f37472ea fleat: update add product 1 week ago
16 changed files with 1090 additions and 715 deletions
  1. 12 8
      customerAdd.php
  2. 610 33
      customerEdit.php
  3. 27 4
      customerSave.php
  4. 50 0
      delete_relationship.php
  5. 54 0
      get_relationship.php
  6. 2 2
      order.php
  7. 49 229
      order_add.php
  8. 1 1
      order_details.php
  9. 75 252
      order_edit.php
  10. 10 156
      order_save.php
  11. 1 1
      panel.php
  12. 109 0
      save_relationship.php
  13. 4 4
      statistics_order_warnings.php
  14. 77 16
      system/add_product.php
  15. 3 3
      system/edit_product.php
  16. 6 6
      system/products.php

+ 12 - 8
customerAdd.php

@@ -40,12 +40,10 @@ checkLogin();
                         <h3>联系人 #${contactIndex + 1}</h3>
                     </div>
                     <input type="hidden" name="contact[${contactIndex}][id]" value="">
-                    <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
-                        <tr>
-                            <th width="8%">联系人</th>
-                            <td><input type="text" name="contact[${contactIndex}][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
-                        </tr>
-                    </table>
+                    <div class="contact-method-row">
+                        <span style="width:80px;display:inline-block;font-weight:bold;" class="method-select">联系人姓名</span>
+                        <input type="text" name="contact[${contactIndex}][contact_name]" class="txt1 method-input" style="width:60%;" placeholder="联系人姓名"/>
+                    </div>
                     <div class="contact-methods-container" id="contact-methods-${contactIndex}">
                         <!-- Contact methods will be added here -->
                     </div>
@@ -249,6 +247,12 @@ checkLogin();
             return false;
         }
         
+        // Validate that at least one business type is selected
+        if (!$('input[name="cs_type[]"]:checked').length) {
+            alert("请至少选择一种业务类型!");
+            return false;
+        }
+        
         // Get source text to check if it's from Alibaba platforms
         var clientFromText = $("#cs_from option:selected").text();
         var isAlibabaSource = clientFromText.indexOf("1688") >= 0 || 
@@ -401,7 +405,7 @@ checkLogin();
         .contact-method-row {
             margin-bottom: 6px;
             padding: 6px;
-            border: 1px solid #eee;
+            /*border: 1px solid #eee;*/
            /*background-color: #f5f5f5;*/
             display: flex;
             align-items: center;
@@ -511,7 +515,7 @@ checkLogin();
                         <?php
                         $result = $conn->query("SELECT id, businessType FROM clienttype");
                         while ($row = $result->fetch_assoc()) {
-                            echo "<input type=\"radio\" name=\"cs_type\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\">
+                            echo "<input type=\"checkbox\" name=\"cs_type[]\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\">
                                   <label for=\"fortype{$row['id']}\">{$row['businessType']}</label>";
                         }
                         ?>

+ 610 - 33
customerEdit.php

@@ -90,17 +90,8 @@ if (!empty($id) && is_numeric($id)) {
     <script>
     $(document).ready(function(){
         $('.txt2').xheditor({
-            tools:'full',
-            hoverExecDelay:-1,
-            urlBase:'system',
-            upLinkUrl:"upload.php",
-            upLinkExt:"zip,rar,txt,pdf",
-            upImgUrl:"upload.php",
-            upImgExt:"jpg,jpeg,gif,png",
-            upFlashUrl:"upload.php",
-            upFlashExt:"swf",
-            upMediaUrl:"upload.php",
-            upMediaExt:"wmv,avi,wma,mp3,mid"
+            tools:'simple',
+            hoverExecDelay:-1
         });
         
         // Remove contact
@@ -125,12 +116,10 @@ if (!empty($id) && is_numeric($id)) {
                         <h3>联系人 #${contactIndex + 1}</h3>
                     </div>
                     <input type="hidden" name="contact[${contactIndex}][id]" value="">
-                    <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
-                        <tr>
-                            <th width="8%">联系人</th>
-                            <td><input type="text" name="contact[${contactIndex}][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
-                        </tr>
-                    </table>
+                    <div class="contact-method-row">
+                        <span style="width:80px;display:inline-block;font-weight:bold;" class="method-select">联系人姓名</span>
+                        <input type="text" name="contact[${contactIndex}][contact_name]" class="txt1 method-input" style="width:60%;" placeholder="联系人姓名"/>
+                    </div>
                     <div class="contact-methods-container" id="contact-methods-${contactIndex}">
                         <!-- Contact methods will be added here -->
                     </div>
@@ -185,6 +174,272 @@ if (!empty($id) && is_numeric($id)) {
             // Update available options in other selects
             updateAvailableMethodTypes(contactIndex);
         });
+        
+        // 客户关系相关JS代码
+        // 显示添加关系弹窗
+        $('#add-relationship-btn').click(function() {
+            $('#relationship-modal-title').text('添加客户关系');
+            $('#relationship_id').val('');
+            $('#related_customer_id').val('');
+            $('#related_customer_search').val('').show();
+            $('#related_customer_selected').hide();
+            $('#relationship_type').val('');
+            $('input[name="relationship_status"][value="1"]').prop('checked', true);
+            $('#relationship_description').val('');
+            
+            $('<div class="modal-backdrop"></div>').appendTo('body');
+            $('#relationship-modal').show();
+        });
+        
+        // 关闭弹窗
+        $('#cancel-relationship-btn').click(function() {
+            $('#relationship-modal').hide();
+            $('.modal-backdrop').remove();
+        });
+        
+        // 编辑关系
+        $(document).on('click', '.edit-relationship-btn', function() {
+            var relationshipId = $(this).data('id');
+            
+            // AJAX获取关系详情
+            $.ajax({
+                url: 'get_relationship.php',
+                type: 'GET',
+                data: {id: relationshipId},
+                dataType: 'json',
+                success: function(data) {
+                    if (data && data.success) {
+                        var relationship = data.relationship;
+                        $('#relationship_id').val(relationship.id);
+                        
+                        // 确定关联的客户(不是当前客户的那一方)
+                        var currentCustomerId = $('#current_customer_id').val();
+                        var relatedCustomerId = relationship.source_customer_id == currentCustomerId 
+                                            ? relationship.target_customer_id 
+                                            : relationship.source_customer_id;
+                        var relatedCustomerName = relationship.source_customer_id == currentCustomerId 
+                                            ? relationship.target_company 
+                                            : relationship.source_company;
+                        var relatedCustomerCode = relationship.source_customer_id == currentCustomerId 
+                                            ? relationship.target_code 
+                                            : relationship.source_code;
+                        
+                        var displayText = relatedCustomerName;
+                        if (relatedCustomerCode) {
+                            displayText = relatedCustomerCode + ' - ' + relatedCustomerName;
+                        }
+                        
+                        $('#related_customer_id').val(relatedCustomerId);
+                        $('#related_customer_search').hide();
+                        $('#related_customer_selected')
+                            .text(displayText)
+                            .append('<span class="customer-clear-btn" title="清除选择">X</span>')
+                            .show()
+                            .attr('title', displayText);
+                        
+                        $('#relationship_type').val(relationship.relationship_type);
+                        $('input[name="relationship_status"][value="' + relationship.relationship_status + '"]').prop('checked', true);
+                        $('#relationship_description').val(relationship.description);
+                        
+                        $('#relationship-modal-title').text('编辑客户关系');
+                        $('<div class="modal-backdrop"></div>').appendTo('body');
+                        $('#relationship-modal').show();
+                    } else {
+                        alert('获取关系信息失败');
+                    }
+                },
+                error: function() {
+                    alert('获取关系信息失败,请稍后重试');
+                }
+            });
+        });
+        
+        // 删除关系
+        $(document).on('click', '.delete-relationship-btn', function() {
+            if (confirm('确定要删除此客户关系吗?')) {
+                var relationshipId = $(this).data('id');
+                
+                $.ajax({
+                    url: 'delete_relationship.php',
+                    type: 'POST',
+                    data: {id: relationshipId},
+                    dataType: 'json',
+                    success: function(data) {
+                        if (data && data.success) {
+                            alert('删除成功');
+                            location.reload();
+                        } else {
+                            alert(data.message || '删除失败');
+                        }
+                    },
+                    error: function() {
+                        alert('操作失败,请稍后重试');
+                    }
+                });
+            }
+        });
+        
+        // 保存关系
+        $('#save-relationship-btn').click(function() {
+            var relationshipId = $('#relationship_id').val();
+            var currentCustomerId = $('#current_customer_id').val();
+            var relatedCustomerId = $('#related_customer_id').val();
+            var relationshipType = $('#relationship_type').val();
+            var relationshipStatus = $('input[name="relationship_status"]:checked').val();
+            var description = $('#relationship_description').val();
+            
+            // 验证
+            if (!relatedCustomerId) {
+                alert('请选择关联客户');
+                return;
+            }
+            
+            if (!relationshipType) {
+                alert('请选择关系类型');
+                return;
+            }
+            
+            var data = {
+                id: relationshipId,
+                source_customer_id: currentCustomerId,
+                target_customer_id: relatedCustomerId,
+                relationship_type: relationshipType,
+                relationship_status: relationshipStatus,
+                description: description
+            };
+            
+            $.ajax({
+                url: 'save_relationship.php',
+                type: 'POST',
+                data: data,
+                dataType: 'json',
+                success: function(response) {
+                    if (response && response.success) {
+                        alert('保存成功');
+                        $('#relationship-modal').hide();
+                        $('.modal-backdrop').remove();
+                        location.reload();
+                    } else {
+                        alert(response.message || '保存失败');
+                    }
+                },
+                error: function() {
+                    alert('操作失败,请稍后重试');
+                }
+            });
+        });
+        
+        // 客户搜索功能
+        var customerSearchTimeout = null;
+        var customerIsComposing = false;
+        
+        // 监听输入法组合事件
+        $(document).on('compositionstart', '#related_customer_search', function() {
+            customerIsComposing = true;
+        });
+
+        $(document).on('compositionend', '#related_customer_search', function() {
+            customerIsComposing = false;
+            $(this).trigger('input'); // 手动触发一次input事件
+        });
+        
+        // 客户搜索输入
+        $(document).on('input', '#related_customer_search', function() {
+            // 如果是输入法正在组合中文,不处理
+            if (customerIsComposing) return;
+            
+            var searchTerm = $(this).val().trim();
+            var customerDropdown = $('#related_customer_dropdown');
+            var currentCustomerId = $('#current_customer_id').val();
+            
+            // 清除之前的超时
+            clearTimeout(customerSearchTimeout);
+            
+            // 隐藏之前的结果
+            customerDropdown.hide();
+            
+            // 清除之前的选择
+            $('#related_customer_id').val('');
+            $('#related_customer_selected').hide();
+            
+            // 如果搜索词少于1个字符,不执行搜索
+            if (searchTerm.length < 1) {
+                return;
+            }
+            
+            // 设置一个300毫秒的超时,以减少请求数量
+            customerSearchTimeout = setTimeout(function() {
+                $.ajax({
+                    url: 'get_customer_search.php',
+                    type: 'GET',
+                    data: {
+                        search: searchTerm,
+                        exclude_id: currentCustomerId // 排除当前客户
+                    },
+                    dataType: 'json',
+                    success: function(data) {
+                        customerDropdown.empty();
+                        
+                        if (data && data.customers && data.customers.length > 0) {
+                            $.each(data.customers, function(i, customer) {
+                                var displayText = customer.cs_company;
+                                if (customer.cs_code) {
+                                    displayText = customer.cs_code + ' - ' + displayText;
+                                }
+                                
+                                var item = $('<div class="customer-item"></div>')
+                                    .attr('data-id', customer.id)
+                                    .attr('data-display', displayText)
+                                    .text(displayText);
+                                
+                                customerDropdown.append(item);
+                            });
+                            customerDropdown.show();
+                        }
+                    },
+                    error: function() {
+                        console.log('搜索客户失败,请重试');
+                    }
+                });
+            }, 300);
+        });
+        
+        // 点击选择客户
+        $(document).on('click', '.customer-item', function() {
+            var customerId = $(this).data('id');
+            var displayText = $(this).data('display');
+            
+            // 设置选中的客户ID和显示
+            $('#related_customer_id').val(customerId);
+            $('#related_customer_search').hide();
+            $('#related_customer_selected')
+                .text(displayText)
+                .append('<span class="customer-clear-btn" title="清除选择">X</span>')
+                .show()
+                .attr('title', displayText);
+            
+            // 隐藏下拉菜单
+            $('#related_customer_dropdown').hide();
+        });
+        
+        // 点击X按钮清除选择的客户
+        $(document).on('click', '.customer-clear-btn', function(e) {
+            e.stopPropagation();
+            
+            // 显示搜索框,隐藏已选信息
+            $('#related_customer_search').val('').show();
+            $('#related_customer_selected').hide();
+            
+            // 清空客户ID
+            $('#related_customer_id').val('');
+        });
+        
+        // 点击其他地方隐藏下拉列表
+        $(document).on('click', function(e) {
+            if (!$(e.target).closest('.customer-search-container').length) {
+                $('.customer-dropdown').hide();
+            }
+        });
     });
 
     // Update method fields based on selection
@@ -318,6 +573,12 @@ if (!empty($id) && is_numeric($id)) {
             return false;
         }
         
+        // Validate that at least one business type is selected
+        if (!$('input[name="cs_type[]"]:checked').length) {
+            alert("请至少选择一种业务类型!");
+            return false;
+        }
+        
         // Get source text to check if it's from Alibaba platforms
         var clientFromText = $("#cs_from option:selected").text();
         var isAlibabaSource = clientFromText.indexOf("1688") >= 0 || 
@@ -495,7 +756,7 @@ if (!empty($id) && is_numeric($id)) {
         .contact-method-row {
             margin-bottom: 6px;
             padding: 6px;
-            border: 1px solid #eee;
+            border: 0px solid #eee;
            /*background-color: #f5f5f5;*/
             display: flex;
             align-items: center;
@@ -526,6 +787,185 @@ if (!empty($id) && is_numeric($id)) {
         .contact-table td, .contact-table th {
             padding: 4px 6px;
         }
+        
+        /* 客户关系样式 */
+        .relationships-table {
+            width: 100%;
+            border-collapse: collapse;
+            margin-bottom: 10px;
+        }
+        .relationships-table th, .relationships-table td {
+            border: 1px solid #ddd;
+            padding: 8px;
+            text-align: left;
+        }
+        .relationships-table th {
+            background-color: #f2f2f2;
+        }
+        .btn-add-relationship {
+            background-color: #4CAF50;
+            color: white;
+            border: none;
+            padding: 6px 12px;
+            margin-bottom: 10px;
+            cursor: pointer;
+        }
+        .edit-relationship-btn, .delete-relationship-btn {
+            margin-right: 5px;
+            cursor: pointer;
+            padding: 3px 8px;
+            border: none;
+        }
+        .edit-relationship-btn {
+            background-color: #2196F3;
+            color: white;
+        }
+        .delete-relationship-btn {
+            background-color: #f44336;
+            color: white;
+        }
+        #relationship-modal {
+            position: fixed;
+            top: 50%;
+            left: 50%;
+            transform: translate(-50%, -50%);
+            background-color: white;
+            padding: 20px;
+            border: 1px solid #ddd;
+            box-shadow: 0 0 10px rgba(0,0,0,0.3);
+            z-index: 1000;
+            width: 600px;
+            max-width: 90%;
+        }
+        /* 弹窗内表格样式修复 */
+        #relationship-modal table.table1 {
+            width: 100%;
+            border-collapse: collapse;
+            table-layout: fixed;
+        }
+        #relationship-modal table.table1 th {
+            width: 120px;
+            text-align: right;
+            padding-right: 10px;
+            vertical-align: middle;
+            white-space: nowrap;
+        }
+        #relationship-modal table.table1 td {
+            padding: 6px 8px;
+        }
+        #relationship-modal .txt1 {
+            width: 90%;
+        }
+        #relationship-modal select.txt1 {
+            max-width: 300px;
+        }
+        .modal-backdrop {
+            position: fixed;
+            top: 0;
+            left: 0;
+            width: 100%;
+            height: 100%;
+            background-color: rgba(0,0,0,0.5);
+            z-index: 999;
+        }
+        .modal-actions {
+            text-align: right;
+            margin-top: 15px;
+        }
+        .modal-actions button {
+            padding: 5px 15px;
+            margin-left: 10px;
+            cursor: pointer;
+        }
+        /* 弹窗按钮样式 */
+        .modal-actions .btn1 {
+            border: 1px solid #ccc;
+            background: #f5f5f5;
+            border-radius: 3px;
+            color: #333;
+            font-size: 12px;
+            height: 26px;
+            padding: 0 15px;
+            transition: all 0.3s;
+        }
+        .modal-actions .btn1:hover {
+            background: #e6e6e6;
+            border-color: #adadad;
+        }
+        #save-relationship-btn {
+            background-color: #428bca;
+            color: white;
+            border-color: #357ebd;
+        }
+        #save-relationship-btn:hover {
+            background-color: #3071a9;
+            border-color: #285e8e;
+        }
+        .customer-search-container {
+            display: flex;
+            align-items: center;
+            margin-bottom: 10px;
+            position: relative;
+            width: 80%;
+        }
+        .customer-dropdown {
+            display: none;
+            position: absolute;
+            background: white;
+            border: 1px solid #ccc;
+            max-height: 200px;
+            overflow-y: auto;
+            width: 100%;
+            z-index: 1000;
+            box-shadow: 0 3px 8px rgba(0,0,0,0.25);
+            border-radius: 0 0 4px 4px;
+            top: 100%;
+            left: 0;
+        }
+        .customer-item {
+            padding: 10px 12px;
+            cursor: pointer;
+            border-bottom: 1px solid #eee;
+            transition: background-color 0.2s;
+        }
+        .customer-item:hover {
+            background-color: #f0f0f0;
+        }
+        .selected-customer-info {
+            font-weight: bold;
+            padding: 8px 10px;
+            border: 1px solid #ddd;
+            background-color: #f9f9f9;
+            display: none;
+            width: 100%;
+            box-sizing: border-box;
+            word-break: break-all;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            white-space: normal;
+            min-height: 38px;
+            position: relative;
+            padding-right: 25px;
+        }
+        .customer-clear-btn {
+            position: absolute;
+            right: 5px;
+            top: 50%;
+            transform: translateY(-50%);
+            color: #e74c3c;
+            font-weight: bold;
+            cursor: pointer;
+            width: 16px;
+            height: 16px;
+            text-align: center;
+            line-height: 16px;
+            background: #f5f5f5;
+            border-radius: 50%;
+        }
+        .customer-clear-btn:hover {
+            background: #e74c3c;
+            color: white;
+        }
     </style>
 </head>
 <body class="clear">
@@ -548,6 +988,140 @@ if (!empty($id) && is_numeric($id)) {
                     <th width="8%">公司名称</th>
                     <td><input type="text" id="cs_company" name="cs_company" value="<?= htmlspecialcharsFix($customer['cs_company']) ?>" class="txt1" /></td>
                 </tr>
+                <!-- 客户关系管理部分 -->
+                <tr>
+                    <th width="8%" valign="top">客户关系</th>
+                    <td>
+                        <div id="relationships-container">
+                            <?php
+                            // 获取当前客户的所有关系
+                            $relationshipSql = "SELECT cr.*, 
+                                                c1.cs_company as source_company, c1.cs_code as source_code,
+                                                c2.cs_company as target_company, c2.cs_code as target_code
+                                                FROM customer_relationship cr
+                                                LEFT JOIN customer c1 ON cr.source_customer_id = c1.id
+                                                LEFT JOIN customer c2 ON cr.target_customer_id = c2.id
+                                                WHERE cr.source_customer_id = ? OR cr.target_customer_id = ?";
+                            $relationshipStmt = $conn->prepare($relationshipSql);
+                            $relationshipStmt->bind_param("ii", $id, $id);
+                            $relationshipStmt->execute();
+                            $relationshipResult = $relationshipStmt->get_result();
+                            
+                            $hasRelationships = false;
+                            if ($relationshipResult->num_rows > 0) {
+                                $hasRelationships = true;
+                                echo '<table width="100%" border="0" cellpadding="3" cellspacing="1" class="relationships-table">';
+                                echo '<tr><th>关系类型</th><th>相关客户</th><th>关系状态</th><th>关系描述</th><th>操作</th></tr>';
+                                
+                                while ($relationship = $relationshipResult->fetch_assoc()) {
+                                    $relationType = '';
+                                    switch ($relationship['relationship_type']) {
+                                        case 1: $relationType = '母公司-子公司'; break;
+                                        case 2: $relationType = '供应商-客户'; break;
+                                        case 3: $relationType = '合作伙伴'; break;
+                                        case 4: $relationType = '竞争对手'; break;
+                                        case 5: $relationType = '推荐人'; break;
+                                        case 6: $relationType = '其他'; break;
+                                    }
+                                    
+                                    $relationStatus = $relationship['relationship_status'] == 1 ? '启用' : '停用';
+                                    
+                                    // 确定关联的客户(不是当前客户的那一方)
+                                    $relatedCustomerId = $relationship['source_customer_id'] == $id 
+                                                        ? $relationship['target_customer_id'] 
+                                                        : $relationship['source_customer_id'];
+                                    $relatedCustomerName = $relationship['source_customer_id'] == $id 
+                                                        ? textUncode($relationship['target_company']) 
+                                                        : textUncode($relationship['source_company']);
+                                    $relatedCustomerCode = $relationship['source_customer_id'] == $id 
+                                                        ? textUncode($relationship['target_code']) 
+                                                        : textUncode($relationship['source_code']);
+                                    
+                                    $displayText = $relatedCustomerName;
+                                    if ($relatedCustomerCode) {
+                                        $displayText = $relatedCustomerCode . ' - ' . $relatedCustomerName;
+                                    }
+                                    
+                                    echo '<tr>';
+                                    echo '<td>' . $relationType . '</td>';
+                                    echo '<td>' . htmlspecialchars($displayText) . '</td>';
+                                    echo '<td>' . $relationStatus . '</td>';
+                                    echo '<td>' . htmlspecialchars(textUncode($relationship['description'])) . '</td>';
+                                    echo '<td>';
+                                    echo '<button type="button" class="edit-relationship-btn" data-id="' . $relationship['id'] . '">编辑</button>';
+                                    echo '<button type="button" class="delete-relationship-btn" data-id="' . $relationship['id'] . '">删除</button>';
+                                    echo '</td>';
+                                    echo '</tr>';
+                                }
+                                
+                                echo '</table>';
+                            } else {
+                                echo '<p>暂无关联客户关系。</p>';
+                            }
+                            ?>
+                            <button type="button" id="add-relationship-btn" class="btn-add-relationship">添加客户关系</button>
+                        </div>
+                        
+                        <!-- 添加/编辑关系的弹出框 -->
+                        <div id="relationship-modal" style="display: none;">
+                            <h3 id="relationship-modal-title" style="margin-top: 0; margin-bottom: 15px;">添加客户关系</h3>
+                            <input type="hidden" id="relationship_id" value="">
+                            <input type="hidden" id="current_customer_id" value="<?= $id ?>">
+                            
+                            <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1 relationship-modal-table">
+                                <tr>
+                                    <th width="120">关联客户</th>
+                                    <td>
+                                        <div class="customer-search-container" style="width: 90%; position: relative;">
+                                            <input type="text" id="related_customer_search" class="customer-search txt1" placeholder="输入客户编码或名称搜索..." value="" style="width: 100%; box-sizing: border-box;" />
+                                            <div id="related_customer_selected" class="selected-customer-info"></div>
+                                            <div id="related_customer_dropdown" class="customer-dropdown"></div>
+                                        </div>
+                                        <input type="hidden" id="related_customer_id" value="" />
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <th>关系类型</th>
+                                    <td>
+                                        <select id="relationship_type" class="txt1" style="width: auto; min-width: 200px;">
+                                            <option value="">请选择关系类型</option>
+                                            <option value="1">母公司-子公司</option>
+                                            <option value="2">供应商-客户</option>
+                                            <option value="3">合作伙伴</option>
+                                            <option value="4">竞争对手</option>
+                                            <option value="5">推荐人</option>
+                                            <option value="6">其他</option>
+                                        </select>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <th>关系状态</th>
+                                    <td>
+                                        <label style="margin-right: 15px;">
+                                            <input type="radio" name="relationship_status" value="1" checked>
+                                            启用
+                                        </label>
+                                        <label>
+                                            <input type="radio" name="relationship_status" value="0">
+                                            停用
+                                        </label>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <th>关系描述</th>
+                                    <td>
+                                        <textarea id="relationship_description" class="txt1" style="width: 90%; height: 100px; resize: vertical;"></textarea>
+                                    </td>
+                                </tr>
+                            </table>
+                            
+                            <div class="modal-actions">
+                                <button type="button" id="save-relationship-btn" class="btn1">保存</button>
+                                <button type="button" id="cancel-relationship-btn" class="btn1">取消</button>
+                            </div>
+                        </div>
+                    </td>
+                </tr>
                 <tr>
                     <th width="8%">地区/国家</th>
                     <td>
@@ -615,12 +1189,10 @@ if (!empty($id) && is_numeric($id)) {
                                         <h3>联系人 #<?= $index + 1 ?></h3>
                                     </div>
                                     <input type="hidden" name="contact[<?= $index ?>][id]" value="<?= $contact['id'] ?>">
-                                    <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
-                                        <tr>
-                                            <th width="8%">联系人</th>
-                                            <td><input type="text" name="contact[<?= $index ?>][contact_name]" value="<?= htmlspecialcharsFix($contact['contact_name']) ?>" class="txt1" placeholder="联系人姓名"/></td>
-                                        </tr>
-                                    </table>
+                                    <div class="contact-method-row">
+                                        <span style="width:80px;display:inline-block;font-weight:bold;" class="method-select">联系人姓名</span>
+                                        <input type="text" name="contact[<?= $index ?>][contact_name]" value="<?= htmlspecialcharsFix($contact['contact_name']) ?>" class="txt1 method-input" style="width:60%;" placeholder="联系人姓名"/>
+                                    </div>
                                     <div class="contact-methods-container" id="contact-methods-<?= $index ?>">
                                         <?php
                                         $methodTypes = [
@@ -665,18 +1237,16 @@ if (!empty($id) && is_numeric($id)) {
                                 </div>
                                 <?php endforeach; ?>
                             <?php else: ?>
-                                <div class="contact-form" id="contact-form-0">
+                                <div class="contact-form" id="contact-form-0"">
                                     <div class="contact-header">
                                         <button type="button" class="remove-contact-btn" data-index="0">删除</button>
                                         <h3>联系人 #1</h3>
                                     </div>
                                     <input type="hidden" name="contact[0][id]" value="">
-                                    <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
-                                        <tr>
-                                            <th width="8%">联系人</th>
-                                            <td><input type="text" name="contact[0][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
-                                        </tr>
-                                    </table>
+                                    <div class="contact-method-row">
+                                        <span style="width:80px;display:inline-block;font-weight:bold;" class="method-select">联系人姓名</span>
+                                        <input type="text" name="contact[0][contact_name]" class="txt1 method-input" style="width:60%;" placeholder="联系人姓名"/>
+                                    </div>
                                     <div class="contact-methods-container" id="contact-methods-0">
                                         <!-- Contact methods will be added here -->
                                     </div>
@@ -694,10 +1264,17 @@ if (!empty($id) && is_numeric($id)) {
                     <th>业务类型</th>
                     <td>
                         <?php
+                        // 获取当前客户的业务类型
+                        $selected_types = [];
+                        $type_result = $conn->query("SELECT business_type_id FROM customer_business_type WHERE customer_id = " . intval($id));
+                        while ($type_row = $type_result->fetch_assoc()) {
+                            $selected_types[] = $type_row['business_type_id'];
+                        }
+                        
                         $result = $conn->query("SELECT id, businessType FROM clienttype");
                         while ($row = $result->fetch_assoc()) {
-                            $checked = ($row['id'] == $customer['cs_type']) ? ' checked="checked"' : '';
-                            echo "<input type=\"radio\" name=\"cs_type\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\"$checked>
+                            $checked = in_array($row['id'], $selected_types) ? ' checked="checked"' : '';
+                            echo "<input type=\"checkbox\" name=\"cs_type[]\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\"$checked>
                                   <label for=\"fortype{$row['id']}\">{$row['businessType']}</label>";
                         }
                         ?>

+ 27 - 4
customerSave.php

@@ -26,7 +26,7 @@ $cs_company = textEncode($_POST['cs_company'] ?? '');
 $cs_country = $_POST['cs_country'] ?? '';
 $cs_from = $_POST['cs_from'] ?? '';
 $cs_address = textEncode($_POST['cs_address'] ?? '');
-$cs_type = textEncode($_POST['cs_type'] ?? '');
+$cs_type = $_POST['cs_type'] ?? []; // Changed to array for multi-select
 $cs_belongclient = $_POST['cs_belongclient'] ?? '';
 $cs_addtime = $_POST['cs_addtime'] ?? '';
 $cs_updatetime = date('Y-m-d H:i:s');
@@ -43,7 +43,6 @@ $allowedit = is_numeric($allowedit) ? $allowedit : 0;
 $cs_country = (is_numeric($cs_country) && $cs_country !== '') ? $cs_country : 0;
 $cs_from = (is_numeric($cs_from) && $cs_from !== '') ? $cs_from : 0;
 $cs_deal = (is_numeric($cs_deal) && $cs_deal !== '') ? $cs_deal : 1;
-$cs_type = (is_numeric($cs_type) && $cs_type !== '') ? $cs_type : 5;
 $cs_belongClient = (is_numeric($cs_belongclient) && $cs_belongclient !== '') ? $cs_belongclient : 0;
 
 $cs_note = htmlEncode($_POST['cs_note'] ?? '');
@@ -698,6 +697,20 @@ if ($act == "editSave" || $allowedit == 1) {
 
     $conn->query($updateSql);
     
+    // 处理业务类型 - 先删除已有的业务类型
+    $conn->query("DELETE FROM customer_business_type WHERE customer_id = " . intval($id));
+    
+    // 添加新的业务类型
+    if (!empty($cs_type) && is_array($cs_type)) {
+        foreach ($cs_type as $type_id) {
+            $type_id = intval($type_id);
+            if ($type_id > 0) {
+                $conn->query("INSERT INTO customer_business_type (customer_id, business_type_id) 
+                             VALUES (" . intval($id) . ", " . $type_id . ")");
+            }
+        }
+    }
+    
     // 处理联系人信息 - 首先删除已有的不在提交列表中的联系人
     $existingContactIds = [];
     foreach ($contacts as $contact) {
@@ -795,7 +808,7 @@ if ($act == "editSave" || $allowedit == 1) {
     // Insert new customer record
     $insertSql = "INSERT INTO customer (
         cs_code, cs_company, cs_country, cs_from, cs_address,
-        cs_type, cs_addtime, cs_updatetime, cs_belong, cs_belongClient, 
+        cs_addtime, cs_updatetime, cs_belong, cs_belongClient, 
         cs_state, cs_deal, cs_note, cs_chain, is_silent, cs_dealdate
     ) VALUES (
         '" . $conn->real_escape_string($cs_code) . "',
@@ -803,7 +816,6 @@ if ($act == "editSave" || $allowedit == 1) {
         " . $cs_country . ",
         " . $cs_from . ",
         '" . $conn->real_escape_string($cs_address) . "',
-        " . $cs_type . ",
         NOW(),
         NOW(),
         " . $cs_belong . ",
@@ -819,6 +831,17 @@ if ($act == "editSave" || $allowedit == 1) {
     $conn->query($insertSql);
     $new_customer_id = $conn->insert_id;
     
+    // Insert business types for new customer
+    if ($new_customer_id > 0 && !empty($cs_type) && is_array($cs_type)) {
+        foreach ($cs_type as $type_id) {
+            $type_id = intval($type_id);
+            if ($type_id > 0) {
+                $conn->query("INSERT INTO customer_business_type (customer_id, business_type_id) 
+                             VALUES (" . $new_customer_id . ", " . $type_id . ")");
+            }
+        }
+    }
+    
     // Insert contact information for all contacts
     if ($new_customer_id > 0) {
         foreach ($contacts as $contact) {

+ 50 - 0
delete_relationship.php

@@ -0,0 +1,50 @@
+<?php
+require_once 'conn.php';
+checkLogin();
+
+header('Content-Type: application/json');
+
+if (!isset($_POST['id']) || !is_numeric($_POST['id'])) {
+    echo json_encode(['success' => false, 'message' => '参数错误']);
+    exit;
+}
+
+$id = intval($_POST['id']);
+$isAdmin = checkIfAdmin();
+
+// 验证权限
+if (!$isAdmin) {
+    // 检查当前用户是否是源客户或目标客户的负责人
+    $sql = "SELECT cr.source_customer_id, cr.target_customer_id 
+            FROM customer_relationship cr
+            WHERE cr.id = $id";
+    $result = mysqli_query($conn, $sql);
+    
+    if ($row = mysqli_fetch_assoc($result)) {
+        $sourceId = $row['source_customer_id'];
+        $targetId = $row['target_customer_id'];
+        $employeeId = $_SESSION['employee_id'];
+        
+        $customerSql = "SELECT id FROM customer WHERE (id = $sourceId OR id = $targetId) AND cs_belong = $employeeId";
+        $customerResult = mysqli_query($conn, $customerSql);
+        
+        if (mysqli_num_rows($customerResult) == 0) {
+            echo json_encode(['success' => false, 'message' => '您没有权限删除此客户关系']);
+            exit;
+        }
+    } else {
+        echo json_encode(['success' => false, 'message' => '未找到客户关系']);
+        exit;
+    }
+}
+
+// 执行删除
+$deleteSql = "DELETE FROM customer_relationship WHERE id = $id";
+$result = mysqli_query($conn, $deleteSql);
+
+if ($result) {
+    echo json_encode(['success' => true, 'message' => '客户关系已删除']);
+} else {
+    echo json_encode(['success' => false, 'message' => '删除失败: ' . mysqli_error($conn)]);
+}
+?> 

+ 54 - 0
get_relationship.php

@@ -0,0 +1,54 @@
+<?php
+require_once 'conn.php';
+checkLogin();
+
+header('Content-Type: application/json');
+
+if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
+    echo json_encode(['success' => false, 'message' => '参数错误']);
+    exit;
+}
+
+$id = intval($_GET['id']);
+
+// 获取关系详情
+$sql = "SELECT cr.*, 
+        c1.cs_company as source_company, c1.cs_code as source_code,
+        c2.cs_company as target_company, c2.cs_code as target_code
+        FROM customer_relationship cr
+        LEFT JOIN customer c1 ON cr.source_customer_id = c1.id
+        LEFT JOIN customer c2 ON cr.target_customer_id = c2.id
+        WHERE cr.id = $id";
+
+$result = mysqli_query($conn, $sql);
+
+if ($row = mysqli_fetch_assoc($result)) {
+    // 检查权限:如果不是管理员,只能查看自己能操作的客户
+    $isAdmin = checkIfAdmin();
+    if (!$isAdmin) {
+        // 检查当前用户是否是源客户或目标客户的负责人
+        $sourceId = $row['source_customer_id'];
+        $targetId = $row['target_customer_id'];
+        $employeeId = $_SESSION['employee_id'];
+        
+        $customerSql = "SELECT id FROM customer WHERE (id = $sourceId OR id = $targetId) AND cs_belong = $employeeId";
+        $customerResult = mysqli_query($conn, $customerSql);
+        
+        if (mysqli_num_rows($customerResult) == 0) {
+            echo json_encode(['success' => false, 'message' => '您没有权限查看此客户关系']);
+            exit;
+        }
+    }
+    
+    // 准备返回数据
+    $row['source_company'] = textUncode($row['source_company']);
+    $row['source_code'] = textUncode($row['source_code']);
+    $row['target_company'] = textUncode($row['target_company']);
+    $row['target_code'] = textUncode($row['target_code']);
+    $row['description'] = textUncode($row['description']);
+    
+    echo json_encode(['success' => true, 'relationship' => $row]);
+} else {
+    echo json_encode(['success' => false, 'message' => '未找到客户关系']);
+}
+?> 

+ 2 - 2
order.php

@@ -201,7 +201,7 @@ $sqlStr .= " $fliterStr ORDER BY {$ordStr}o.created_at DESC";
     <div class="fastSelect clear">
         <H1>筛选条件</H1>
         <div class="selectItem">
-            <label>订单日期</label>
+            <label>出货日期</label>
             <input type="date" name="fliterFromDate" class="date-input filterSearch" value="<?= $fliterFromDate ?>">
             <label>到</label>
             <input type="date" name="fliterToDate" class="date-input filterSearch" value="<?= $fliterToDate ?>">
@@ -224,7 +224,7 @@ $sqlStr .= " $fliterStr ORDER BY {$ordStr}o.created_at DESC";
             <div class="col3">销售订单号</div>
             <div class="col4">客户编码</div>
             <div class="col5">客户</div>
-            <div class="col7">订单日期</div>
+            <div class="col7">出货日期</div>
             <div class="col9">订单金额</div>
             <div class="col10">操作</div>
         </div>

+ 49 - 229
order_add.php

@@ -58,7 +58,7 @@ if ($customerId > 0) {
             display: flex;
             align-items: center;
             flex-wrap: wrap;
-            gap: 8px;
+            gap: 20px; /* 增加间距 */
             background-color: #f9f9f9;
             box-shadow: 0 1px 3px rgba(0,0,0,0.1);
         }
@@ -83,7 +83,7 @@ if ($customerId > 0) {
             color: white;
         }
         .product-info {
-            flex: 2;
+            flex: 3;
             min-width: 200px;
         }
         .product-spec {
@@ -95,7 +95,7 @@ if ($customerId > 0) {
             min-width: 80px;
         }
         .product-unit {
-            flex: 0.5;
+            flex: 0.8;
             min-width: 60px;
         }
         .product-price {
@@ -103,12 +103,12 @@ if ($customerId > 0) {
             min-width: 100px;
         }
         .product-total {
-            flex: 1;
+            flex: 1.2;
             min-width: 100px;
             font-weight: bold;
         }
         .product-row input[type="number"] {
-            width: 80px;
+            width: 90%;
             padding: 5px;
             border: 1px solid #ddd;
             border-radius: 4px;
@@ -305,6 +305,9 @@ if ($customerId > 0) {
         .customer-clear-btn:hover {
             color: #c0392b;
         }
+        .product-row .total-price-input {
+            width: 90%;
+        }
     </style>
 </head>
 <body>
@@ -314,7 +317,7 @@ if ($customerId > 0) {
             <tbody>
             <tr>
                 <th width="8%">销售订单号</th>
-                <td><input type="text" id="order_code" name="order_code" value="" class="txt1" placeholder="请输入销售订单号" /></td>
+                <td><input type="text" id="order_code" name="order_code" value="" class="txt1" placeholder="请输入销售订单号 (多个用 / 分隔) " /></td>
             </tr>
             <tr>
                 <th width="8%">客户选择</th>
@@ -343,7 +346,7 @@ if ($customerId > 0) {
                 </td>
             </tr>
             <tr>
-                <th width="8%">订单日期</th>
+                <th width="8%">出货日期</th>
                 <td><input type="date" id="order_date" name="order_date" value="<?= date('Y-m-d') ?>" class="txt1" /></td>
             </tr>
             <tr>
@@ -351,13 +354,11 @@ if ($customerId > 0) {
                 <td>
                     <button type="button" id="add-product-btn" class="add-product-btn">添加产品</button>
                     
-                    <div class="product-list-header" style="display: flex; background-color: #eee; padding: 8px 15px; margin-bottom: 10px; border-radius: 4px; font-weight: bold; color: #555; font-size: 13px; gap: 8px;">
-                        <div style="flex: 2; min-width: 200px;">产品</div>
-                        <div style="flex: 2; min-width: 200px;">规格</div>
+                    <div class="product-list-header" style="display: flex; background-color: #eee; padding: 8px 15px; margin-bottom: 10px; border-radius: 4px; font-weight: bold; color: #555; font-size: 13px; gap: 20px;">
+                        <div style="flex: 3; min-width: 200px;">产品</div>
                         <div style="flex: 1; min-width: 80px;">数量</div>
-                        <div style="flex: 0.5; min-width: 60px;">单位</div>
-                        <div style="flex: 1; min-width: 100px;">单价</div>
-                        <div style="flex: 1; min-width: 100px;">总价</div>
+                        <div style="flex: 0.8; min-width: 60px;">单位</div>
+                        <div style="flex: 1.2; min-width: 100px;">总价</div>
                     </div>
                     
                     <div id="product-container">
@@ -630,6 +631,20 @@ if ($customerId > 0) {
                 var categoryTag = $this.find('.category-tag').text();
                 var row = $this.closest('.product-row');
                 
+                // 检查是否已存在相同的产品
+                var isDuplicate = false;
+                $('.product-id-input').not(row.find('.product-id-input')).each(function() {
+                    if ($(this).val() == productId) {
+                        isDuplicate = true;
+                        return false; // 跳出循环
+                    }
+                });
+                
+                if (isDuplicate) {
+                    alert('该产品已添加,不能添加相同的产品');
+                    return;
+                }
+                
                 // 清理产品名称,移除分类信息
                 if (categoryTag) {
                     productName = productName.replace(categoryTag, '').trim();
@@ -649,87 +664,10 @@ if ($customerId > 0) {
                 // 隐藏产品搜索结果
                 row.find('.productlist').hide();
                 
-                // 获取产品规格信息
+                // 获取产品单位信息
                 getProductSpecifications(productId, row);
             });
             
-            // 规格选择改变事件
-            $(document).on('change', '.spec-select', function() {
-                var $this = $(this);
-                var row = $this.closest('.product-row');
-                var specId = $this.val();
-                var specData = $this.find('option:selected').data();
-                
-                if (specId) {
-                    // 检查是否已存在相同的产品规格组合
-                    var isDuplicate = false;
-                    $('.spec-select').not($this).each(function() {
-                        if ($(this).val() == specId) {
-                            isDuplicate = true;
-                            return false; // 跳出循环
-                        }
-                    });
-                    
-                    if (isDuplicate) {
-                        alert('该产品规格已添加,不能重复添加');
-                        $this.val(''); // 重置选择
-                        return;
-                    }
-                    
-                    // 设置规格ID到隐藏字段
-                    row.find('.spec-id-input').val(specId);
-                    
-                    // 不再自动设置价格信息
-                    // if (specData.price) {
-                    //     row.find('.price-input').val(specData.price);
-                    // } else {
-                    //     row.find('.price-input').val('');
-                    // }
-                    
-                    // 存储规格价格作为最低价格限制
-                    var minPrice = specData.price || 0;
-                    var priceInput = row.find('.price-input');
-                    priceInput.attr('data-min-price', minPrice);
-                    if (minPrice > 0) {
-                        priceInput.attr('placeholder', '输入单价');
-                    } else {
-                        priceInput.attr('placeholder', '输入单价');
-                    }
-                    
-                    // 设置最小订购数量
-                    var minQty = specData.minQty || 1;
-                    var qtyInput = row.find('.quantity-input');
-                    if (parseInt(qtyInput.val()) < minQty) {
-                        qtyInput.val(minQty);
-                    }
-                    qtyInput.attr('min', minQty);
-                    
-                    // 更新规格信息显示
-                    // var specInfoHtml = '';
-                    // if (specData.code) {
-                    //     specInfoHtml += '<span>编码: ' + specData.code + '</span>';
-                    // }
-                    // if (specData.minQty > 1) {
-                    //     specInfoHtml += ' <span>最小订购量: ' + specData.minQty + '</span>';
-                    // }
-                    // if (specData.price) {
-                    //     specInfoHtml += ' <span>参考价格: ¥' + specData.price + '</span>';
-                    // }
-                    // row.find('.spec-info').html(specInfoHtml);
-                    
-                    // 重新计算总价
-                    calculateItemTotal(row.find('.price-input')[0]);
-                } else {
-                    // 清除规格相关信息
-                    row.find('.spec-id-input').val('');
-                    // 不再清除价格
-                    // row.find('.price-input').val('');
-                    row.find('.price-input').attr('data-min-price', '0').attr('placeholder', '输入单价');
-                    row.find('.spec-info').html('');
-                    calculateItemTotal(row.find('.price-input')[0]);
-                }
-            });
-            
             // 点击其他地方隐藏下拉列表
             $(document).on('click', function(e) {
                 if (!$(e.target).closest('.product-search').length && !$(e.target).closest('.productlist').length) {
@@ -747,26 +685,21 @@ if ($customerId > 0) {
                 
                 // 只有当已经选择了产品时才允许重新选择
                 if (productId) {
-                    if (confirm('确定要重新选择产品吗?这将清除当前选择的产品及其规格信息。')) {
-                        // 清空产品ID和选择的规格
+                    if (confirm('确定要重新选择产品吗?这将清除当前选择的产品信息。')) {
+                        // 清空产品ID
                         row.find('.product-id-input').val('');
-                        row.find('.spec-id-input').val('');
                         
                         // 隐藏产品信息,显示搜索框
                         $(this).hide();
                         row.find('.product-search').val('').show();
                         
-                        // 隐藏并清空规格选择
-                        row.find('.spec-select').hide().empty();
-                        row.find('.spec-info').html('');
-                        
                         // 清除单位信息
                         row.find('.unit-input').val('');
                         row.find('.unit-label').text('');
                         
-                        // 清除价信息并重新计算总额
-                        row.find('.price-input').val('');
-                        calculateItemTotal(row.find('.price-input')[0]);
+                        // 清除价信息并重新计算总额
+                        row.find('.total-price-input').val('0.00');
+                        calculateOrderTotal();
                     }
                 }
             });
@@ -785,18 +718,9 @@ if ($customerId > 0) {
                     <div class="selected-product-info" style="cursor: pointer; display: none;" title="点击重新选择产品"></div>
                 </div>
                 
-                <div class="row-section product-spec">
-                    <div class="row-section-label"><span>规格</span></div>
-                    <input type="hidden" name="items[${productIndex}][spec_id]" class="spec-id-input" value="">
-                    <select class="spec-select" name="items[${productIndex}][spec_select]" style="display: none;">
-                        <option value="">请选择规格</option>
-                    </select>
-                    <div class="spec-info"></div>
-                </div>
-                
                 <div class="row-section product-quantity">
                     <div class="row-section-label"><span>数量</span></div>
-                    <input type="number" name="items[${productIndex}][quantity]" value="1" min="1" class="quantity-input" onchange="calculateItemTotal(this)">
+                    <input type="number" name="items[${productIndex}][quantity]" value="1" min="1" class="quantity-input">
                 </div>
                 
                 <div class="row-section product-unit">
@@ -805,15 +729,9 @@ if ($customerId > 0) {
                     <input type="hidden" name="items[${productIndex}][unit]" class="unit-input" value="">
                 </div>
                 
-                <div class="row-section product-price">
-                    <div class="row-section-label"><span>单价</span></div>
-                    <input type="number" step="0.01" name="items[${productIndex}][unit_price]" value="" class="price-input" placeholder="输入单价" onchange="calculateItemTotal(this)">
-                </div>
-                
                 <div class="row-section product-total">
                     <div class="row-section-label"><span>总价</span></div>
-                    <span class="total-price-display" style="display: inline-block; background-color: #f0f0f0; border: 1px solid #ddd; padding: 2px 8px; min-width: 60px; text-align: right;">0.00</span>
-                    <input type="hidden" name="items[${productIndex}][total_price]" value="0.00" class="total-price-input">
+                    <input type="number" step="0.01" name="items[${productIndex}][total_price]" value="0.00" class="total-price-input" placeholder="输入总价" onchange="calculateOrderTotal()">
                 </div>
             </div>
             `;
@@ -832,49 +750,14 @@ if ($customerId > 0) {
                 data: {product_id: productId},
                 dataType: 'json',
                 success: function(data) {
-                    if (data && data.product && data.specifications) {
-                        // 恢复设置单位信息
+                    if (data && data.product) {
+                        // 设置单位信息
                         if (data.product.unit) {
                             row.find('.unit-input').val(data.product.unit);
                             row.find('.unit-label').text(data.product.unit);
                         }
-                        
-                        // 处理规格信息
-                        var specifications = data.specifications;
-                        if (specifications.length === 0) {
-                            alert('此产品没有规格信息,请添加规格后再选择');
-                            // 重置产品选择
-                            row.find('.product-id-input').val('');
-                            row.find('.selected-product-info').hide();
-                            row.find('.product-search').val('').show();
-                            return;
-                        }
-                        
-                        // 填充规格选择下拉框
-                        var specSelect = row.find('.spec-select');
-                        specSelect.empty();
-                        specSelect.append('<option value="">请选择规格</option>');
-                        
-                        $.each(specifications, function(i, spec) {
-                            var displayText = spec.spec_name + ': ' + spec.spec_value;
-                            if (spec.price) {
-                                displayText += ' (¥' + spec.price + ')';
-                            }
-                            
-                            var option = $('<option></option>')
-                                .attr('value', spec.id)
-                                .text(displayText)
-                                .data('price', spec.price)
-                                .data('minQty', spec.min_order_quantity)
-                                .data('code', spec.spec_code);
-                            
-                            specSelect.append(option);
-                        });
-                        
-                        // 显示规格选择下拉框
-                        specSelect.show();
                     } else {
-                        alert('获取产品规格失败');
+                        alert('获取产品信息失败');
                         // 重置产品选择
                         row.find('.product-id-input').val('');
                         row.find('.selected-product-info').hide();
@@ -882,7 +765,7 @@ if ($customerId > 0) {
                     }
                 },
                 error: function() {
-                    alert('获取产品规格失败,请重试');
+                    alert('获取产品信息失败,请重试');
                     // 重置产品选择
                     row.find('.product-id-input').val('');
                     row.find('.selected-product-info').hide();
@@ -905,31 +788,6 @@ if ($customerId > 0) {
             productIndex = $('.product-row').length;
         }
 
-        function calculateItemTotal(element) {
-            var row = $(element).closest('.product-row');
-            var quantity = parseInt(row.find('.quantity-input').val()) || 0;
-            var priceInput = row.find('.price-input');
-            var priceValue = priceInput.val().trim();
-            var price = (priceValue === '') ? 0 : (parseFloat(priceValue) || 0);
-            var minPrice = parseFloat(priceInput.attr('data-min-price')) || 0;
-
-            // 检查价格是否低于规格最低价
-            if (price > 0 && minPrice > 0 && price < minPrice) {
-                priceInput.css('color', 'red');
-            } else {
-                priceInput.css('color', '');
-            }
-
-            var total = quantity * price;
-            if (total < 0) total = 0;
-
-            // 更新显示元素和隐藏输入框
-            row.find('.total-price-display').text(total.toFixed(2));
-            row.find('.total-price-input').val(total.toFixed(2));
-
-            calculateOrderTotal();
-        }
-
         function calculateOrderTotal() {
             var total = 0;
             $('.total-price-input').each(function() {
@@ -964,9 +822,7 @@ if ($customerId > 0) {
             var customerId = $('#customer_id').val();
             var customerName = $('#customer_search').val();
             var hasProducts = false;
-            var allSpecsSelected = true;
-            var allPricesValid = true;
-            var allPricesHighEnough = true;
+            var allTotalPricesValid = true;
             var firstInvalidField = null;
 
             // 检查是否有产品行
@@ -978,12 +834,8 @@ if ($customerId > 0) {
 
             $('.product-row').each(function() {
                 var productId = $(this).find('.product-id-input').val();
-                var specId = $(this).find('.spec-id-input').val();
-                var priceInput = $(this).find('.price-input');
-                var priceValue = priceInput.val().trim();
-                var price = parseFloat(priceValue) || 0;
-                var minPrice = parseFloat(priceInput.attr('data-min-price')) || 0;
-                var specSelect = $(this).find('.spec-select');
+                var totalPriceInput = $(this).find('.total-price-input');
+                var totalPrice = parseFloat(totalPriceInput.val()) || 0;
                 var productSearch = $(this).find('.product-search');
                 
                 // 检查产品是否已选择
@@ -996,27 +848,11 @@ if ($customerId > 0) {
                 
                 hasProducts = true;
                 
-                // 检查规格是否已选择
-                if (!specId && specSelect.is(':visible')) {
-                    allSpecsSelected = false;
-                    if (!firstInvalidField) {
-                        firstInvalidField = specSelect;
-                    }
-                }
-                
-                // 检查单价是否有效
-                if (priceValue === '' || isNaN(parseFloat(priceValue))) {
-                    allPricesValid = false;
+                // 检查总价是否有效
+                if (totalPrice <= 0) {
+                    allTotalPricesValid = false;
                     if (!firstInvalidField) {
-                        firstInvalidField = priceInput;
-                    }
-                }
-                
-                // 检查单价是否大于等于规格价格
-                if (minPrice > 0 && price < minPrice) {
-                    allPricesHighEnough = false;
-                    if (!firstInvalidField) {
-                        firstInvalidField = priceInput;
+                        firstInvalidField = totalPriceInput;
                     }
                 }
             });
@@ -1050,24 +886,8 @@ if ($customerId > 0) {
                 return false;
             }
             
-            if (!allSpecsSelected) {
-                alert('请为所有产品选择规格');
-                if (firstInvalidField) {
-                    firstInvalidField.focus();
-                }
-                return false;
-            }
-            
-            if (!allPricesValid) {
-                alert('请为所有产品输入有效的单价');
-                if (firstInvalidField) {
-                    firstInvalidField.focus();
-                }
-                return false;
-            }
-            
-            if (!allPricesHighEnough) {
-                alert('单价不能低于规格设定的参考价格');
+            if (!allTotalPricesValid) {
+                alert('请为所有产品输入有效的总价');
                 if (firstInvalidField) {
                     firstInvalidField.focus();
                 }

+ 1 - 1
order_details.php

@@ -220,7 +220,7 @@ if (!empty($id) && is_numeric($id)) {
 <!--            <span class="info-label">联系人:</span> --><?php //= htmlspecialcharsFix($order['contact_name']) ?>
 <!--        </div>-->
         <div class="info-row">
-            <span class="info-label">订单日期:</span> <?= date('Y-m-d', strtotime($order['order_date'])) ?>
+            <span class="info-label">出货日期:</span> <?= date('Y-m-d', strtotime($order['order_date'])) ?>
         </div>
         <div class="info-row">
             <span class="info-label">创建时间:</span> <?= $order['created_at'] ?>

+ 75 - 252
order_edit.php

@@ -77,7 +77,7 @@ if (!empty($id) && is_numeric($id)) {
             display: flex;
             align-items: center;
             flex-wrap: wrap;
-            gap: 8px;
+            gap: 20px; /* 增加间距 */
             background-color: #f9f9f9;
             box-shadow: 0 1px 3px rgba(0,0,0,0.1);
         }
@@ -102,7 +102,7 @@ if (!empty($id) && is_numeric($id)) {
             color: white;
         }
         .product-info {
-            flex: 2;
+            flex: 3;
             min-width: 200px;
         }
         .product-spec {
@@ -114,7 +114,7 @@ if (!empty($id) && is_numeric($id)) {
             min-width: 80px;
         }
         .product-unit {
-            flex: 0.5;
+            flex: 0.8;
             min-width: 60px;
         }
         .product-price {
@@ -122,12 +122,12 @@ if (!empty($id) && is_numeric($id)) {
             min-width: 100px;
         }
         .product-total {
-            flex: 1;
+            flex: 1.2;
             min-width: 100px;
             font-weight: bold;
         }
         .product-row input[type="number"] {
-            width: 80px;
+            width: 90%;
             padding: 5px;
             border: 1px solid #ddd;
             border-radius: 4px;
@@ -323,6 +323,9 @@ if (!empty($id) && is_numeric($id)) {
         .customer-clear-btn:hover {
             color: #c0392b;
         }
+        .product-row .total-price-input {
+            width: 90%;
+        }
     </style>
 </head>
 <body>
@@ -352,7 +355,7 @@ if (!empty($id) && is_numeric($id)) {
                 </td>
             </tr>
             <tr>
-                <th width="8%">订单日期</th>
+                <th width="8%">出货日期</th>
                 <td>
                     <input type="date" id="order_date" name="order_date" value="<?= substr($order['order_date'], 0, 10) ?>" class="txt1" />
                 </td>
@@ -362,13 +365,11 @@ if (!empty($id) && is_numeric($id)) {
                 <td>
                     <button type="button" id="add-product-btn" class="add-product-btn">添加产品</button>
                     
-                    <div class="product-list-header" style="display: flex; background-color: #eee; padding: 8px 15px; margin-bottom: 10px; border-radius: 4px; font-weight: bold; color: #555; font-size: 13px; gap: 8px;">
-                        <div style="flex: 2; min-width: 200px;">产品</div>
-                        <div style="flex: 2; min-width: 200px;">规格</div>
+                    <div class="product-list-header" style="display: flex; background-color: #eee; padding: 8px 15px; margin-bottom: 10px; border-radius: 4px; font-weight: bold; color: #555; font-size: 13px; gap: 20px;">
+                        <div style="flex: 3; min-width: 200px;">产品</div>
                         <div style="flex: 1; min-width: 80px;">数量</div>
-                        <div style="flex: 0.5; min-width: 60px;">单位</div>
-                        <div style="flex: 1; min-width: 100px;">单价</div>
-                        <div style="flex: 1; min-width: 100px;">总价</div>
+                        <div style="flex: 0.8; min-width: 60px;">单位</div>
+                        <div style="flex: 1.2; min-width: 100px;">总价</div>
                     </div>
                     
                     <div id="product-container">
@@ -389,20 +390,6 @@ if (!empty($id) && is_numeric($id)) {
                                         </div>
                                     </div>
                                 
-                                <div class="row-section product-spec">
-                                    <div class="row-section-label"><span>规格</span></div>
-                                    <input type="hidden" name="items[<?= $index ?>][spec_id]" class="spec-id-input" value="<?= $item['specification_id'] ?? 0 ?>">
-                                    <!-- 规格选择框将在加载产品时填充 -->
-                                    <select class="spec-select" name="items[<?= $index ?>][spec_select]" style="display: none;">
-                                        <option value="">请选择规格</option>
-                                    </select>
-                                    <div class="spec-info" style="cursor: pointer;" title="点击修改规格">
-                                        <?php if (!empty($item['spec_name'])): ?>
-                                            <?= htmlspecialcharsFix($item['spec_name']) ?>: <?= htmlspecialcharsFix($item['spec_value'] ?? '') ?>
-                                        <?php endif; ?>
-                                    </div>
-                                </div>
-                                
                                 <div class="row-section product-quantity">
                                     <div class="row-section-label"><span>数量</span></div>
                                     <input type="number" name="items[<?= $index ?>][quantity]" value="<?= $item['quantity'] ?>" min="1" class="quantity-input" onchange="calculateItemTotal(this)">
@@ -414,15 +401,9 @@ if (!empty($id) && is_numeric($id)) {
                                     <input type="hidden" name="items[<?= $index ?>][unit]" value="<?= htmlspecialcharsFix($item['unit']) ?>" class="unit-input">
                                 </div>
                                 
-                                <div class="row-section product-price">
-                                    <div class="row-section-label"><span>单价</span></div>
-                                    <input type="number" step="0.01" name="items[<?= $index ?>][unit_price]" value="<?= $item['unit_price'] ?>" class="price-input" onchange="calculateItemTotal(this)">
-                    </div>
-                    
                                 <div class="row-section product-total">
                                     <div class="row-section-label"><span>总价</span></div>
-                                    <span class="total-price-display" style="display: inline-block; background-color: #f0f0f0; border: 1px solid #ddd; padding: 2px 8px; min-width: 60px; text-align: right;"><?= number_format($item['total_price'], 2) ?></span>
-                                    <input type="hidden" name="items[<?= $index ?>][total_price]" value="<?= $item['total_price'] ?>" class="total-price-input">
+                                    <input type="number" step="0.01" name="items[<?= $index ?>][total_price]" value="<?= $item['total_price'] ?>" class="total-price-input" placeholder="输入总价" onchange="calculateOrderTotal()">
                                 </div>
                                 
                                 <!-- 保留隐藏的折扣字段以便后端兼容 -->
@@ -692,6 +673,20 @@ if (!empty($id) && is_numeric($id)) {
                 var categoryTag = $this.find('.category-tag').text();
                 var row = $this.closest('.product-row');
                 
+                // 检查是否已存在相同的产品
+                var isDuplicate = false;
+                $('.product-id-input').not(row.find('.product-id-input')).each(function() {
+                    if ($(this).val() == productId) {
+                        isDuplicate = true;
+                        return false; // 跳出循环
+                    }
+                });
+                
+                if (isDuplicate) {
+                    alert('该产品已添加,不能添加相同的产品');
+                    return;
+                }
+                
                 // 清理产品名称,移除分类信息
                 if (categoryTag) {
                     productName = productName.replace(categoryTag, '').trim();
@@ -715,6 +710,32 @@ if (!empty($id) && is_numeric($id)) {
                 getProductSpecifications(productId, row);
             });
             
+            // 点击已选产品名显示的标签时,切换回搜索模式
+            $(document).on('click dblclick', '.selected-product-info', function() {
+                var row = $(this).closest('.product-row');
+                var productId = row.find('.product-id-input').val();
+                
+                // 只有当已经选择了产品时才允许重新选择
+                if (productId) {
+                    if (confirm('确定要重新选择产品吗?这将清除当前选择的产品信息。')) {
+                        // 清空产品ID
+                        row.find('.product-id-input').val('');
+                        
+                        // 隐藏产品信息,显示搜索框
+                        $(this).hide();
+                        row.find('.product-search').val('').show();
+                        
+                        // 清除单位信息
+                        row.find('.unit-input').val('');
+                        row.find('.unit-label').text('');
+                        
+                        // 清除总价信息并重新计算总额
+                        row.find('.total-price-input').val('0.00');
+                        calculateOrderTotal();
+                    }
+                }
+            });
+            
             // 规格选择改变事件
             $(document).on('change', '.spec-select', function() {
                 var $this = $(this);
@@ -786,49 +807,6 @@ if (!empty($id) && is_numeric($id)) {
                     $('#customer_dropdown').hide();
                 }
             });
-            
-            // 点击已选产品名显示的标签时,切换回搜索模式
-            $(document).on('click dblclick', '.selected-product-info', function() {
-                var row = $(this).closest('.product-row');
-                var productId = row.find('.product-id-input').val();
-                
-                // 只有当已经选择了产品时才允许重新选择
-                if (productId) {
-                    if (confirm('确定要重新选择产品吗?这将清除当前选择的产品及其规格信息。')) {
-                        // 清空产品ID和选择的规格
-                        row.find('.product-id-input').val('');
-                        row.find('.spec-id-input').val('');
-                        
-                        // 隐藏产品信息,显示搜索框
-                        $(this).hide();
-                        row.find('.product-search').val('').show();
-                        
-                        // 隐藏并清空规格选择
-                        row.find('.spec-select').hide().empty();
-                        row.find('.spec-info').html('');
-                        
-                        // 清除单位信息
-                        row.find('.unit-input').val('');
-                        row.find('.unit-label').text('');
-                        
-                        // 清除价格信息并重新计算总额
-                        row.find('.price-input').val('');
-                        calculateItemTotal(row.find('.price-input')[0]);
-                    }
-                }
-            });
-            
-            // 点击规格信息时显示规格选择下拉框
-            $(document).on('click', '.spec-info', function() {
-                var row = $(this).closest('.product-row');
-                var specSelect = row.find('.spec-select');
-                
-                if (specSelect.find('option').length > 1) {
-                    // 隐藏规格信息,显示规格选择下拉框
-                    $(this).hide();
-                    specSelect.show().focus();
-                }
-            });
         });
 
         function addEmptyProductRow() {
@@ -844,18 +822,9 @@ if (!empty($id) && is_numeric($id)) {
                     <div class="selected-product-info" style="cursor: pointer; display: none;" title="点击重新选择产品"></div>
                 </div>
                 
-                <div class="row-section product-spec">
-                    <div class="row-section-label"><span>规格</span></div>
-                    <input type="hidden" name="items[${productIndex}][spec_id]" class="spec-id-input" value="">
-                    <select class="spec-select" name="items[${productIndex}][spec_select]" style="display: none;">
-                        <option value="">请选择规格</option>
-                    </select>
-                    <div class="spec-info" style="cursor: pointer;" title="点击修改规格"></div>
-                </div>
-                
                 <div class="row-section product-quantity">
                     <div class="row-section-label"><span>数量</span></div>
-                    <input type="number" name="items[${productIndex}][quantity]" value="1" min="1" class="quantity-input" onchange="calculateItemTotal(this)">
+                    <input type="number" name="items[${productIndex}][quantity]" value="1" min="1" class="quantity-input">
                 </div>
                 
                 <div class="row-section product-unit">
@@ -864,15 +833,9 @@ if (!empty($id) && is_numeric($id)) {
                     <input type="hidden" name="items[${productIndex}][unit]" class="unit-input" value="">
                 </div>
                 
-                <div class="row-section product-price">
-                    <div class="row-section-label"><span>单价</span></div>
-                    <input type="number" step="0.01" name="items[${productIndex}][unit_price]" value="" class="price-input" placeholder="输入单价" onchange="calculateItemTotal(this)">
-                </div>
-                
                 <div class="row-section product-total">
                     <div class="row-section-label"><span>总价</span></div>
-                    <span class="total-price-display" style="display: inline-block; background-color: #f0f0f0; border: 1px solid #ddd; padding: 2px 8px; min-width: 60px; text-align: right;">0.00</span>
-                    <input type="hidden" name="items[${productIndex}][total_price]" value="0.00" class="total-price-input">
+                    <input type="number" step="0.01" name="items[${productIndex}][total_price]" value="0.00" class="total-price-input" placeholder="输入总价" onchange="calculateOrderTotal()">
                 </div>
                 
                 <!-- 保留隐藏的字段以便后端兼容 -->
@@ -937,111 +900,26 @@ if (!empty($id) && is_numeric($id)) {
                 data: {product_id: productId},
                 dataType: 'json',
                 success: function(data) {
-                    if (data && data.product && data.specifications) {
-                        console.log("获取到规格数据:", data.specifications);
+                    if (data && data.product) {
                         // 设置单位信息
                         if (data.product.unit) {
                             row.find('.unit-input').val(data.product.unit);
                             row.find('.unit-label').text(data.product.unit);
                         }
-                        
-                        // 处理规格信息
-                        var specifications = data.specifications;
-                        console.log("获取到的规格列表详情:", JSON.stringify(specifications)); // 打印完整的规格对象
-                        if (specifications.length === 0) {
-                            // 如果是编辑现有产品,不显示警告
-                            if (!currentSpecId) {
-                                alert('此产品没有规格信息,请添加规格后再选择');
-                                // 重置产品选择
-                                row.find('.product-id-input').val('');
-                                row.find('.selected-product-info').hide();
-                                row.find('.product-search').val('').show();
-                            }
-                            return;
-                        }
-                        
-                        // 填充规格选择下拉框
-                        var specSelect = row.find('.spec-select');
-                        specSelect.empty();
-                        specSelect.append('<option value="">请选择规格</option>');
-                        
-                        var foundSelectedSpec = false;
-                        
-                        $.each(specifications, function(i, spec) {
-                            var displayText = spec.spec_name + ': ' + spec.spec_value;
-                            if (spec.price) {
-                                displayText += ' (¥' + spec.price + ')';
-                            }
-                            
-                            var option = $('<option></option>')
-                                .attr('value', spec.id)
-                                .text(displayText)
-                                .data('price', spec.price)
-                                .data('minQty', spec.min_order_quantity)
-                                .data('code', spec.spec_code);
-                            
-                            // 如果是当前选中的规格,设置selected属性
-                            if (currentSpecId && parseInt(spec.id) === parseInt(currentSpecId)) {
-                                console.log("找到匹配的规格 - 规格ID:", spec.id, "当前规格ID:", currentSpecId, 
-                                           "规格名称:", spec.spec_name, "规格值:", spec.spec_value);
-                                option.prop('selected', true);
-                                foundSelectedSpec = true;
-                                
-                                // 更新规格信息显示
-                                row.find('.spec-info').html(displayText);
-                                
-                                // 设置参考价格
-                                var priceInput = row.find('.price-input');
-                                priceInput.attr('data-min-price', spec.price || 0);
-                            } else {
-                                console.log("规格不匹配 - 规格ID:", spec.id, "当前规格ID:", currentSpecId, 
-                                           "类型:", typeof spec.id, typeof currentSpecId);
-                            }
-                            
-                            specSelect.append(option);
-                        });
-                        
-                        // 显示规格选择下拉框并隐藏spec-info
-                        if (!currentSpecId || !foundSelectedSpec) {
-                            // 如果没有选中规格,显示下拉框
-                            specSelect.show();
-                            row.find('.spec-info').hide();
-                        } else {
-                            // 如果已选中规格,显示规格信息
-                            specSelect.hide();
-                            row.find('.spec-info').show();
-                        }
-                        
-                        // 如果在规格列表中找不到已选择的规格
-                        if (currentSpecId && !foundSelectedSpec) {
-                            console.log("在规格列表中找不到已选择的规格ID:", currentSpecId);
-                            // 不清除规格ID,保留数据库中的值
-                            // row.find('.spec-id-input').val('');
-                            
-                            // 隐藏规格选择下拉框,保留现有规格信息
-                            specSelect.hide();
-                            row.find('.spec-info').show();
-                        }
                     } else {
-                        // 如果是编辑现有产品,不显示警告
-                        if (!currentSpecId) {
-                            alert('获取产品规格失败');
-                            // 重置产品选择
-                            row.find('.product-id-input').val('');
-                            row.find('.selected-product-info').hide();
-                            row.find('.product-search').val('').show();
-                        }
-                    }
-                },
-                error: function() {
-                    // 如果是编辑现有产品,不显示警告
-                    if (!currentSpecId) {
-                        alert('获取产品规格失败,请重试');
+                        alert('获取产品信息失败');
                         // 重置产品选择
                         row.find('.product-id-input').val('');
                         row.find('.selected-product-info').hide();
                         row.find('.product-search').val('').show();
                     }
+                },
+                error: function() {
+                    alert('获取产品信息失败,请重试');
+                    // 重置产品选择
+                    row.find('.product-id-input').val('');
+                    row.find('.selected-product-info').hide();
+                    row.find('.product-search').val('').show();
                 }
             });
         }
@@ -1063,29 +941,12 @@ if (!empty($id) && is_numeric($id)) {
                             //默认不设置单价
                             //row.find('.price-input').val(data.price);
                         }
-                        calculateItemTotal(row.find('.price-input')[0]);
+                        calculateOrderTotal();
                     }
                 }
             });
         }
 
-        function calculateItemTotal(element) {
-            var row = $(element).closest('.product-row');
-            var quantity = parseInt(row.find('.quantity-input').val()) || 0;
-            var priceInput = row.find('.price-input');
-            var priceValue = priceInput.val().trim();
-            var price = (priceValue === '') ? 0 : (parseFloat(priceValue) || 0);
-
-            var total = quantity * price;
-            if (total < 0) total = 0;
-
-            // 更新显示元素和隐藏输入框
-            row.find('.total-price-display').text(total.toFixed(2));
-            row.find('.total-price-input').val(total.toFixed(2));
-
-            calculateOrderTotal();
-        }
-
         function calculateOrderTotal() {
             var total = 0;
             $('.total-price-input').each(function() {
@@ -1103,9 +964,7 @@ if (!empty($id) && is_numeric($id)) {
             var customerId = $('#customer_id').val();
             var customerName = $('#customer_search').val() || $('#customer_selected').text().trim();
             var hasProducts = false;
-            var allSpecsSelected = true;
-            var allPricesValid = true;
-            var allPricesHighEnough = true;
+            var allTotalPricesValid = true;
             var firstInvalidField = null;
 
             // 检查是否有产品行
@@ -1117,12 +976,8 @@ if (!empty($id) && is_numeric($id)) {
 
             $('.product-row').each(function() {
                 var productId = $(this).find('.product-id-input').val();
-                var specId = $(this).find('.spec-id-input').val();
-                var priceInput = $(this).find('.price-input');
-                var priceValue = priceInput.val().trim();
-                var price = parseFloat(priceValue) || 0;
-                var minPrice = parseFloat(priceInput.attr('data-min-price')) || 0;
-                var specSelect = $(this).find('.spec-select');
+                var totalPriceInput = $(this).find('.total-price-input');
+                var totalPrice = parseFloat(totalPriceInput.val()) || 0;
                 var productSearch = $(this).find('.product-search');
                 
                 // 检查产品是否已选择
@@ -1135,27 +990,11 @@ if (!empty($id) && is_numeric($id)) {
                 
                 hasProducts = true;
                 
-                // 检查规格是否已选择
-                if (!specId && specSelect.is(':visible')) {
-                    allSpecsSelected = false;
+                // 检查总价是否有效
+                if (totalPrice <= 0) {
+                    allTotalPricesValid = false;
                     if (!firstInvalidField) {
-                        firstInvalidField = specSelect;
-                    }
-                }
-                
-                // 检查单价是否有效
-                if (priceValue === '' || isNaN(parseFloat(priceValue))) {
-                    allPricesValid = false;
-                    if (!firstInvalidField) {
-                        firstInvalidField = priceInput;
-                    }
-                }
-                
-                // 检查单价是否大于等于规格价格
-                if (minPrice > 0 && price < minPrice) {
-                    allPricesHighEnough = false;
-                    if (!firstInvalidField) {
-                        firstInvalidField = priceInput;
+                        firstInvalidField = totalPriceInput;
                     }
                 }
             });
@@ -1188,24 +1027,8 @@ if (!empty($id) && is_numeric($id)) {
                 return false;
             }
             
-            if (!allSpecsSelected) {
-                alert('请为所有产品选择规格');
-                if (firstInvalidField) {
-                    firstInvalidField.focus();
-                }
-                return false;
-            }
-            
-            if (!allPricesValid) {
-                alert('请为所有产品输入有效的单价');
-                if (firstInvalidField) {
-                    firstInvalidField.focus();
-                }
-                return false;
-            }
-            
-            if (!allPricesHighEnough) {
-                alert('单价不能低于规格设定的参考价格');
+            if (!allTotalPricesValid) {
+                alert('请为所有产品输入有效的总价');
                 if (firstInvalidField) {
                     firstInvalidField.focus();
                 }

+ 10 - 156
order_save.php

@@ -46,9 +46,8 @@ $discount_amount = !empty($_POST['discount_amount']) ? (float)$_POST['discount_a
 
 foreach ($items as $item) {
     $quantity = (int)$item['quantity'];
-    $unit_price = (float)$item['unit_price'];
-    $item_total = $quantity * $unit_price;
-    $subtotal += $item_total;
+    $total_price = (float)$item['total_price']; // 直接使用用户输入的总价
+    $subtotal += $total_price;
 }
 
 $total_amount = $subtotal - $discount_amount;
@@ -116,79 +115,6 @@ if ($customer_result && mysqli_num_rows($customer_result) > 0) {
 // 处理保存
 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'];
-        $spec_id = isset($item['spec_id']) ? (int)$item['spec_id'] : 0;
-        $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,检查规格价格
-        if ($spec_id > 0) {
-
-            //先判断是否国家有特殊规格
-
-
-            $spec_result=null;
-            if($customer_country>0) {
-                $spec_query = "SELECT pcp.price,pcp.min_order_quantity, ps.spec_name, ps.spec_value FROM product_country_price pcp
-                                    left join product_specifications ps on pcp.specification_id=ps.id
-                          WHERE pcp.specification_id = $spec_id  AND pcp.country_id = $customer_country
-                          LIMIT 1";
-                $spec_result = mysqli_query($conn, $spec_query);
-            }
-
-            if (mysqli_num_rows($spec_result) < 1) {
-                $spec_query = "SELECT price, spec_name, spec_value FROM product_specifications 
-                          WHERE id = $spec_id AND product_id = $product_id 
-                          LIMIT 1";
-
-                $spec_result = mysqli_query($conn, $spec_query);
-            }
-            
-            if (mysqli_num_rows($spec_result) > 0) {
-                $spec_row = mysqli_fetch_assoc($spec_result);
-                $min_price = (float)$spec_row['price'];
-                
-                // 如果单价低于规格价格,标记错误
-                if ($min_price > 0 && $unit_price < $min_price) {
-                    $price_error = true;
-                    $error_product_name = $product_name . " (" . $spec_row['spec_name'] . ": " . $spec_row['spec_value'] . ")";
-                    $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 
             order_code = '$order_code', 
@@ -220,11 +146,11 @@ if ($isedit) {
         if (empty($item['product_id'])) continue; // 跳过没有选择产品的行
 
         $product_id = (int)$item['product_id'];
-        $spec_id = isset($item['spec_id']) ? (int)$item['spec_id'] : 0; // 添加规格ID
         $quantity = (int)$item['quantity'];
         $unit = mysqli_real_escape_string($conn, htmlspecialchars($item['unit'], ENT_QUOTES, 'UTF-8'));
-        $unit_price = (float)$item['unit_price'];
-        $total_price = $quantity * $unit_price;
+        $total_price = (float)$item['total_price'];
+        // 如果数量大于0,计算单价,否则单价为0
+        $unit_price = ($quantity > 0) ? ($total_price / $quantity) : 0;
         $item_notes = mysqli_real_escape_string($conn, htmlspecialchars($item['notes'] ?? '', ENT_QUOTES, 'UTF-8'));
 
         $sql = "INSERT INTO order_items (
@@ -232,7 +158,7 @@ if ($isedit) {
                 total_price, notes, 
                 created_at, updated_at
             ) VALUES (
-                $id, $product_id, $spec_id, $quantity, '$unit', $unit_price, 
+                $id, $product_id, 0, $quantity, '$unit', $unit_price, 
                 $total_price, '$item_notes', 
                 NOW(), NOW()
             )";
@@ -243,78 +169,6 @@ if ($isedit) {
     $message = "订单更新成功!";
 } 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'];
-        $spec_id = isset($item['spec_id']) ? (int)$item['spec_id'] : 0;
-        $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,检查规格价格
-        if ($spec_id > 0) {
-
-            //先判断是否国家有特殊规格
-
-            $spec_result=null;
-            if($customer_country>0) {
-                $spec_query = "SELECT pcp.price,pcp.min_order_quantity, ps.spec_name, ps.spec_value FROM product_country_price pcp
-                                    left join product_specifications ps on pcp.specification_id=ps.id
-                          WHERE pcp.specification_id = $spec_id  AND pcp.country_id = $customer_country
-                          LIMIT 1";
-                $spec_result = mysqli_query($conn, $spec_query);
-            }
-
-            if (mysqli_num_rows($spec_result) < 1) {
-                $spec_query = "SELECT price, spec_name, spec_value FROM product_specifications 
-                          WHERE id = $spec_id AND product_id = $product_id 
-                          LIMIT 1";
-
-                $spec_result = mysqli_query($conn, $spec_query);
-            }
-            
-            if (mysqli_num_rows($spec_result) > 0) {
-                $spec_row = mysqli_fetch_assoc($spec_result);
-                $min_price = (float)$spec_row['price'];
-                
-                // 如果单价低于规格价格,标记错误
-                if ($min_price > 0 && $unit_price < $min_price) {
-                    $price_error = true;
-                    $error_product_name = $product_name . " (" . $spec_row['spec_name'] . ": " . $spec_row['spec_value'] . ")";
-                    $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 = "INSERT INTO orders (
             order_code, customer_id, contact_id, employee_id, 
@@ -338,11 +192,11 @@ if ($isedit) {
         if (empty($item['product_id'])) continue; // 跳过没有选择产品的行
 
         $product_id = (int)$item['product_id'];
-        $spec_id = isset($item['spec_id']) ? (int)$item['spec_id'] : 0; // 添加规格ID
         $quantity = (int)$item['quantity'];
         $unit = mysqli_real_escape_string($conn, htmlspecialchars($item['unit'], ENT_QUOTES, 'UTF-8'));
-        $unit_price = (float)$item['unit_price'];
-        $total_price = $quantity * $unit_price;
+        $total_price = (float)$item['total_price'];
+        // 如果数量大于0,计算单价,否则单价为0
+        $unit_price = ($quantity > 0) ? ($total_price / $quantity) : 0;
         $item_notes = mysqli_real_escape_string($conn, htmlspecialchars($item['notes'] ?? '', ENT_QUOTES, 'UTF-8'));
 
         $sql = "INSERT INTO order_items (
@@ -350,7 +204,7 @@ if ($isedit) {
                 total_price, notes, 
                 created_at, updated_at
             ) VALUES (
-                $order_id, $product_id, $spec_id, $quantity, '$unit', $unit_price, 
+                $order_id, $product_id, 0, $quantity, '$unit', $unit_price, 
                 $total_price, '$item_notes', 
                 NOW(), NOW()
             )";

+ 1 - 1
panel.php

@@ -43,7 +43,7 @@ $stmt->close();
                 <dt><a href="../home.php" target="contentFrame">客户查找</a></dt>
             <?php endif; ?>
             <dt><a href="../customerAdd.php" target="contentFrame">客户录入</a></dt>
-            <dt><a href="relationships.php" target="contentFrame">客户关系</a></dt>
+            <!-- <dt><a href="relationships.php" target="contentFrame">客户关系</a></dt> -->
             <dt><a href="../order.php" target="contentFrame">订单管理</a></dt>
             <dt id="myCustomer" class="subnav">我的客户
                 <div class="list-wraper">

+ 109 - 0
save_relationship.php

@@ -0,0 +1,109 @@
+<?php
+require_once 'conn.php';
+checkLogin();
+
+header('Content-Type: application/json');
+
+// 验证必要的字段
+if (
+    !isset($_POST['source_customer_id']) || !is_numeric($_POST['source_customer_id']) ||
+    !isset($_POST['target_customer_id']) || !is_numeric($_POST['target_customer_id']) ||
+    !isset($_POST['relationship_type']) || !is_numeric($_POST['relationship_type'])
+) {
+    echo json_encode(['success' => false, 'message' => '参数错误']);
+    exit;
+}
+
+$sourceId = intval($_POST['source_customer_id']);
+$targetId = intval($_POST['target_customer_id']);
+$relationType = intval($_POST['relationship_type']);
+$relationStatus = isset($_POST['relationship_status']) ? intval($_POST['relationship_status']) : 1;
+$description = isset($_POST['description']) ? mysqli_real_escape_string($conn, $_POST['description']) : '';
+$id = isset($_POST['id']) && !empty($_POST['id']) ? intval($_POST['id']) : null;
+$employeeId = $_SESSION['employee_id'];
+
+$isAdmin = checkIfAdmin();
+
+// 验证权限
+if (!$isAdmin) {
+    // 检查当前用户是否是源客户的负责人
+    $customerSql = "SELECT id FROM customer WHERE id = $sourceId AND cs_belong = $employeeId";
+    $customerResult = mysqli_query($conn, $customerSql);
+    
+    if (mysqli_num_rows($customerResult) == 0) {
+        echo json_encode(['success' => false, 'message' => '您没有权限操作此客户关系']);
+        exit;
+    }
+    
+    // 如果是编辑,还需要验证是否有权限修改
+    if ($id) {
+        $checkSql = "SELECT source_customer_id FROM customer_relationship WHERE id = $id";
+        $checkResult = mysqli_query($conn, $checkSql);
+        
+        if ($checkRow = mysqli_fetch_assoc($checkResult)) {
+            $existingSourceId = $checkRow['source_customer_id'];
+            
+            // 检查现有关系的源客户是否是当前用户负责的
+            if ($existingSourceId != $sourceId) {
+                $sourceCheckSql = "SELECT id FROM customer WHERE id = $existingSourceId AND cs_belong = $employeeId";
+                $sourceResult = mysqli_query($conn, $sourceCheckSql);
+                
+                if (mysqli_num_rows($sourceResult) == 0) {
+                    echo json_encode(['success' => false, 'message' => '您没有权限修改此客户关系']);
+                    exit;
+                }
+            }
+        }
+    }
+}
+
+// 检查源客户和目标客户是否相同
+if ($sourceId == $targetId) {
+    echo json_encode(['success' => false, 'message' => '源客户和目标客户不能是同一个']);
+    exit;
+}
+
+// 检查是否已存在相同的关系
+$checkDuplicateSql = "SELECT id FROM customer_relationship WHERE 
+                      ((source_customer_id = $sourceId AND target_customer_id = $targetId) OR 
+                       (source_customer_id = $targetId AND target_customer_id = $sourceId))";
+
+// 如果是编辑模式,需要排除当前记录
+if ($id) {
+    $checkDuplicateSql .= " AND id != $id";
+}
+
+$duplicateResult = mysqli_query($conn, $checkDuplicateSql);
+
+if (mysqli_num_rows($duplicateResult) > 0) {
+    echo json_encode(['success' => false, 'message' => '已存在相同的客户关系']);
+    exit;
+}
+
+// 创建或更新关系
+if ($id) {
+    // 更新现有关系
+    $sql = "UPDATE customer_relationship SET 
+            source_customer_id = $sourceId,
+            target_customer_id = $targetId,
+            relationship_type = $relationType,
+            relationship_status = $relationStatus,
+            description = '$description',
+            updated_at = NOW()
+            WHERE id = $id";
+} else {
+    // 创建新关系
+    $sql = "INSERT INTO customer_relationship 
+            (source_customer_id, target_customer_id, relationship_type, relationship_status, description, employee_id, created_at, updated_at) 
+            VALUES ($sourceId, $targetId, $relationType, $relationStatus, '$description', $employeeId, NOW(), NOW())";
+}
+
+$result = mysqli_query($conn, $sql);
+
+if ($result) {
+    $relationId = $id ?: mysqli_insert_id($conn);
+    echo json_encode(['success' => true, 'id' => $relationId, 'message' => '保存成功']);
+} else {
+    echo json_encode(['success' => false, 'message' => '保存失败: ' . mysqli_error($conn)]);
+}
+?> 

+ 4 - 4
statistics_order_warnings.php

@@ -180,7 +180,7 @@ include('statistics_header.php');
                     <th>本期订单金额</th>
                     <th>上期订单金额</th>
                     <th>变化百分比</th>
-                    <th>最近订单日期</th>
+                    <th>最近出货日期</th>
                     <th>业务员</th>
                     <th>操作</th>
                 </tr>
@@ -235,7 +235,7 @@ include('statistics_header.php');
                     <th>平均复购周期(天)</th>
                     <th>最近复购周期(天)</th>
                     <th>偏离正常值</th>
-                    <th>最近订单日期</th>
+                    <th>最近出货日期</th>
                     <th>订单总数</th>
                     <th>业务员</th>
                     <th>操作</th>
@@ -291,7 +291,7 @@ include('statistics_header.php');
                 <tr>
                     <th>客户编码</th>
                     <th>客户名称</th>
-                    <th>最后订单日期</th>
+                    <th>最后出货日期</th>
                     <th>不活跃天数</th>
                     <th>历史订单数</th>
                     <th>历史订单总额</th>
@@ -643,7 +643,7 @@ include('statistics_header.php');
     width: 20%;
 }
 
-#inactive-customers .data-table th:nth-child(3), /* 最后订单日期 */
+#inactive-customers .data-table th:nth-child(3), /* 最后出货日期 */
 #inactive-customers .data-table td:nth-child(3) {
     width: 12%;
 }

+ 77 - 16
system/add_product.php

@@ -15,6 +15,7 @@ $note = '';
 $tips = '';
 $keys = isset($_GET['Keys']) ? urlencode($_GET['Keys']) : '';
 $page = isset($_GET['Page']) ? $_GET['Page'] : 1;
+$rebate = 0; // 默认不启用返点
 
 // Get the return URL
 $href_str = "products.php?keys=" . $keys . "&Page=" . $page;
@@ -136,26 +137,28 @@ if ($category_id) {
 <!--                    <td><input type="text" id="moq" name="moq" value="--><?php //echo $moq; ?><!--" class="txt1"/></td>-->
 <!--                </tr>-->
                 <tr>
-                    <th width="8%">产品规格</th>
+                    <th width="8%">启用返点</th>
+                    <td>
+                        <label><input type="radio" name="rebate" value="1" <?php echo $rebate == 1 ? 'checked' : ''; ?> /> 启用</label>
+                        <label style="margin-left: 20px;"><input type="radio" name="rebate" value="0" <?php echo $rebate == 0 ? 'checked' : ''; ?> /> 不启用</label>
+                    </td>
+                </tr>
+                <tr id="rebate_settings">
+                    <th width="8%">返点设置</th>
                     <td>
                         <div class="specifications">
                             <div class="specitem">
-                                <span class="spec-label">规格名称<span class="required">*</span>:</span>
-                                <input type="text" class="spec-input" name="spec_name[]" placeholder="如: 红色、XL" required>
+                                <span class="spec-label">最低采购数量<span class="required">*</span>:</span>
+                                <input type="number" class="spec-small-input" name="min_quantity[]" value="1" required>
                                 
-                                <span class="spec-label">起订数量<span class="required">*</span>:</span>
-                                <input type="number" class="spec-small-input" name="spec_moq[]" value="1" required>
-                                
-                                <span class="spec-label">规格价格<span class="required">*</span>:</span>
-                                <input type="text" class="spec-small-input" name="spec_price[]" placeholder="价格" required>
+                                <span class="spec-label">单件返点金额<span class="required">*</span>:</span>
+                                <input type="text" class="spec-small-input" name="rebate_amount[]" placeholder="返点金额" value="0" required>
                                 
                                 <span class="addspecitem">+</span>
                                 <span class="delspecitem">-</span>
                                 
                                 <!-- 隐藏字段,仍然提交但不显示 -->
-                                <input type="hidden" name="spec_value[]" value="">
-                                <input type="hidden" name="spec_code[]" value="">
-                                <input type="hidden" name="spec_sort[]" value="0">
+                                <input type="hidden" name="rebate_id[]" value="0">
                             </div>
                         </div>
                     </td>
@@ -191,21 +194,21 @@ if ($category_id) {
 
 <script>
     $(document).ready(function(){
-        // Add specification item
+        // Add rebate rule item
         $(document).on('click', '.addspecitem', function(){
             var newSpecItem = $(this).closest('.specitem').clone(true);
             newSpecItem.find('input[type="text"], input[type="hidden"]').val(''); // Clear values
-            newSpecItem.find('input[name="spec_moq[]"]').val('1'); // Reset MOQ to 1
-            newSpecItem.find('input[name="spec_sort[]"]').val('0'); // Reset sort to 0
+            newSpecItem.find('input[name="min_quantity[]"]').val('1'); // Reset min quantity to 1
+            newSpecItem.find('input[name="rebate_id[]"]').val('0'); // Set ID to 0 for new rebate rules
             $(this).closest('.specifications').append(newSpecItem);
         });
         
-        // Remove specification item
+        // Remove rebate rule item
         $(document).on('click', '.delspecitem', function(){
             if($('.specitem').length > 1){
                 $(this).closest('.specitem').remove();
             } else {
-                alert('至少需要保留一个规格项');
+                alert('至少需要保留一个返点规则');
             }
         });
         
@@ -213,6 +216,64 @@ if ($category_id) {
         $('#unit').on('change keyup', function(){
             $('.unit').text($(this).val());
         });
+        
+        // 验证最低采购数量不重复且返点金额符合规则
+        $('form[name="form1"]').on('submit', function(e){
+            // 检查是否有重复的最低采购数量
+            var quantities = [];
+            var hasError = false;
+            
+            // 收集并检查所有数量值
+            $('input[name="min_quantity[]"]').each(function(){
+                var quantity = parseInt($(this).val());
+                if(quantities.includes(quantity)) {
+                    alert('错误:存在重复的最低采购数量 ' + quantity + ',请修改!');
+                    $(this).focus();
+                    hasError = true;
+                    return false; // 跳出循环
+                }
+                quantities.push(quantity);
+            });
+            
+            if(hasError) {
+                e.preventDefault();
+                return false;
+            }
+            
+            // 按最低采购数量排序规则
+            var rules = [];
+            $('.specitem').each(function(){
+                var quantity = parseInt($(this).find('input[name="min_quantity[]"]').val());
+                var amount = parseFloat($(this).find('input[name="rebate_amount[]"]').val());
+                rules.push({
+                    element: $(this),
+                    quantity: quantity,
+                    amount: amount
+                });
+            });
+            
+            // 按数量从小到大排序
+            rules.sort(function(a, b){
+                return a.quantity - b.quantity;
+            });
+            
+            // 检查返点金额规则:数量越多,返点金额应大于等于数量小的
+            for(var i = 1; i < rules.length; i++) {
+                if(rules[i].amount < rules[i-1].amount) {
+                    alert('错误:最低采购数量为 ' + rules[i].quantity + ' 的返点金额不能小于最低采购数量为 ' + rules[i-1].quantity + ' 的返点金额!');
+                    rules[i].element.find('input[name="rebate_amount[]"]').focus();
+                    hasError = true;
+                    break;
+                }
+            }
+            
+            if(hasError) {
+                e.preventDefault();
+                return false;
+            }
+            
+            return true;
+        });
     });
 </script>
 

+ 3 - 3
system/edit_product.php

@@ -42,7 +42,7 @@ $nosale = $row['nosale'];
 $note = htmlspecialcharsFix($row['note']);
 $tips = htmlspecialcharsFix($row['tips']);
 $category_id = $row['category_id'] ? intval($row['category_id']) : 0;
-$rebate = isset($row['rebate']) ? intval($row['rebate']) : 1; // 默认启用返点
+$rebate = isset($row['rebate']) ? intval($row['rebate']) : 0; // 默认不启用返点
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
@@ -192,14 +192,14 @@ $rebate = isset($row['rebate']) ? intval($row['rebate']) : 1; // 默认启用返
                                 <?php
                             }
                         } else {
-                            // No rebate rules found, show one empty form
+                            // No rebate rules found, show one default form with quantity=1 and rebate=0
                             ?>
                             <div class="specitem">
                                 <span class="spec-label">最低采购数量<span class="required">*</span>:</span>
                                 <input type="number" class="spec-small-input" name="min_quantity[]" value="1" required>
                                 
                                 <span class="spec-label">单件返点金额<span class="required">*</span>:</span>
-                                <input type="text" class="spec-small-input" name="rebate_amount[]" placeholder="返点金额" required>
+                                <input type="text" class="spec-small-input" name="rebate_amount[]" placeholder="返点金额" value="0" required>
                                 
                                 <span class="addspecitem">+</span>
                                 <span class="delspecitem">-</span>

+ 6 - 6
system/products.php

@@ -211,7 +211,7 @@ $temp_num = $pageSize * ($page - 1);
                 <th width="25%">产品名称</th>
                 <th width="15%">产品分类</th>
                 <th width="30%">图片</th>
-                <th width="10%">规格数量</th>
+                <th width="10%">返点规则数量</th>
                 <th width="20%">操作</th>
             </tr>
         </thead>
@@ -235,11 +235,11 @@ $temp_num = $pageSize * ($page - 1);
                     <td align="center"><img src="<?php echo htmlspecialcharsFix($row['ProductImg']); ?>" width="30px"></td>
                     <td align="center">
                         <?php 
-                        // Count specifications for this product
-                        $spec_sql = "SELECT COUNT(*) as spec_count FROM product_specifications WHERE product_id = " . $row['id'];
-                        $spec_result = mysqli_query($conn, $spec_sql);
-                        $spec_row = mysqli_fetch_assoc($spec_result);
-                        echo $spec_row['spec_count']; 
+                        // Count rebate rules for this product (only where rebate_amount > 0)
+                        $rebate_sql = "SELECT COUNT(*) as rebate_count FROM rebate_rules WHERE product_id = " . $row['id'] . " AND rebate_amount > 0";
+                        $rebate_result = mysqli_query($conn, $rebate_sql);
+                        $rebate_row = mysqli_fetch_assoc($rebate_result);
+                        echo $rebate_row['rebate_count']; 
                         ?>
                     </td>
                     <td align="center">