Explorar el Código

fleat: update add product

igb hace 3 días
padre
commit
e7f37472ea
Se han modificado 2 ficheros con 79 adiciones y 18 borrados
  1. 77 16
      system/add_product.php
  2. 2 2
      system/edit_product.php

+ 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 = 1; // 默认启用返点
 
 // 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>
 

+ 2 - 2
system/edit_product.php

@@ -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>