Browse Source

fleat: order type

igb 12 hours ago
parent
commit
0cfbf125c1
6 changed files with 64 additions and 2 deletions
  1. 21 0
      order_add.php
  2. 21 0
      order_edit.php
  3. 9 2
      order_save.php
  4. 3 0
      rebate_expiring.php
  5. 5 0
      rebate_redeem.php
  6. 5 0
      rebate_summary.php

+ 21 - 0
order_add.php

@@ -319,6 +319,19 @@ if ($customerId > 0) {
                 <th width="8%" nowrap>销售订单号</th>
                 <td><input type="text" id="order_code" name="order_code" value="" class="txt1" placeholder="请输入销售订单号 (多个用 / 分隔) " maxlength="100" /></td>
             </tr>
+            <tr>
+                <th width="8%" nowrap>订单类型</th>
+                <td>
+                    <div style="display: flex; gap: 20px;">
+                        <label style="display: flex; align-items: center;">
+                            <input type="radio" name="order_type" id="order_type_1" value="1"> 普通订单
+                        </label>
+                        <label style="display: flex; align-items: center;">
+                            <input type="radio" name="order_type" id="order_type_2" value="2"> 定制订单
+                        </label>
+                    </div>
+                </td>
+            </tr>
             <tr>
                 <th width="8%" nowrap>客户选择</th>
                 <td>
@@ -821,6 +834,7 @@ if ($customerId > 0) {
             var orderCode = $('#order_code').val();
             var customerId = $('#customer_id').val();
             var customerName = $('#customer_search').val();
+            var orderType = $('input[name="order_type"]:checked').val();
             var hasProducts = false;
             var allTotalPricesValid = true;
             var firstInvalidField = null;
@@ -833,6 +847,13 @@ if ($customerId > 0) {
                 return false;
             }
 
+            // 检查订单类型是否已选择
+            if (!orderType) {
+                alert('请选择订单类型');
+                $('#order_type_1').focus();
+                return false;
+            }
+            
             $('.product-row').each(function() {
                 var productId = $(this).find('.product-id-input').val();
                 var totalPriceInput = $(this).find('.total-price-input');

+ 21 - 0
order_edit.php

@@ -340,6 +340,19 @@ if (!empty($id) && is_numeric($id)) {
                     <input type="hidden" name="id" value="<?= $id ?>" />
                 </td>
             </tr>
+            <tr>
+                <th width="8%">订单类型</th>
+                <td>
+                    <div style="display: flex; gap: 20px;">
+                        <label style="display: flex; align-items: center;">
+                            <input type="radio" name="order_type" id="order_type_1" value="1" <?= ($order['order_type'] == 1) ? 'checked' : '' ?>> 普通订单
+                        </label>
+                        <label style="display: flex; align-items: center;">
+                            <input type="radio" name="order_type" id="order_type_2" value="2" <?= ($order['order_type'] == 2) ? 'checked' : '' ?>> 定制订单
+                        </label>
+                    </div>
+                </td>
+            </tr>
             <tr>
                 <th width="8%">客户选择</th>
                 <td>
@@ -963,6 +976,7 @@ if (!empty($id) && is_numeric($id)) {
             var orderCode = $('#order_code').val();
             var customerId = $('#customer_id').val();
             var customerName = $('#customer_search').val() || $('#customer_selected').text().trim();
+            var orderType = $('input[name="order_type"]:checked').val();
             var hasProducts = false;
             var allTotalPricesValid = true;
             var firstInvalidField = null;
@@ -974,6 +988,13 @@ if (!empty($id) && is_numeric($id)) {
                 return false;
             }
 
+            // 检查订单类型是否已选择
+            if (!orderType) {
+                alert('请选择订单类型');
+                $('#order_type_1').focus();
+                return false;
+            }
+            
             $('.product-row').each(function() {
                 var productId = $(this).find('.product-id-input').val();
                 var totalPriceInput = $(this).find('.total-price-input');

+ 9 - 2
order_save.php

@@ -27,6 +27,7 @@ $customer_id = (int)$_POST['customer_id'];
 $contact_id = !empty($_POST['contact_id']) ? (int)$_POST['contact_id'] : "NULL";
 $employee_id = $_SESSION['employee_id'];
 $order_date = mysqli_real_escape_string($conn, $_POST['order_date']);
+$order_type = (int)$_POST['order_type'];
 
 // 设置已删除字段的默认值
 $delivery_date = "NULL";
@@ -58,6 +59,11 @@ if (empty($order_code)) {
     exit;
 }
 
+if (!in_array($order_type, [1, 2])) {
+    echo "<script>alert('请选择有效的订单类型');history.back();</script>";
+    exit;
+}
+
 if ($customer_id <= 0) {
     echo "<script>alert('请选择客户');history.back();</script>";
     exit;
@@ -119,6 +125,7 @@ if ($isedit) {
     // 更新订单基本信息
     $sql = "UPDATE orders SET 
             order_code = '$order_code', 
+            order_type = $order_type,
             customer_id = $customer_id, 
             contact_id = $contact_id, 
             employee_id = $employee_id, 
@@ -172,13 +179,13 @@ if ($isedit) {
 
     // 创建新订单
     $sql = "INSERT INTO orders (
-            order_code, customer_id, contact_id, employee_id, 
+            order_code, order_type, customer_id, contact_id, employee_id, 
             order_date, delivery_date, actual_delivery_date, 
             order_status, payment_status, currency, 
             subtotal, discount_amount, total_amount, 
             notes, internal_notes, created_at, updated_at
         ) VALUES (
-            '$order_code', $customer_id, $contact_id, $employee_id, 
+            '$order_code', $order_type, $customer_id, $contact_id, $employee_id, 
             '$order_date', $delivery_date, $actual_delivery_date, 
             $order_status, $payment_status, '$currency', 
             $subtotal, $discount_amount, $total_amount, 

+ 3 - 0
rebate_expiring.php

@@ -49,6 +49,7 @@ JOIN customer c ON o.customer_id = c.id
 JOIN products p ON oi.product_id = p.id
 WHERE 
     o.order_date BETWEEN '$expiryDate' AND '$cutoffDate'
+    AND o.order_type = 1
     AND p.rebate = 1
     AND NOT EXISTS (
         SELECT 1
@@ -139,6 +140,7 @@ foreach ($paginatedCustomers as &$customer) {
                     FROM order_items oi2
                     JOIN orders o2 ON oi2.order_id = o2.id
                     WHERE o2.customer_id = o.customer_id
+                    AND o2.order_type = 1
                     AND oi2.product_id = oi.product_id
                     AND o2.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
                     AND NOT EXISTS (
@@ -160,6 +162,7 @@ foreach ($paginatedCustomers as &$customer) {
         products p ON oi.product_id = p.id
     WHERE 
         o.customer_id = $customer_id
+        AND o.order_type = 1
         AND o.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
         AND p.rebate = 1
         AND NOT EXISTS (

+ 5 - 0
rebate_redeem.php

@@ -39,6 +39,7 @@ SELECT
             FROM order_items oi2
             JOIN orders o2 ON oi2.order_id = o2.id
             WHERE o2.customer_id = o.customer_id
+            AND o2.order_type = 1
             AND oi2.product_id = oi.product_id
             AND o2.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
             AND NOT EXISTS (
@@ -59,6 +60,7 @@ SELECT
             FROM order_items oi2
             JOIN orders o2 ON oi2.order_id = o2.id
             WHERE o2.customer_id = o.customer_id
+            AND o2.order_type = 1
             AND oi2.product_id = oi.product_id
             AND o2.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
             AND NOT EXISTS (
@@ -79,6 +81,7 @@ SELECT
             FROM order_items oi2
             JOIN orders o2 ON oi2.order_id = o2.id
             WHERE o2.customer_id = o.customer_id
+            AND o2.order_type = 1
             AND oi2.product_id = oi.product_id
             AND o2.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
             AND NOT EXISTS (
@@ -98,6 +101,7 @@ JOIN
     products p ON oi.product_id = p.id
 WHERE 
     o.customer_id = $customerId
+    AND o.order_type = 1
     AND o.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
     AND p.rebate = 1
     AND NOT EXISTS (
@@ -115,6 +119,7 @@ WHERE
             FROM order_items oi2
             JOIN orders o2 ON oi2.order_id = o2.id
             WHERE o2.customer_id = o.customer_id
+            AND o2.order_type = 1
             AND oi2.product_id = oi.product_id
             AND o2.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
             AND NOT EXISTS (

+ 5 - 0
rebate_summary.php

@@ -39,6 +39,7 @@ JOIN customer c ON o.customer_id = c.id
 JOIN products p ON oi.product_id = p.id
 WHERE 
     o.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
+    AND o.order_type = 1
     AND p.rebate = 1
     AND NOT EXISTS (
         SELECT 1
@@ -55,6 +56,7 @@ WHERE
         FROM order_items oi2
         JOIN orders o2 ON oi2.order_id = o2.id
         WHERE o2.customer_id = o.customer_id
+        AND o2.order_type = 1
         AND oi2.product_id = oi.product_id
         AND o2.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
         AND NOT EXISTS (
@@ -168,6 +170,7 @@ if (!empty($customers)) {
                     FROM order_items oi2
                     JOIN orders o2 ON oi2.order_id = o2.id
                     WHERE o2.customer_id = o.customer_id
+                    AND o2.order_type = 1
                     AND oi2.product_id = oi.product_id
                     AND o2.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
                     AND NOT EXISTS (
@@ -189,6 +192,7 @@ if (!empty($customers)) {
         products p ON oi.product_id = p.id
     WHERE 
         o.customer_id IN ($customerIdsForDetailsStr)
+        AND o.order_type = 1
         AND o.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
         AND p.rebate = 1
         AND NOT EXISTS (
@@ -234,6 +238,7 @@ if (!empty($customers)) {
             products p ON oi.product_id = p.id
         WHERE 
             o.customer_id = $customerId
+            AND o.order_type = 1
             AND o.order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 90 DAY)
             AND p.rebate = 1
             AND NOT EXISTS (