Quellcode durchsuchen

fleat: update $current_permission order

igb vor 2 Tagen
Ursprung
Commit
7a52dac414

+ 3 - 0
customer_composition_stats.php

@@ -59,6 +59,7 @@ if (!$is_export) {
  * 获取业务员业绩的客户构成
  */
 function getCustomerCompositionStats($conn, $start_date, $end_date, $employee_filter = null) {
+    global $current_permission_role;
     // 查询业务员的新客户业绩(客户编码以0开头的)
     $new_customer_sql = "SELECT 
                 e.id AS employee_id,
@@ -199,6 +200,7 @@ function getCustomerCompositionStats($conn, $start_date, $end_date, $employee_fi
  * 获取按月统计的客户构成业绩
  */
 function getMonthlyCustomerComposition($conn, $start_date, $end_date, $employee_filter = null) {
+    global $current_permission_role;
     // 查询每月新客户业绩(客户编码以0开头的)
     $new_customer_sql = "SELECT 
                 DATE_FORMAT(o.order_date, '%Y-%m') AS month,
@@ -328,6 +330,7 @@ function getMonthlyCustomerComposition($conn, $start_date, $end_date, $employee_
  * 导出数据为CSV
  */
 function exportToCSV($data, $columns, $filename) {
+    global $current_permission_role;
     // 设置头信息
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment;filename="' . $filename . '.csv"');

+ 5 - 3
inquiry_conversion_stats.php

@@ -288,7 +288,7 @@ function renderEmployeeConversionRateTable($data, $is_export = false) {
     echo '<div class="card-header d-flex justify-content-between align-items-center">';
     echo '<span>业务员询盘转化率统计</span>';
     // 只有管理员才显示导出按钮
-    if ($current_permission_role == 1) {
+    if ($GLOBALS['current_permission_role'] == 1) {
         echo '<a href="' . $_SERVER['REQUEST_URI'] . '&export=excel&type=employee" class="btn btn-sm btn-success ml-3">导出CSV</a>';
     }
     echo '</div>';
@@ -364,8 +364,10 @@ function renderChannelTotalConversionRateTable($data, $is_export = false) {
     echo '<div class="card">';
     echo '<div class="card-header d-flex justify-content-between align-items-center">';
     echo '<span>渠道询盘转化率汇总</span>';
+
+
     // 只有管理员才显示导出按钮
-    if ($current_permission_role == 1) {
+    if ($GLOBALS['current_permission_role'] == 1) {
         echo '<a href="' . $_SERVER['REQUEST_URI'] . '&export=excel&type=channel" class="btn btn-sm btn-success ml-3">导出CSV</a>';
     }
     echo '</div>';
@@ -442,7 +444,7 @@ function renderCountryChannelConversionRateTable($data, $is_export = false) {
     echo '<div class="card-header d-flex justify-content-between align-items-center">';
     echo '<span>国家/渠道月度转化率明细</span>';
     // 只有管理员才显示导出按钮
-    if ($current_permission_role == 1) {
+    if ($GLOBALS['current_permission_role'] == 1) {
         echo '<a href="' . $_SERVER['REQUEST_URI'] . '&export=excel&type=country_channel" class="btn btn-sm btn-success ml-3">导出CSV</a>';
     }
     echo '</div>';

+ 2 - 2
monthly_deal_stats.php

@@ -200,7 +200,7 @@ function renderMonthlyDealCustomersTable($data, $is_export = false) {
     echo '<div class="card-header d-flex justify-content-between align-items-center">';
     echo '<span>每月新增成交客户数量明细 (总计: '.$total_customers.' 客户)</span>';
     // 只有管理员才显示导出按钮
-    if ($current_permission_role == 1) {
+    if ($GLOBALS['current_permission_role'] == 1) {
         echo '<a href="' . $_SERVER['REQUEST_URI'] . '&export=excel&type=customers" class="btn btn-sm btn-success ml-3">导出CSV</a>';
     }
     echo '</div>';
@@ -272,7 +272,7 @@ function renderDealStatsByEmployeeTable($data, $is_export = false) {
     echo '<div class="card-header d-flex justify-content-between align-items-center">';
     echo '<span>业务员成交统计明细</span>';
     // 只有管理员才显示导出按钮
-    if ($current_permission_role == 1) {
+    if ($GLOBALS['current_permission_role'] == 1) {
         echo '<a href="' . $_SERVER['REQUEST_URI'] . '&export=excel&type=employee" class="btn btn-sm btn-success ml-3">导出CSV</a>';
     }
     echo '</div>';

+ 21 - 2
order_add.php

@@ -824,6 +824,7 @@ if ($customerId > 0) {
             var hasProducts = false;
             var allTotalPricesValid = true;
             var firstInvalidField = null;
+            var hasUnselectedProducts = false;
 
             // 检查是否有产品行
             if ($('.product-row').length === 0) {
@@ -837,11 +838,21 @@ if ($customerId > 0) {
                 var totalPriceInput = $(this).find('.total-price-input');
                 var totalPrice = parseFloat(totalPriceInput.val()) || 0;
                 var productSearch = $(this).find('.product-search');
+                var searchValue = productSearch.val().trim();
                 
                 // 检查产品是否已选择
                 if (!productId) {
-                    if (!firstInvalidField) {
-                        firstInvalidField = productSearch;
+                    if (searchValue) {
+                        // 如果有搜索内容但未选择产品
+                        hasUnselectedProducts = true;
+                        if (!firstInvalidField) {
+                            firstInvalidField = productSearch;
+                        }
+                    } else {
+                        // 如果既没有选择产品也没有搜索内容
+                        if (!firstInvalidField) {
+                            firstInvalidField = productSearch;
+                        }
                     }
                     return true; // continue
                 }
@@ -885,6 +896,14 @@ if ($customerId > 0) {
                 }
                 return false;
             }
+
+            if (hasUnselectedProducts) {
+                alert('请从搜索结果中选择产品,不能直接提交未选择的产品');
+                if (firstInvalidField) {
+                    firstInvalidField.focus();
+                }
+                return false;
+            }
             
             if (!allTotalPricesValid) {
                 alert('请为所有产品输入有效的总价');

+ 5 - 4
order_save.php

@@ -84,8 +84,9 @@ if ($customer_result && mysqli_num_rows($customer_result) > 0) {
             if (empty($item['product_id'])) continue;
             
             $product_id = (int)$item['product_id'];
-            
-            // 获取产品详情,包括nosale字段
+
+            if($product_id <= 0) continue; // 跳过无效的产品ID
+
             $product_query = "SELECT ProductName, nosale FROM products WHERE id = $product_id LIMIT 1";
             $product_result = mysqli_query($conn, $product_query);
             
@@ -144,8 +145,8 @@ if ($isedit) {
     // 添加新的订单项
     foreach ($items as $item) {
         if (empty($item['product_id'])) continue; // 跳过没有选择产品的行
-
         $product_id = (int)$item['product_id'];
+        if($product_id <= 0) continue; // 跳过无效的产品ID
         $quantity = (int)$item['quantity'];
         $unit = mysqli_real_escape_string($conn, htmlspecialchars($item['unit'], ENT_QUOTES, 'UTF-8'));
         $total_price = (float)$item['total_price'];
@@ -190,8 +191,8 @@ if ($isedit) {
     // 添加订单项
     foreach ($items as $item) {
         if (empty($item['product_id'])) continue; // 跳过没有选择产品的行
-
         $product_id = (int)$item['product_id'];
+        if($product_id <= 0) continue; // 跳过无效的产品ID
         $quantity = (int)$item['quantity'];
         $unit = mysqli_real_escape_string($conn, htmlspecialchars($item['unit'], ENT_QUOTES, 'UTF-8'));
         $total_price = (float)$item['total_price'];

+ 2 - 2
region_performance_stats.php

@@ -216,7 +216,7 @@ function renderMonthlyRegionPerformanceTable($data, $is_export = false) {
     echo '<div class="card-header d-flex justify-content-between align-items-center">';
     echo '<span>每月区域新客户业绩明细 (总计: '.formatCurrency($total_amount).', 共'.$total_customers.'个新客户)</span>';
     // 只有管理员才显示导出按钮
-    if ($current_permission_role == 1) {
+    if ($GLOBALS['current_permission_role'] == 1) {
         echo '<a href="' . $_SERVER['REQUEST_URI'] . '&export=excel&type=monthly" class="btn btn-sm btn-success ml-3">导出CSV</a>';
     }
     echo '</div>';
@@ -300,7 +300,7 @@ function renderRegionPerformanceSummaryTable($data, $is_export = false) {
     echo '<div class="card-header d-flex justify-content-between align-items-center">';
     echo '<span>区域新客户业绩汇总 (总计: '.formatCurrency($total_amount).', 共'.$total_customers.'个新客户)</span>';
     // 只有管理员才显示导出按钮
-    if ($current_permission_role == 1) {
+    if ($GLOBALS['current_permission_role'] == 1) {
         echo '<a href="' . $_SERVER['REQUEST_URI'] . '&export=excel&type=summary" class="btn btn-sm btn-success ml-3">导出CSV</a>';
     }
     echo '</div>';