Browse Source

fleat: update stats and order

igb 16 hours ago
parent
commit
d5fafa9841

+ 8 - 8
customer_composition_stats.php

@@ -69,7 +69,7 @@ function getCustomerCompositionStats($conn, $start_date, $end_date, $employee_fi
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
             JOIN employee e ON c.cs_belong = e.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_code LIKE '%.0%'";
     
@@ -82,7 +82,7 @@ function getCustomerCompositionStats($conn, $start_date, $end_date, $employee_fi
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
             JOIN employee e ON c.cs_belong = e.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_code LIKE '%.3%'
             AND c.cs_code NOT LIKE '%/%'";
@@ -96,7 +96,7 @@ function getCustomerCompositionStats($conn, $start_date, $end_date, $employee_fi
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
             JOIN employee e ON c.cs_belong = e.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_code LIKE '%/%'";
     
@@ -109,7 +109,7 @@ function getCustomerCompositionStats($conn, $start_date, $end_date, $employee_fi
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
             JOIN employee e ON c.cs_belong = e.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3";
     
     // 根据员工过滤条件添加WHERE子句
@@ -208,7 +208,7 @@ function getMonthlyCustomerComposition($conn, $start_date, $end_date, $employee_
                 SUM(o.total_amount) AS total_amount
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_code LIKE '%.0%'";
     
@@ -219,7 +219,7 @@ function getMonthlyCustomerComposition($conn, $start_date, $end_date, $employee_
                 SUM(o.total_amount) AS total_amount
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_code LIKE '%.3%'
             AND c.cs_code NOT LIKE '%/%'";
@@ -231,7 +231,7 @@ function getMonthlyCustomerComposition($conn, $start_date, $end_date, $employee_
                 SUM(o.total_amount) AS total_amount
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_code LIKE '%/%'";
     
@@ -242,7 +242,7 @@ function getMonthlyCustomerComposition($conn, $start_date, $end_date, $employee_
                 SUM(o.total_amount) AS total_amount
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3";
     
     // 根据员工过滤条件添加WHERE子句

+ 48 - 1
customers_stats.php

@@ -214,7 +214,8 @@ include('statistics_header.php');
     </div>
     
     <!-- 业务员新增客户统计 -->
-    <div class="employee-section">
+    
+    <div class="employee-section auto-chart-container">
         <div class="section-title">
             <h2>业务员新增客户统计</h2>
         </div>
@@ -261,6 +262,52 @@ include('statistics_header.php');
     </div>
 </div>
 
+<style>
+        /* 响应式布局:调整表格容器 */
+        .auto-chart-container {
+            width: 100%;
+            padding: 15px;
+        }
+        
+        /* 表格网格布局 */
+        .auto-chart-grid {
+            width: 100%;
+        }
+        
+        /* 表格样式美化 */
+        .data-table {
+            width: 100%;
+            border-collapse: collapse;
+            margin-bottom: 0;
+        }
+        
+        .data-table th, .data-table td {
+            padding: 10px;
+            border: 1px solid #dee2e6;
+            text-align: left;
+        }
+        
+        .data-table th {
+            background-color: #f8f9fa;
+            font-weight: bold;
+        }
+        
+        .data-table tr:nth-child(even) {
+            background-color: #f8f9fa;
+        }
+        
+        .data-table tr:hover {
+            background-color: #e9ecef;
+        }
+        
+        /* 响应式表格 */
+        .table-responsive {
+            display: block;
+            width: 100%;
+            overflow-x: auto;
+            -webkit-overflow-scrolling: touch;
+        }
+    </style>
 <script>
 function toggleCustomDates() {
     const dateRange = document.getElementById('date_range').value;

+ 234 - 21
monthly_deal_stats.php

@@ -94,13 +94,14 @@ function getMonthlyDealCustomers($conn, $start_date, $end_date, $employee_filter
 function getDealStatsByEmployee($conn, $start_date, $end_date, $employee_filter = null) {
     $sql = "SELECT 
                 e.id AS employee_id,
-                e.em_user AS employee_name,
-                COUNT(DISTINCT c.id) AS customer_count,
-                SUM(o.total_amount) AS total_amount
+                MAX(e.em_user) AS employee_name, 
+                MAX(c.cs_code) AS customer_code,              
+                o.customer_id,
+                SUM(o.total_amount) AS order_amount
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
             JOIN employee e ON c.cs_belong = e.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_dealdate BETWEEN '$start_date' AND '$end_date'";
     
@@ -116,9 +117,10 @@ function getDealStatsByEmployee($conn, $start_date, $end_date, $employee_filter
         }
     }
     
-    $sql .= " GROUP BY e.id
-              ORDER BY total_amount DESC";
-    
+    $sql .= " GROUP BY e.id, o.customer_id
+              ORDER BY e.id, order_amount DESC";
+              
+
     $result = $conn->query($sql);
     $data = [];
     
@@ -246,12 +248,10 @@ function renderDealStatsByEmployeeTable($data, $is_export = false) {
     $table_data = [];
     
     foreach ($data as $item) {
-        $avg_customer_value = $item['customer_count'] > 0 ? $item['total_amount'] / $item['customer_count'] : 0;
         $table_data[] = [
             '业务员' => $item['employee_name'],
-            '成交客户数' => $item['customer_count'],
-            '成交金额' => $is_export ? $item['total_amount'] : formatCurrency($item['total_amount']),
-            '客单价' => $is_export ? $avg_customer_value : formatCurrency($avg_customer_value)
+            '成交客户编码' => $item['customer_code'],
+            '成交金额' => $is_export ? $item['order_amount'] : formatCurrency($item['order_amount'])
         ];
     }
     
@@ -259,7 +259,7 @@ function renderDealStatsByEmployeeTable($data, $is_export = false) {
     if ($is_export) {
         exportToCSV(
             $table_data, 
-            ['业务员', '成交客户数', '成交金额', '客单价'],
+            ['业务员', '成交客户编码', '成交金额'],
             '业务员成交统计_' . date('Ymd')
         );
         return;
@@ -281,21 +281,18 @@ function renderDealStatsByEmployeeTable($data, $is_export = false) {
     echo '<table class="table table-bordered table-striped">';
     echo '<thead class="thead-light">';
     echo '<tr>';
-    echo '<th style="width: 25%; text-align: left;">业务员</th>';
-    echo '<th style="width: 25%; text-align: left;">成交客户数</th>';
-    echo '<th style="width: 25%; text-align: left;">成交金额</th>';
-    echo '<th style="width: 25%; text-align: left;">客单价</th>';
+    echo '<th style="width: 33%; text-align: left;">业务员</th>';
+    echo '<th style="width: 33%; text-align: left;">成交客户编码</th>';
+    echo '<th style="width: 33%; text-align: left;">成交金额</th>';
     echo '</tr>';
     echo '</thead>';
     echo '<tbody>';
     
     foreach ($data as $item) {
-        $avg_customer_value = $item['customer_count'] > 0 ? $item['total_amount'] / $item['customer_count'] : 0;
         echo '<tr>';
         echo '<td>'.$item['employee_name'].'</td>';
-        echo '<td>'.$item['customer_count'].'</td>';
-        echo '<td>'.formatCurrency($item['total_amount']).'</td>';
-        echo '<td>'.formatCurrency($avg_customer_value).'</td>';
+        echo '<td>'.$item['customer_code'].'</td>';
+        echo '<td>'.formatCurrency($item['order_amount']).'</td>';
         echo '</tr>';
     }
     
@@ -308,6 +305,215 @@ function renderDealStatsByEmployeeTable($data, $is_export = false) {
     echo '</div>';
 }
 
+/**
+ * 获取团队数据统计
+ */
+function getTeamStatistics($conn, $start_date, $end_date) {
+    $team_data = [];
+    
+    // 获取组长信息
+    $result = $conn->query("SELECT id, em_user FROM employee WHERE em_role=0 AND em_permission_role_id in(2,3,4)");
+    
+    while ($row = $result->fetch_assoc()) {
+        $team_leader = [
+            'id' => $row['id'],
+            'name' => $row['em_user'],
+            'members' => [],
+            'total_customers' => 0,
+            'deals' => [],
+            'sea_customers' => 0,
+            'claimed_customers' => 0
+        ];
+        
+        // 获取组长的总客户数量
+        $c1Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c1 FROM customer c WHERE c.cs_belong=" . $row['id']);
+        $c1Row = $c1Result->fetch_assoc();
+        $team_leader['total_customers'] = $c1Row['c1'];
+
+        // 获取组长的进公海客户总数
+        $c2Result = $conn->query("SELECT COUNT(c.id) as c2 FROM customer c 
+                                  WHERE c.cs_deal<>3 AND c.cs_deal<>0 AND c.cs_type<>2 
+                                  AND DATEDIFF(NOW(), c.cs_updatetime) > 90 
+                                  AND c.cs_belongclient=0 AND c.cs_belong=" . $row['id']);
+        $c2Row = $c2Result->fetch_assoc();
+        $team_leader['sea_customers'] = $c2Row['c2'];
+
+        // 获取组长在日期范围内的成交客户
+        $c3Result = $conn->query("SELECT DISTINCT c.cs_code FROM customer c 
+                                  WHERE c.cs_dealdate > '" . $conn->real_escape_string($start_date) . "' 
+                                  AND c.cs_dealdate <= '" . $conn->real_escape_string($end_date) . "' 
+                                  AND c.cs_deal=3 AND c.cs_belong=" . $row['id']);
+        while ($c3Row = $c3Result->fetch_assoc()) {
+            $team_leader['deals'][] = $c3Row['cs_code'];
+        }
+
+        // 获取组长的公海认领客户数
+        $c4Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c4 FROM customer c 
+                                  WHERE c.cs_claimdate > '" . $conn->real_escape_string($start_date) . "' 
+                                  AND c.cs_claimdate <= '" . $conn->real_escape_string($end_date) . "' 
+                                  AND c.cs_belong=" . $row['id']);
+        $c4Row = $c4Result->fetch_assoc();
+        $team_leader['claimed_customers'] = $c4Row['c4'];
+
+        // 获取组员数量
+        $c5Result = $conn->query("SELECT COUNT(id) as c5 FROM employee WHERE em_role=" . $row['id']);
+        $c5Row = $c5Result->fetch_assoc();
+        $team_leader['member_count'] = $c5Row['c5'];
+        
+        // 获取组员数据
+        $memberResult = $conn->query("SELECT id, em_user FROM employee WHERE em_role=" . $row['id']);
+        while ($memberRow = $memberResult->fetch_assoc()) {
+            $member = [
+                'id' => $memberRow['id'],
+                'name' => $memberRow['em_user'],
+                'total_customers' => 0,
+                'deals' => [],
+                'sea_customers' => 0,
+                'claimed_customers' => 0
+            ];
+            
+            // 获取组员的总客户数量
+            $mc1Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c1 FROM customer c WHERE c.cs_belong=" . $memberRow['id']);
+            $mc1Row = $mc1Result->fetch_assoc();
+            $member['total_customers'] = $mc1Row['c1'];
+
+            // 获取组员的进公海客户总数
+            $mc2Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c2 FROM customer c 
+                                      WHERE c.cs_deal<>3 AND c.cs_deal<>0 AND c.cs_type<>2 
+                                      AND DATEDIFF(NOW(), c.cs_updatetime) > 90 
+                                      AND c.cs_belongclient=0 AND c.cs_belong=" . $memberRow['id']);
+            $mc2Row = $mc2Result->fetch_assoc();
+            $member['sea_customers'] = $mc2Row['c2'];
+
+            // 获取组员在日期范围内的成交客户
+            $mc3Result = $conn->query("SELECT DISTINCT c.cs_code FROM customer c 
+                                      WHERE c.cs_dealdate > '" . $conn->real_escape_string($start_date) . "' 
+                                      AND c.cs_dealdate <= '" . $conn->real_escape_string($end_date) . "' 
+                                      AND c.cs_deal=3 AND c.cs_belong=" . $memberRow['id']);
+            while ($mc3Row = $mc3Result->fetch_assoc()) {
+                $member['deals'][] = $mc3Row['cs_code'];
+            }
+
+            // 获取组员的公海认领客户数
+            $mc4Result = $conn->query("SELECT COUNT(c.id) as c4 FROM customer c 
+                                      WHERE c.cs_claimdate > '" . $conn->real_escape_string($start_date) . "' 
+                                      AND c.cs_claimdate <= '" . $conn->real_escape_string($end_date) . "' 
+                                      AND c.cs_belong=" . $memberRow['id']);
+            $mc4Row = $mc4Result->fetch_assoc();
+            $member['claimed_customers'] = $mc4Row['c4'];
+            
+            $team_leader['members'][] = $member;
+        }
+        
+        $team_data[] = $team_leader;
+    }
+    
+    return $team_data;
+}
+
+/**
+ * 渲染团队统计表格
+ */
+function renderTeamStatisticsTable($data, $is_export = false) {
+    if (empty($data)) {
+        if (!$is_export) {
+            echo '<div class="alert alert-info">当前选择范围内没有团队数据</div>';
+        }
+        return;
+    }
+    
+    // 准备导出数据
+    if ($is_export) {
+        $export_data = [];
+        foreach ($data as $team) {
+            // 添加组长行
+            $export_data[] = [
+                '组长' => $team['name'],
+                '组员' => $team['name'],
+                '总客户数量' => $team['total_customers'],
+                '本月成交' => implode(', ', $team['deals']),
+                '进公海客户总数' => $team['sea_customers'],
+                '公海认领' => $team['claimed_customers']
+            ];
+            
+            // 添加组员行
+            foreach ($team['members'] as $member) {
+                $export_data[] = [
+                    '组长' => '',
+                    '组员' => $member['name'],
+                    '总客户数量' => $member['total_customers'],
+                    '本月成交' => implode(', ', $member['deals']),
+                    '进公海客户总数' => $member['sea_customers'],
+                    '公海认领' => $member['claimed_customers']
+                ];
+            }
+        }
+        
+        exportToCSV(
+            $export_data,
+            ['组长', '组员', '总客户数量', '本月成交', '进公海客户总数', '公海认领'],
+            '团队数据统计_' . date('Ymd')
+        );
+        return;
+    }
+    
+    // 渲染表格
+    echo '<div class="row mt-5 mb-5">';
+    echo '<div class="col-md-12">';
+    echo '<div class="card">';
+    echo '<div class="card-header d-flex justify-content-between align-items-center">';
+    echo '<span>各组数据统计</span>';
+    // 只有管理员才显示导出按钮
+    if ($GLOBALS['current_permission_role'] == 1) {
+        echo '<a href="' . $_SERVER['REQUEST_URI'] . '&export=excel&type=team" class="btn btn-sm btn-success ml-3">导出CSV</a>';
+    }
+    echo '</div>';
+    echo '<div class="card-body">';
+    echo '<div class="table-responsive">';
+    echo '<table class="table table-bordered table-striped">';
+    echo '<thead class="thead-light">';
+    echo '<tr>';
+    echo '<th>组长</th>';
+    echo '<th>组员</th>';
+    echo '<th>总客户数量</th>';
+    echo '<th width="25%">本月成交</th>';
+    echo '<th>进公海客户总数</th>';
+    echo '<th>公海认领</th>';
+    echo '</tr>';
+    echo '</thead>';
+    echo '<tbody>';
+    
+    foreach ($data as $team) {
+        $member_count = count($team['members']);
+        echo '<tr>';
+        echo '<td rowspan="' . (1 + $member_count) . '">' . htmlspecialchars($team['name']) . '</td>';
+        echo '<td>' . htmlspecialchars($team['name']) . '</td>';
+        echo '<td>' . $team['total_customers'] . '</td>';
+        echo '<td>' . implode('<br>', $team['deals']) . '</td>';
+        echo '<td>' . $team['sea_customers'] . '</td>';
+        echo '<td>' . $team['claimed_customers'] . '</td>';
+        echo '</tr>';
+        
+        foreach ($team['members'] as $member) {
+            echo '<tr>';
+            echo '<td>' . htmlspecialchars($member['name']) . '</td>';
+            echo '<td>' . $member['total_customers'] . '</td>';
+            echo '<td>' . implode('<br>', $member['deals']) . '</td>';
+            echo '<td>' . $member['sea_customers'] . '</td>';
+            echo '<td>' . $member['claimed_customers'] . '</td>';
+            echo '</tr>';
+        }
+    }
+    
+    echo '</tbody>';
+    echo '</table>';
+    echo '</div>';
+    echo '</div>';
+    echo '</div>';
+    echo '</div>';
+    echo '</div>';
+}
+
 // 获取选择的业务员
 $selected_employee = isset($_GET['selected_employee']) ? $_GET['selected_employee'] : 'all';
 
@@ -347,6 +553,9 @@ $monthly_deal_customers = getMonthlyDealCustomers($conn, $start_date, $end_date,
 // 获取业务员成交统计数据
 $deal_stats_by_employee = getDealStatsByEmployee($conn, $start_date, $end_date, $employee_filter);
 
+// 获取团队统计数据
+$team_statistics = getTeamStatistics($conn, $start_date, $end_date);
+
 // 处理导出请求
 if ($is_export) {
     $export_type = isset($_GET['type']) ? $_GET['type'] : '';
@@ -358,6 +567,9 @@ if ($is_export) {
         case 'employee':
             renderDealStatsByEmployeeTable($deal_stats_by_employee, true);
             break;
+        case 'team':
+            renderTeamStatisticsTable($team_statistics, true);
+            break;
     }
     
     exit; // 确保导出后停止执行
@@ -367,7 +579,7 @@ if ($is_export) {
 
 <div class="container">
     <div class="page-header">
-        <h1 class="page-title">每月新增成交客户统计</h1>
+        <h1 class="page-title">每月成交客户统计</h1>
     </div>
     
     <!-- 日期筛选 -->
@@ -434,6 +646,7 @@ if ($is_export) {
     <div class="stats-content">
         <?php
         // 渲染表格
+        renderTeamStatisticsTable($team_statistics);
         renderMonthlyDealCustomersTable($monthly_deal_customers);
         renderDealStatsByEmployeeTable($deal_stats_by_employee);
         ?>

+ 2 - 2
order.php

@@ -42,7 +42,7 @@ $sqlStr = "SELECT o.*, c.cs_company, c.cs_code,
            DATEDIFF(NOW(), o.created_at) as days_diff
            FROM orders o
            LEFT JOIN customer c ON o.customer_id = c.id
-           WHERE 1=1";
+           WHERE o.is_deleted = 0";
 
 // 非管理员只能查看自己的订单
 if (!$isAdmin) {
@@ -238,7 +238,7 @@ $sqlStr .= " $fliterStr ORDER BY {$ordStr}o.created_at DESC";
         $employee_id = $_SESSION['employee_id'];
         $countSql = "SELECT COUNT(*) AS total FROM orders o
                      LEFT JOIN customer c ON o.customer_id = c.id
-                     WHERE 1=1";
+                     WHERE o.is_deleted = 0";
 
         // 非管理员只能查看自己的订单
         if (!$isAdmin) {

+ 9 - 9
order_delete.php

@@ -20,11 +20,11 @@ if ($id <= 0) {
 }
 
 // 验证订单存在
-$checkSql = "SELECT id FROM orders WHERE id = $id";
+$checkSql = "SELECT id FROM orders WHERE id = $id AND is_deleted = 0";
 $checkResult = mysqli_query($conn, $checkSql);
 
 if (mysqli_num_rows($checkResult) === 0) {
-    echo "<script>alert('订单不存在');location.href='order.php?keys=$keys&Page=$page';</script>";
+    echo "<script>alert('订单不存在或已被删除');location.href='order.php?keys=$keys&Page=$page';</script>";
     exit;
 }
 
@@ -33,16 +33,16 @@ mysqli_autocommit($conn, FALSE);
 $error = false;
 
 try {
-    // 先删除订单项目
-    $deleteItemsSql = "DELETE FROM order_items WHERE order_id = $id";
-    if (!mysqli_query($conn, $deleteItemsSql)) {
-        throw new Exception("删除订单项目失败: " . mysqli_error($conn));
+    // 软删除订单明细(更新is_deleted字段为1)
+    $softDeleteItemsSql = "UPDATE order_items SET is_deleted = 1 WHERE order_id = $id";
+    if (!mysqli_query($conn, $softDeleteItemsSql)) {
+        throw new Exception("删除订单明细失败: " . mysqli_error($conn));
     }
     
-    // 删除订单主表
-    $deleteOrderSql = "DELETE FROM orders WHERE id = $id";
+    // 软删除订单(更新is_deleted字段为1)
+    $softDeleteSql = "UPDATE orders SET is_deleted = 1 WHERE id = $id";
 
-    if (!mysqli_query($conn, $deleteOrderSql)) {
+    if (!mysqli_query($conn, $softDeleteSql)) {
         throw new Exception("删除订单失败: " . mysqli_error($conn));
     }
     

+ 2 - 2
order_details.php

@@ -15,7 +15,7 @@ if (!empty($id) && is_numeric($id)) {
             LEFT JOIN customer c ON o.customer_id = c.id 
             LEFT JOIN customer_contact cc ON o.contact_id = cc.id 
             LEFT JOIN employee e ON o.employee_id = e.id
-            WHERE o.id = $id";
+            WHERE o.id = $id AND o.is_deleted = 0";
     
     // 非管理员只能查看自己的订单
     if (!$isAdmin) {
@@ -36,7 +36,7 @@ if (!empty($id) && is_numeric($id)) {
             FROM order_items oi 
             LEFT JOIN products p ON oi.product_id = p.id 
             LEFT JOIN product_specifications ps ON oi.specification_id = ps.id
-            WHERE oi.order_id = $id";
+            WHERE oi.order_id = $id AND oi.is_deleted = 0";
 
     $itemsResult = mysqli_query($conn, $sql);
 

+ 2 - 2
order_edit.php

@@ -16,7 +16,7 @@ if (!empty($id) && is_numeric($id)) {
             FROM orders o 
             LEFT JOIN customer c ON o.customer_id = c.id 
             LEFT JOIN customer_contact cc ON o.contact_id = cc.id 
-            WHERE o.id = $id AND o.employee_id = $employee_id";
+            WHERE o.id = $id AND o.is_deleted = 0 AND o.employee_id = $employee_id";
 
     $result = mysqli_query($conn, $sql);
 
@@ -35,7 +35,7 @@ if (!empty($id) && is_numeric($id)) {
             LEFT JOIN products p ON oi.product_id = p.id 
             LEFT JOIN product_categories pc ON p.category_id = pc.id
             LEFT JOIN product_specifications ps ON oi.specification_id = ps.id
-            WHERE oi.order_id = $id";
+            WHERE oi.order_id = $id AND oi.is_deleted = 0";
 
     $itemsResult = mysqli_query($conn, $sql);
 

+ 8 - 7
order_save.php

@@ -70,8 +70,8 @@ if (empty($order_code)) {
     exit;
 }
 
-// 检查订单号是否已存在
-$check_order_code_sql = "SELECT id FROM orders WHERE order_code = '$order_code'";
+// 检查订单号是否已存在,不管是不是删除的订单
+$check_order_code_sql = "SELECT id FROM orders WHERE order_code = '$order_code' ";
 if ($isedit) {
     $check_order_code_sql .= " AND id != $id";
 }
@@ -168,7 +168,8 @@ if ($isedit) {
 
     mysqli_query($conn, $sql);
 
-    // 删除旧的订单项
+
+    // 编辑保存时不需要保存旧的订单项,删除旧的订单项
     $sql = "DELETE FROM order_items WHERE order_id = $id";
     mysqli_query($conn, $sql);
 
@@ -186,11 +187,11 @@ if ($isedit) {
 
         $sql = "INSERT INTO order_items (
                 order_id, product_id, specification_id, quantity, unit, unit_price, 
-                total_price, notes, 
+                total_price, notes, is_deleted,
                 created_at, updated_at
             ) VALUES (
                 $id, $product_id, 0, $quantity, '$unit', $unit_price, 
-                $total_price, '$item_notes', 
+                $total_price, '$item_notes', 0,
                 NOW(), NOW()
             )";
 
@@ -232,11 +233,11 @@ if ($isedit) {
 
         $sql = "INSERT INTO order_items (
                 order_id, product_id, specification_id, quantity, unit, unit_price, 
-                total_price, notes, 
+                total_price, notes, is_deleted,
                 created_at, updated_at
             ) VALUES (
                 $order_id, $product_id, 0, $quantity, '$unit', $unit_price, 
-                $total_price, '$item_notes', 
+                $total_price, '$item_notes', 0,
                 NOW(), NOW()
             )";
 

+ 2 - 2
panel.php

@@ -75,14 +75,14 @@ $stmt->close();
              ?>
             <dt class="subnav">统计分析
                 <div class="list-wraper">
-                                    <a href="../team.php" target="contentFrame">本月小组数据</a>
+                                    <!-- <a href="../team.php" target="contentFrame">本月小组数据</a> -->
 <!--                    <a href="statistics.php" target="contentFrame">汇总统计</a>-->
                     <a href="customers_stats.php" target="contentFrame">客户统计分析</a>
                     <a href="products_stats.php" target="contentFrame">产品统计分析</a>
                     <a href="region_stats.php" target="contentFrame">地区统计分析</a>
 <!--                    <a href="sales_stats.php" target="contentFrame">销售统计分析</a>-->
                     <a href="statistics_order_warnings.php" target="contentFrame">订单预警系统</a>
-                    <a href="monthly_deal_stats.php" target="contentFrame">每月成交客户</a>
+                    <a href="monthly_deal_stats.php" target="contentFrame">每月成交客户统计</a>
                     <a href="region_performance_stats.php" target="contentFrame">每月区域新客户业绩</a>
                     <a href="inquiry_conversion_stats.php" target="contentFrame">客户来源转化率</a>
                     <a href="customer_composition_stats.php" target="contentFrame">每月业绩客户构成</a>

+ 34 - 34
products_stats.php

@@ -161,7 +161,7 @@ include('statistics_header.php');
     </div>
     
     <!-- 热门产品 -->
-    <div class="chart-container">
+    <div class="chart-container"  style="padding-left:0px;padding-right: 0px;">
         <?php
         $top_products = getTopProducts($conn, $start_date, $end_date, 10, $employee_filter);
         renderTopProductsTable($top_products);
@@ -171,7 +171,7 @@ include('statistics_header.php');
     <!-- 新客户购买产品明细 -->
     <div class="section-container">
         <div class="section-title">
-            <h2>新客户购买产品明细</h2>
+            <h2>新客户购买产品明细 TOP 10</h2>
         </div>
         <?php
         $new_customer_products = getNewCustomerProductPurchases($conn, $start_date, $end_date, $category_filter, $employee_filter);
@@ -182,84 +182,84 @@ include('statistics_header.php');
     <!-- 产品销售趋势 -->
     <div class="chart-container" style="display: none">
         <?php
-        $product_trends = getProductSalesTrend($conn, $start_date, $end_date, $product_id, $period, $employee_filter);
+        // $product_trends = getProductSalesTrend($conn, $start_date, $end_date, $product_id, $period, $employee_filter);
         
-        $time_labels = [];
-        $quantities = [];
-        $revenues = [];
+        // $time_labels = [];
+        // $quantities = [];
+        // $revenues = [];
         
-        while ($row = $product_trends->fetch_assoc()) {
-            $time_labels[] = $row['time_period'];
-            $quantities[] = $row['total_quantity'];
-            $revenues[] = $row['total_revenue'];
-        }
-        renderProductSalesTrendChart($time_labels, $quantities, $revenues);
+        // while ($row = $product_trends->fetch_assoc()) {
+        //     $time_labels[] = $row['time_period'];
+        //     $quantities[] = $row['total_quantity'];
+        //     $revenues[] = $row['total_revenue'];
+        // }
+        // renderProductSalesTrendChart($time_labels, $quantities, $revenues);
         ?>
     </div>
     
     <!-- 产品类别销售分布 -->
     <div class="chart-container" style="display: none">
         <?php
-        $category_sales = getProductCategorySales($conn, $start_date, $end_date, $employee_filter);
+        // $category_sales = getProductCategorySales($conn, $start_date, $end_date, $employee_filter);
         
-        $categories = [];
-        $category_quantities = [];
-        $category_revenues = [];
+        // $categories = [];
+        // $category_quantities = [];
+        // $category_revenues = [];
         
-        while ($row = $category_sales->fetch_assoc()) {
-            $categories[] = $row['category_name'];
-            $category_quantities[] = $row['total_quantity'];
-            $category_revenues[] = $row['total_revenue'];
-        }
-        renderProductCategorySalesChart($categories, $category_quantities, $category_revenues);
+        // while ($row = $category_sales->fetch_assoc()) {
+        //     $categories[] = $row['category_name'];
+        //     $category_quantities[] = $row['total_quantity'];
+        //     $category_revenues[] = $row['total_revenue'];
+        // }
+        // renderProductCategorySalesChart($categories, $category_quantities, $category_revenues);
         ?>
     </div>
     
     <!-- 产品价格趋势分析 -->
     <div class="chart-container" style="display: none">
         <?php
-        $price_trend_data = getProductPriceTrendAnalysis($conn, $start_date, $end_date, $product_id, $period, $employee_filter);
-        renderProductPriceTrendChart($price_trend_data);
+        // $price_trend_data = getProductPriceTrendAnalysis($conn, $start_date, $end_date, $product_id, $period, $employee_filter);
+        // renderProductPriceTrendChart($price_trend_data);
         ?>
     </div>
     
     <!-- 产品季节性分析 -->
     <div class="chart-container" style="display: none">
         <?php
-        $seasonality_data = getProductSeasonalityAnalysis($conn, $start_date, $end_date, $product_id, $employee_filter);
-        renderProductSeasonalityChart($seasonality_data);
+        // $seasonality_data = getProductSeasonalityAnalysis($conn, $start_date, $end_date, $product_id, $employee_filter);
+        // renderProductSeasonalityChart($seasonality_data);
         ?>
     </div>
     
     <!-- 产品客户细分分析 -->
     <div class="chart-container" style="display: none">
         <?php
-        $customer_segment_data = getProductCustomerSegmentAnalysis($conn, $start_date, $end_date, $product_id, $employee_filter);
-        renderProductCustomerSegmentChart($customer_segment_data);
+        // $customer_segment_data = getProductCustomerSegmentAnalysis($conn, $start_date, $end_date, $product_id, $employee_filter);
+        // renderProductCustomerSegmentChart($customer_segment_data);
         ?>
     </div>
     
     <!-- 产品地区关联分析 -->
     <div class="chart-container" style="display: none">
         <?php
-        $product_region_data = getProductRegionAnalysis($conn, $start_date, $end_date, $employee_filter);
-        renderProductRegionAnalysisTable($product_region_data);
+        // $product_region_data = getProductRegionAnalysis($conn, $start_date, $end_date, $employee_filter);
+        // renderProductRegionAnalysisTable($product_region_data);
         ?>
     </div>
     
     <!-- 产品增长率分析 -->
     <div class="chart-container" style="display: none">
         <?php
-        $growth_data = getProductGrowthAnalysis($conn, $start_date, $end_date, $period, $employee_filter);
-        renderProductGrowthAnalysis($growth_data);
+        // $growth_data = getProductGrowthAnalysis($conn, $start_date, $end_date, $period, $employee_filter);
+        // renderProductGrowthAnalysis($growth_data);
         ?>
     </div>
     
     <!-- 产品购买频率分析 -->
     <div class="chart-container" style="display: none">
         <?php
-        $frequency_data = getProductPurchaseFrequency($conn, $start_date, $end_date, $employee_filter);
-        renderProductPurchaseFrequency($frequency_data);
+       // $frequency_data = getProductPurchaseFrequency($conn, $start_date, $end_date, $employee_filter);
+       // renderProductPurchaseFrequency($frequency_data);
         ?>
     </div>
 </div>

+ 9 - 1
rebate_expiring.php

@@ -55,7 +55,9 @@ JOIN order_items oi ON o.id = oi.order_id
 JOIN customer c ON o.customer_id = c.id
 JOIN products p ON oi.product_id = p.id
 WHERE 
-    o.order_date >= '$startDate'
+    o.is_deleted = 0
+    AND oi.is_deleted = 0
+    AND o.order_date >= '$startDate'
     AND o.order_type = 1
     AND p.rebate = 1
     AND NOT EXISTS (
@@ -73,6 +75,8 @@ WHERE
         FROM order_items oi2
         JOIN orders o2 ON oi2.order_id = o2.id
         WHERE o2.customer_id = o.customer_id
+        AND o2.is_deleted = 0
+        AND oi2.is_deleted = 0
         AND oi2.product_id = oi.product_id
         AND o2.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
         AND NOT EXISTS (
@@ -148,6 +152,8 @@ 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.is_deleted = 0
+                    AND oi2.is_deleted = 0
                     AND o2.order_type = 1
                     AND oi2.product_id = oi.product_id
                     AND o2.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
@@ -170,6 +176,8 @@ foreach ($paginatedCustomers as &$customer) {
         products p ON oi.product_id = p.id
     WHERE 
         o.customer_id = $customer_id
+        AND o.is_deleted = 0
+        AND oi.is_deleted = 0
         AND o.order_type = 1
         AND o.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
         AND p.rebate = 1

+ 10 - 0
rebate_redeem.php

@@ -39,6 +39,8 @@ SELECT
             FROM order_items oi2
             JOIN orders o2 ON oi2.order_id = o2.id
             WHERE o2.customer_id = o.customer_id
+            AND o2.is_deleted = 0
+            AND oi2.is_deleted = 0
             AND o2.order_type = 1
             AND oi2.product_id = oi.product_id
             AND o2.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
@@ -60,6 +62,8 @@ SELECT
             FROM order_items oi2
             JOIN orders o2 ON oi2.order_id = o2.id
             WHERE o2.customer_id = o.customer_id
+            AND o2.is_deleted = 0
+            AND oi2.is_deleted = 0
             AND o2.order_type = 1
             AND oi2.product_id = oi.product_id
             AND o2.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
@@ -81,6 +85,8 @@ SELECT
             FROM order_items oi2
             JOIN orders o2 ON oi2.order_id = o2.id
             WHERE o2.customer_id = o.customer_id
+            AND o2.is_deleted = 0
+            AND oi2.is_deleted = 0
             AND o2.order_type = 1
             AND oi2.product_id = oi.product_id
             AND o2.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
@@ -101,6 +107,8 @@ JOIN
     products p ON oi.product_id = p.id
 WHERE 
     o.customer_id = $customerId
+    AND o.is_deleted = 0
+    AND oi.is_deleted = 0
     AND o.order_type = 1
     AND o.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
     AND p.rebate = 1
@@ -119,6 +127,8 @@ WHERE
             FROM order_items oi2
             JOIN orders o2 ON oi2.order_id = o2.id
             WHERE o2.customer_id = o.customer_id
+            AND o2.is_deleted = 0
+            AND oi2.is_deleted = 0
             AND o2.order_type = 1
             AND oi2.product_id = oi.product_id
             AND o2.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')

+ 11 - 1
rebate_summary.php

@@ -38,7 +38,9 @@ JOIN order_items oi ON o.id = oi.order_id
 JOIN customer c ON o.customer_id = c.id
 JOIN products p ON oi.product_id = p.id
 WHERE 
-    o.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
+    o.is_deleted = 0
+    AND oi.is_deleted = 0
+    AND o.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
     AND o.order_type = 1
     AND p.rebate = 1
     AND NOT EXISTS (
@@ -56,6 +58,8 @@ WHERE
         FROM order_items oi2
         JOIN orders o2 ON oi2.order_id = o2.id
         WHERE o2.customer_id = o.customer_id
+        AND o2.is_deleted = 0
+        AND oi2.is_deleted = 0
         AND o2.order_type = 1
         AND oi2.product_id = oi.product_id
         AND o2.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
@@ -172,6 +176,8 @@ 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.is_deleted = 0
+                    AND oi2.is_deleted = 0
                     AND o2.order_type = 1
                     AND oi2.product_id = oi.product_id
                     AND o2.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
@@ -194,6 +200,8 @@ if (!empty($customers)) {
         products p ON oi.product_id = p.id
     WHERE 
         o.customer_id IN ($customerIdsForDetailsStr)
+        AND o.is_deleted = 0
+        AND oi.is_deleted = 0
         AND o.order_type = 1
         AND o.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
         AND p.rebate = 1
@@ -240,6 +248,8 @@ if (!empty($customers)) {
             products p ON oi.product_id = p.id
         WHERE 
             o.customer_id = $customerId
+            AND o.is_deleted = 0
+            AND oi.is_deleted = 0
             AND o.order_type = 1
             AND o.order_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')
             AND p.rebate = 1

+ 2 - 2
region_performance_stats.php

@@ -62,7 +62,7 @@ function getMonthlyRegionPerformance($conn, $start_date, $end_date, $employee_fi
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
             JOIN country co ON c.cs_country = co.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_dealdate BETWEEN '$start_date' AND '$end_date'";
     
@@ -104,7 +104,7 @@ function getRegionPerformanceSummary($conn, $start_date, $end_date, $employee_fi
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
             JOIN country co ON c.cs_country = co.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
             AND c.cs_deal = 3
             AND c.cs_dealdate BETWEEN '$start_date' AND '$end_date'";
     

+ 17 - 48
region_stats.php

@@ -159,7 +159,8 @@ include('statistics_header.php');
                     }
                 }
                 
-                $total_sales = getRegionTotalSales($conn, $start_date, $end_date, $employee_filter);
+                // 修改getRegionTotalSales和getActiveCountries函数调用,传入国家筛选条件
+                $total_sales = getRegionTotalSales($conn, $start_date, $end_date, $employee_filter, $country_filter);
                 echo "<div class='stat-value'>¥" . number_format($total_sales['total_amount'], 2) . "</div>";
                 echo "<div class='stat-trend " . ($total_sales['growth'] >= 0 ? 'positive' : 'negative') . "'>";
                 echo ($total_sales['growth'] >= 0 ? '+' : '') . number_format($total_sales['growth'], 2) . "%</div>";
@@ -169,47 +170,37 @@ include('statistics_header.php');
             <div class="stat-card">
                 <h3>活跃国家数</h3>
                 <?php
-                $active_countries = getActiveCountries($conn, $start_date, $end_date, $employee_filter);
+                $active_countries = getActiveCountries($conn, $start_date, $end_date, $employee_filter, $country_filter);
                 echo "<div class='stat-value'>" . $active_countries['count'] . "</div>";
                 ?>
             </div>
-            
-            <div class="stat-card">
-                <h3>平均订单金额</h3>
-                <?php
-                $avg_order = getAverageOrderByRegion($conn, $start_date, $end_date, $employee_filter);
-                echo "<div class='stat-value'>¥" . number_format($avg_order['global_avg'], 2) . "</div>";
-                ?>
-            </div>
         </div>
     </div>
     
     <!-- 热门地区 -->
     <div class="chart-container">
         <div class="section-title">
-            <h2>热门地区</h2>
+            <h2><?php echo $country_filter > 0 ? '地区数据详情' : '热门地区 TOP-10'; ?></h2>
         </div>
         <?php
-        $region_orders = getOrdersByRegion($conn, $start_date, $end_date, $employee_filter);
+        $region_orders = getOrdersByRegion($conn, $start_date, $end_date, $employee_filter, $country_filter);
         $region_labels = [];
         $region_order_counts = [];
-        $region_quantities = [];
         $region_amounts = [];
         
         while ($row = $region_orders->fetch_assoc()) {
             $region_labels[] = $row['countryName'];
             $region_order_counts[] = $row['order_count'];
-            $region_quantities[] = $row['total_quantity'];
             $region_amounts[] = $row['total_amount'];
         }
-        renderTopRegionsTable($region_labels, $region_order_counts, $region_quantities, $region_amounts);
+        renderTopRegionsTable($region_labels, $region_order_counts, $region_amounts);
         ?>
     </div>
     
     <!-- 客户国家分布 -->
     <div class="chart-container">
         <div class="section-title">
-            <h2>客户国家分布</h2>
+            <h2><?php echo $country_filter > 0 ? '客户国家分布' : '客户国家分布 TOP-10'; ?></h2>
         </div>
         <?php
         $country_distribution = getCustomerCountryDistribution($conn, $employee_filter);
@@ -227,10 +218,10 @@ include('statistics_header.php');
     <!-- 地区销售趋势 -->
     <div class="chart-container">
         <div class="section-title">
-            <h2>地区销售趋势</h2>
+            <h2><?php echo $country_filter > 0 ? '地区销售趋势' : '地区销售趋势 TOP-10'; ?></h2>
         </div>
         <?php
-        $growth_trends = getRegionGrowthTrends($conn, $start_date, $end_date, $period, $employee_filter);
+        $growth_trends = getRegionGrowthTrends($conn, $start_date, $end_date, $period, $employee_filter, $country_filter);
         renderRegionGrowthTrendsChart($growth_trends);
         ?>
     </div>
@@ -238,42 +229,20 @@ include('statistics_header.php');
     <!-- 地区订单分析 -->
     <div class="chart-container">
         <div class="section-title">
-            <h2>地区订单分析</h2>
-        </div>
-        <?php
-        renderRegionOrdersChart($region_labels, $region_order_counts, $region_quantities);
-        ?>
-    </div>
-    
-    <!-- 地区平均订单金额分析 -->
-    <div class="chart-container">
-        <div class="section-title">
-            <h2>地区平均订单金额分析</h2>
-        </div>
-        <?php
-        $avg_order_data = getAverageOrderByRegion($conn, $start_date, $end_date, $employee_filter);
-        renderAverageOrderByRegionChart($avg_order_data['regions']);
-        ?>
-    </div>
-    
-    <!-- 各地区产品类别偏好 -->
-    <div class="chart-container">
-        <div class="section-title">
-            <h2>各地区产品类别偏好</h2>
+            <h2><?php echo $country_filter > 0 ? '地区订单分析' : '地区订单分析 TOP-10'; ?></h2>
         </div>
         <?php
-        $category_preferences = getRegionCategoryPreferences($conn, $start_date, $end_date, $employee_filter);
-        renderRegionCategoryPreferencesChart($category_preferences);
+        renderRegionOrdersChart($region_labels, $region_order_counts);
         ?>
     </div>
     
     <!-- 地区销售同比分析 -->
     <div class="chart-container">
         <div class="section-title">
-            <h2>地区销售同比分析</h2>
+            <h2><?php echo $country_filter > 0 ? '地区销售同比分析' : '地区销售同比分析 TOP-10'; ?></h2>
         </div>
         <?php
-        $comparison_data = getRegionSalesComparison($conn, $start_date, $end_date, $employee_filter);
+        $comparison_data = getRegionSalesComparison($conn, $start_date, $end_date, $employee_filter, $country_filter);
         renderRegionSalesComparisonTable($comparison_data);
         ?>
     </div>
@@ -281,10 +250,10 @@ include('statistics_header.php');
     <!-- 地区季节性分析 -->
     <div class="chart-container">
         <div class="section-title">
-            <h2>地区季节性分析</h2>
+            <h2><?php echo $country_filter > 0 ? '地区季节性分析' : '地区季节性分析 TOP-10'; ?></h2>
         </div>
         <?php
-        $seasonal_analysis = getRegionSeasonalAnalysis($conn, $employee_filter);
+        $seasonal_analysis = getRegionSeasonalAnalysis($conn, $employee_filter, $country_filter);
         renderRegionSeasonalAnalysisChart($seasonal_analysis);
         ?>
     </div>
@@ -292,10 +261,10 @@ include('statistics_header.php');
     <!-- 地区销售预测 -->
     <div class="chart-container">
         <div class="section-title">
-            <h2>地区销售预测</h2>
+            <h2><?php echo $country_filter > 0 ? '地区销售预测 (未来6个月)' : '地区销售预测 (未来6个月) TOP-10'; ?></h2>
         </div>
         <?php
-        $forecast_data = getRegionSalesForecast($conn, $start_date, $end_date, $employee_filter);
+        $forecast_data = getRegionSalesForecast($conn, $start_date, $end_date, $employee_filter, $country_filter);
         renderRegionSalesForecastChart($forecast_data);
         ?>
     </div>

+ 8 - 7
statistics_customers.php

@@ -86,7 +86,7 @@ function getNewVsReturningCustomerOrders($conn, $start_date, $end_date) {
                 MAX(c.cs_addtime) as customer_addtime
             FROM orders o
             JOIN customer c ON o.customer_id = c.id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             GROUP BY o.customer_id";
     
     $stmt = $conn->prepare($sql);
@@ -103,6 +103,7 @@ function getNewVsReturningCustomerOrders($conn, $start_date, $end_date) {
         // 查找之前是否有订单
         $prev_sql = "SELECT id FROM orders 
                      WHERE customer_id = ? 
+                     AND is_deleted = 0
                      AND order_date < ? 
                      LIMIT 1";
         
@@ -536,7 +537,7 @@ function getAverageCustomerValue($conn, $start_date, $end_date, $employee_filter
                     SUM(o.total_amount) as customer_value
                 FROM orders o
                 JOIN customer c ON o.customer_id = c.id
-                WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+                WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     // 如果有业务员过滤
     if ($employee_filter !== null) {
@@ -588,7 +589,7 @@ function getCustomerRetentionRate($conn, $start_date, $end_date, $employee_filte
     $prev_sql = "SELECT DISTINCT o.customer_id 
                 FROM orders o
                 JOIN customer c ON o.customer_id = c.id
-                WHERE o.order_date BETWEEN '$previous_start' AND '$previous_end'";
+                WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$previous_start' AND '$previous_end'";
     
     // 如果有业务员过滤
     if ($employee_filter !== null) {
@@ -633,7 +634,7 @@ function getCustomerRetentionRate($conn, $start_date, $end_date, $employee_filte
     $current_sql = "SELECT COUNT(DISTINCT o.customer_id) as retained_count
                    FROM orders o
                    JOIN customer c ON o.customer_id = c.id
-                   WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
+                   WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
                    AND o.customer_id IN (" . implode(',', $previous_customers) . ")";
     
     // 如果有业务员过滤
@@ -716,7 +717,7 @@ function getOrderConversionRate($conn, $start_date, $end_date, $employee_filter
     $order_sql = "SELECT COUNT(DISTINCT o.customer_id) as order_count 
                  FROM orders o
                  JOIN customer c ON o.customer_id = c.id
-                 WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+                 WHERE o.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     // 如果有业务员过滤
     if ($employee_filter !== null) {
@@ -1352,7 +1353,7 @@ function getCustomerConversionFunnel($conn, $start_date, $end_date) {
     $deal_customers = $deal_row['deal_count'];
     
     // 获取有订单的客户数
-    $order_sql = "SELECT COUNT(DISTINCT customer_id) as order_count FROM orders WHERE order_date BETWEEN ? AND ?";
+    $order_sql = "SELECT COUNT(DISTINCT customer_id) as order_count FROM orders WHERE is_deleted = 0 AND order_date BETWEEN ? AND ?";
     $order_stmt = $conn->prepare($order_sql);
     $order_stmt->bind_param("ss", $start_date, $end_date);
     $order_stmt->execute();
@@ -1364,7 +1365,7 @@ function getCustomerConversionFunnel($conn, $start_date, $end_date) {
     $repeat_sql = "SELECT COUNT(customer_id) as repeat_count FROM (
                         SELECT customer_id, COUNT(id) as order_count 
                         FROM orders 
-                        WHERE order_date BETWEEN ? AND ?
+                        WHERE is_deleted = 0 AND order_date BETWEEN ? AND ?
                         GROUP BY customer_id
                         HAVING order_count > 1
                     ) as repeat_customers";

+ 33 - 17
statistics_order_warnings.php

@@ -222,7 +222,7 @@ include('statistics_header.php');
             // 获取总预警数
             $sql_total_warnings = "SELECT 
                 (SELECT COUNT(*) FROM customer WHERE cs_deal = 3) as total_customers,
-                (SELECT COUNT(DISTINCT customer_id) FROM orders WHERE order_date BETWEEN ? AND ?) as active_customers";
+                (SELECT COUNT(DISTINCT customer_id) FROM orders WHERE is_deleted = 0 AND order_date BETWEEN ? AND ?) as active_customers";
             
             $stmt = $conn->prepare($sql_total_warnings);
             $stmt->bind_param("ss", $current_start_date, $current_end_date);
@@ -328,7 +328,6 @@ include('statistics_header.php');
         <table class="data-table">
             <thead>
                 <tr>
-                    <th>客户名称</th>
                     <th>本期订单金额</th>
                     <th>上期订单金额</th>
                     <th>变化百分比</th>
@@ -355,7 +354,6 @@ include('statistics_header.php');
                     $change_class = $change_percent < -20 ? 'text-danger' : 'text-warning';
                     
                     echo "<tr>";
-                    echo "<td>" . htmlspecialcharsFix($customer['cs_company']) . "</td>";
                     echo "<td>¥" . number_format($customer['current_amount'], 2) . "</td>";
                     echo "<td>¥" . number_format($customer['previous_amount'], 2) . "</td>";
                     echo "<td class='{$change_class}'>" . $change_percent . "%</td>";
@@ -366,7 +364,7 @@ include('statistics_header.php');
                 }
                 
                 if ($decreasing_customers->num_rows == 0) {
-                    echo "<tr><td colspan='7' class='text-center'>没有发现订单金额下降的客户</td></tr>";
+                    echo "<tr><td colspan='6' class='text-center'>没有发现订单金额下降的客户</td></tr>";
                 }
                 ?>
             </tbody>
@@ -384,7 +382,6 @@ include('statistics_header.php');
             <thead>
                 <tr>
                     <th>客户编码</th>
-                    <th>客户名称</th>
                     <th>上次订单日期</th>
                     <th>未订单天数</th>
                     <th>历史订单总数</th>
@@ -427,7 +424,6 @@ include('statistics_header.php');
                     
                     echo "<tr>";
                     echo "<td title='{$customer['cs_code']}'>" . htmlspecialcharsFix($customer['cs_code']) . "</td>";
-                    echo "<td>" . htmlspecialcharsFix($customer['cs_company'] ?: '未填写') . "</td>";
                     echo "<td>" . ($customer['last_order_date'] ? $customer['last_order_date'] : '从未下单') . "</td>";
                     echo "<td class='{$inactive_class}'>" . $inactive_days . "</td>";
                     echo "<td>" . $customer['order_count'] . "</td>";
@@ -438,7 +434,7 @@ include('statistics_header.php');
                 }
                 
                 if ($abnormal_customers->num_rows == 0) {
-                    echo "<tr><td colspan='8' class='text-center'>没有发现复购周期异常的客户</td></tr>";
+                    echo "<tr><td colspan='7' class='text-center'>没有发现复购周期异常的客户</td></tr>";
                 }
                 ?>
             </tbody>
@@ -516,7 +512,6 @@ include('statistics_header.php');
             <thead>
                 <tr>
                     <th>客户编码</th>
-                    <th>客户名称</th>
                     <th>最后出货日期</th>
                     <th>未订单天数</th>
                     <th>历史订单数</th>
@@ -550,7 +545,6 @@ include('statistics_header.php');
                     
                     echo "<tr>";
                     echo "<td title='{$customer['cs_code']}'>" . htmlspecialcharsFix($customer['cs_code']) . "</td>";
-                    echo "<td>" . htmlspecialcharsFix($customer['cs_company'] ?: '未填写') . "</td>";
                     echo "<td>" . ($customer['last_order_date'] ? $customer['last_order_date'] : '从未下单') . "</td>";
                     echo "<td class='{$inactive_class}'>" . $inactive_days . "</td>";
                     echo "<td>" . $customer['order_count'] . "</td>";
@@ -561,7 +555,7 @@ include('statistics_header.php');
                 }
                 
                 if ($churn_customers->num_rows == 0) {
-                    echo "<tr><td colspan='8' class='text-center'>没有发现流失客户</td></tr>";
+                    echo "<tr><td colspan='7' class='text-center'>没有发现流失客户</td></tr>";
                 }
                 ?>
             </tbody>
@@ -635,10 +629,24 @@ include('statistics_header.php');
             <p>最近12个月的订单数量和金额趋势</p>
         </div>
         
-        <div class="chart-container">
+        <div class="order-trend-chart-container">
             <canvas id="orderTrendChart"></canvas>
         </div>
         
+        <style>
+            /* 响应式布局:调整图表高度 */
+            .order-trend-chart-container {
+                width: 100%;
+                height: auto;
+            }
+            
+            @media (min-width: 768px) {
+                .order-trend-chart-container {
+                    height: 33vh; /* 视窗高度的1/3 */
+                }
+            }
+        </style>
+        
         <?php
         // 获取最近12个月的订单趋势数据
         $sql_trend = "SELECT 
@@ -647,7 +655,7 @@ include('statistics_header.php');
             SUM(total_amount) as total_amount
         FROM orders o
         JOIN customer c ON o.customer_id = c.id
-        WHERE order_date >= DATE_SUB(?, INTERVAL 11 MONTH)";
+        WHERE o.is_deleted = 0 AND order_date >= DATE_SUB(?, INTERVAL 11 MONTH)";
         
         // 添加业务员筛选条件
         if (is_array($query_employee_filter) && !empty($query_employee_filter)) {
@@ -1151,13 +1159,13 @@ function getDecreasingOrderAmountCustomers($conn, $current_start, $current_end,
         LEFT JOIN (
             SELECT customer_id, SUM(total_amount) as amount
             FROM orders
-            WHERE order_date BETWEEN '{$current_start}' AND '{$current_end}'
+            WHERE is_deleted = 0 AND order_date BETWEEN '{$current_start}' AND '{$current_end}'
             GROUP BY customer_id
         ) current_period ON c.id = current_period.customer_id
         LEFT JOIN (
             SELECT customer_id, SUM(total_amount) as amount
             FROM orders
-            WHERE order_date BETWEEN '{$previous_start}' AND '{$previous_end}'
+            WHERE is_deleted = 0 AND order_date BETWEEN '{$previous_start}' AND '{$previous_end}'
             GROUP BY customer_id
         ) previous_period ON c.id = previous_period.customer_id
         JOIN employee e ON c.cs_belong = e.id
@@ -1177,18 +1185,18 @@ function getDecreasingOrderAmountCustomers($conn, $current_start, $current_end,
         IFNULL(current_period.amount, 0) as current_amount,
         previous_period.amount as previous_amount,
         e.em_user,
-        IFNULL((SELECT MAX(order_date) FROM orders WHERE customer_id = c.id), '') as last_order_date
+        IFNULL((SELECT MAX(order_date) FROM orders WHERE is_deleted = 0 AND customer_id = c.id), '') as last_order_date
     FROM customer c
     LEFT JOIN (
         SELECT customer_id, SUM(total_amount) as amount
         FROM orders
-        WHERE order_date BETWEEN '{$current_start}' AND '{$current_end}'
+        WHERE is_deleted = 0 AND order_date BETWEEN '{$current_start}' AND '{$current_end}'
         GROUP BY customer_id
     ) current_period ON c.id = current_period.customer_id
     LEFT JOIN (
         SELECT customer_id, SUM(total_amount) as amount
         FROM orders
-        WHERE order_date BETWEEN '{$previous_start}' AND '{$previous_end}'
+        WHERE is_deleted = 0 AND order_date BETWEEN '{$previous_start}' AND '{$previous_end}'
         GROUP BY customer_id
     ) previous_period ON c.id = previous_period.customer_id
     JOIN employee e ON c.cs_belong = e.id
@@ -1222,6 +1230,7 @@ function getAbnormalRepurchaseCycleCustomers($conn, $current_start, $current_end
         LEFT JOIN (
             SELECT customer_id, MAX(order_date) as last_order_date
             FROM orders
+            WHERE is_deleted = 0
             GROUP BY customer_id
         ) last_orders ON c.id = last_orders.customer_id
         JOIN employee e ON c.cs_belong = e.id
@@ -1254,11 +1263,13 @@ function getAbnormalRepurchaseCycleCustomers($conn, $current_start, $current_end
     LEFT JOIN (
         SELECT customer_id, MAX(order_date) as last_order_date
         FROM orders
+        WHERE is_deleted = 0
         GROUP BY customer_id
     ) last_orders ON c.id = last_orders.customer_id
     LEFT JOIN (
         SELECT customer_id, COUNT(*) as order_count, SUM(total_amount) as total_amount
         FROM orders
+        WHERE is_deleted = 0
         GROUP BY customer_id
     ) order_stats ON c.id = order_stats.customer_id
     JOIN employee e ON c.cs_belong = e.id
@@ -1317,11 +1328,13 @@ function getInactiveCustomers($conn, $end_date, $inactive_days, $count_only = fa
     LEFT JOIN (
         SELECT customer_id, MAX(order_date) as last_order_date
         FROM orders
+        WHERE is_deleted = 0
         GROUP BY customer_id
     ) last_orders ON c.id = last_orders.customer_id
     LEFT JOIN (
         SELECT customer_id, COUNT(*) as order_count, SUM(total_amount) as total_amount
         FROM orders
+        WHERE is_deleted = 0
         GROUP BY customer_id
     ) order_stats ON c.id = order_stats.customer_id
     JOIN employee e ON c.cs_belong = e.id
@@ -1355,6 +1368,7 @@ function getChurnCustomers($conn, $end_date, $churn_days, $count_only = false, $
         LEFT JOIN (
             SELECT customer_id, MAX(order_date) as last_order_date
             FROM orders
+            WHERE is_deleted = 0
             GROUP BY customer_id
         ) last_orders ON c.id = last_orders.customer_id
         JOIN employee e ON c.cs_belong = e.id
@@ -1387,11 +1401,13 @@ function getChurnCustomers($conn, $end_date, $churn_days, $count_only = false, $
     LEFT JOIN (
         SELECT customer_id, MAX(order_date) as last_order_date
         FROM orders
+        WHERE is_deleted = 0
         GROUP BY customer_id
     ) last_orders ON c.id = last_orders.customer_id
     LEFT JOIN (
         SELECT customer_id, COUNT(*) as order_count, SUM(total_amount) as total_amount
         FROM orders
+        WHERE is_deleted = 0
         GROUP BY customer_id
     ) order_stats ON c.id = order_stats.customer_id
     JOIN employee e ON c.cs_belong = e.id

+ 40 - 78
statistics_products.php

@@ -30,7 +30,7 @@ function getTopProducts($conn, $start_date, $end_date, $limit = 5, $employee_fil
         $sql .= " JOIN customer c ON o.customer_id = c.id";
     }
     
-    $sql .= " WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $sql .= " WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     // 添加业务员过滤
     if ($employee_filter !== null) {
@@ -83,7 +83,7 @@ function getProductSalesTrend($conn, $start_date, $end_date, $product_id = 0, $p
         $sql .= " JOIN customer c ON o.customer_id = c.id";
     }
     
-    $sql .= " WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $sql .= " WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     if ($product_id > 0) {
         $sql .= " AND oi.product_id = $product_id";
@@ -132,7 +132,7 @@ function getProductCategorySales($conn, $start_date, $end_date, $employee_filter
         $sql .= " JOIN customer c ON o.customer_id = c.id";
     }
     
-    $sql .= " WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $sql .= " WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     // 添加业务员过滤
     if ($employee_filter !== null) {
@@ -175,7 +175,7 @@ function getProductRegionAnalysis($conn, $start_date, $end_date, $employee_filte
             JOIN customer cu ON o.customer_id = cu.id
             JOIN country c ON cu.cs_country = c.id";
     
-    $sql .= " WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $sql .= " WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     // 添加业务员过滤
     if ($employee_filter !== null) {
@@ -208,7 +208,7 @@ function getProductRegionAnalysis($conn, $start_date, $end_date, $employee_filte
  * @return array 产品销售概览数据
  */
 function getProductSalesOverview($conn, $start_date, $end_date, $category_filter = 0, $employee_filter = null) {
-    $where_clause = "WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $where_clause = "WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     if ($category_filter > 0) {
         $where_clause .= " AND p.category_id = $category_filter";
@@ -274,7 +274,7 @@ function getProductPriceTrendAnalysis($conn, $start_date, $end_date, $product_id
         $sql .= " JOIN customer c ON o.customer_id = c.id";
     }
     
-    $sql .= " WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $sql .= " WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     if ($product_id > 0) {
         $sql .= " AND oi.product_id = $product_id";
@@ -321,7 +321,7 @@ function getProductSeasonalityAnalysis($conn, $start_date, $end_date, $product_i
         $sql .= " JOIN customer c ON o.customer_id = c.id";
     }
     
-    $sql .= " WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $sql .= " WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     if ($product_id > 0) {
         $sql .= " AND oi.product_id = $product_id";
@@ -368,7 +368,7 @@ function getProductCustomerSegmentAnalysis($conn, $start_date, $end_date, $produ
             JOIN customer c ON o.customer_id = c.id
             JOIN clienttype ct ON c.cs_type = ct.id";
     
-    $sql .= " WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $sql .= " WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     if ($product_id > 0) {
         $sql .= " AND oi.product_id = $product_id";
@@ -422,9 +422,9 @@ function getProductCategories($conn) {
  */
 function renderTopProductsTable($top_products) {
     ?>
-    <div class="chart-container">
+    <div class="chart-container" style="padding-left:0px;padding-right: 0px;">
         <div class="chart-header">
-            <h2 class="chart-title">热门产品</h2>
+            <h2 class="chart-title">热门产品 TOP 10</h2>
         </div>
         <table class="data-table">
             <thead>
@@ -1066,7 +1066,7 @@ function getProductGrowthAnalysis($conn, $start_date, $end_date, $period = 'mont
         $sql .= " JOIN customer c ON o.customer_id = c.id";
     }
     
-    $sql .= " WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+    $sql .= " WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     // 添加业务员过滤
     if ($employee_filter !== null) {
@@ -1105,7 +1105,7 @@ function getProductGrowthAnalysis($conn, $start_date, $end_date, $period = 'mont
             FROM order_items oi
             JOIN products p ON oi.product_id = p.id
             JOIN orders o ON oi.order_id = o.id
-            WHERE o.order_date BETWEEN '$prev_start' AND '$prev_end'
+            WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$prev_start' AND '$prev_end'
             GROUP BY oi.product_id";
     
     $prev_result = $conn->query($sql);
@@ -1251,11 +1251,12 @@ function getProductPurchaseFrequency($conn, $start_date, $end_date, $employee_fi
                 FROM orders o1
                 LEFT JOIN orders o2 ON o1.customer_id = o2.customer_id 
                     AND o2.order_date > o1.order_date
-                WHERE o1.order_date BETWEEN '$start_date' AND '$end_date'
+                    AND o2.is_deleted = 0
+                WHERE o1.is_deleted = 0 AND o1.order_date BETWEEN '$start_date' AND '$end_date'
                 GROUP BY o1.customer_id, o1.order_date
             ) next_order ON o.customer_id = next_order.customer_id 
                 AND o.order_date = next_order.order_date
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'";
+            WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'";
     
     // 添加业务员过滤
     if ($employee_filter !== null) {
@@ -1324,7 +1325,25 @@ function renderProductPurchaseFrequency($frequency_data) {
  * @return array 新客户购买产品明细数据
  */
 function getNewCustomerProductPurchases($conn, $start_date, $end_date, $category_filter = 0, $employee_filter = null) {
-    // 获取符合条件的新客户订单
+
+    // 获取新客户ID列表 - 使用cs_dealdate作为判断标准
+    $new_customer_sql = "SELECT id 
+                        FROM customer 
+                        WHERE cs_dealdate BETWEEN '$start_date' AND '$end_date'";
+    
+    // 添加业务员过滤
+    if ($employee_filter !== null) {
+        if (is_array($employee_filter)) {
+            if (count($employee_filter) > 0) {
+                $employee_ids = implode(',', $employee_filter);
+                $new_customer_sql .= " AND cs_belong IN ($employee_ids)";
+            }
+        } else {
+            $new_customer_sql .= " AND cs_belong = $employee_filter";
+        }
+    }
+    
+    // 获取符合条件的新客户产品购买数据
     $sql = "SELECT 
                 p.ProductName,
                 p.id as product_id,
@@ -1339,30 +1358,8 @@ function getNewCustomerProductPurchases($conn, $start_date, $end_date, $category
             JOIN products p ON oi.product_id = p.id
             JOIN product_categories pc ON p.category_id = pc.id
             JOIN customer c ON o.customer_id = c.id
-            WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
-            AND o.id IN (
-                SELECT MIN(id) 
-                FROM orders 
-                WHERE order_date BETWEEN '$start_date' AND '$end_date'";
-    
-    if ($employee_filter !== null) {
-        $sql .= " AND customer_id IN (
-                    SELECT id FROM customer WHERE ";
-        
-        if (is_array($employee_filter)) {
-            if (count($employee_filter) > 0) {
-                $employee_ids = implode(',', $employee_filter);
-                $sql .= "cs_belong IN ($employee_ids))";
-            } else {
-                $sql .= "1=1)";
-            }
-        } else {
-            $sql .= "cs_belong = $employee_filter)";
-        }
-    }
-    
-    $sql .= " GROUP BY customer_id
-            )";
+            WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN '$start_date' AND '$end_date'
+            AND o.customer_id IN ($new_customer_sql)";
     
     if ($category_filter > 0) {
         $sql .= " AND p.category_id = $category_filter";
@@ -1381,50 +1378,15 @@ function getNewCustomerProductPurchases($conn, $start_date, $end_date, $category
     }
     
     $sql .= " GROUP BY p.id
-              ORDER BY customer_count DESC, total_revenue DESC";
+              ORDER BY customer_count DESC, total_revenue DESC
+              LIMIT 10";
     
     $result = $conn->query($sql);
     
     // 查询新客户总数
     $sql_count = "SELECT 
-                    COUNT(DISTINCT o.customer_id) as total_new_customers
-                FROM orders o
-                JOIN customer c ON o.customer_id = c.id
-                WHERE o.order_date BETWEEN '$start_date' AND '$end_date'
-                AND o.id IN (
-                    SELECT MIN(id) 
-                    FROM orders 
-                    WHERE order_date BETWEEN '$start_date' AND '$end_date'";
-    
-    if ($employee_filter !== null) {
-        $sql_count .= " AND customer_id IN (
-                        SELECT id FROM customer WHERE ";
-        
-        if (is_array($employee_filter)) {
-            if (count($employee_filter) > 0) {
-                $employee_ids = implode(',', $employee_filter);
-                $sql_count .= "cs_belong IN ($employee_ids))";
-            } else {
-                $sql_count .= "1=1)";
-            }
-        } else {
-            $sql_count .= "cs_belong = $employee_filter)";
-        }
-    }
-    
-    $sql_count .= " GROUP BY customer_id
-                )";
-    
-    if ($employee_filter !== null) {
-        if (is_array($employee_filter)) {
-            if (count($employee_filter) > 0) {
-                $employee_ids = implode(',', $employee_filter);
-                $sql_count .= " AND c.cs_belong IN ($employee_ids)";
-            }
-        } else {
-            $sql_count .= " AND c.cs_belong = $employee_filter";
-        }
-    }
+                    COUNT(*) as total_new_customers
+                FROM ($new_customer_sql) as new_customers";
     
     $result_count = $conn->query($sql_count);
     $count_row = $result_count->fetch_assoc();

+ 334 - 151
statistics_region.php

@@ -58,10 +58,12 @@ function getCustomerCountryDistribution($conn, $employee_filter = null) {
  * @param string $start_date 开始日期
  * @param string $end_date 结束日期
  * @param array|int|null $employee_filter 业务员ID或ID数组,用于过滤数据
+ * @param int $country_filter 国家/地区ID,默认为0表示全部地区
  * @return mysqli_result 地区订单数据结果集
  */
-function getOrdersByRegion($conn, $start_date, $end_date, $employee_filter = null) {
+function getOrdersByRegion($conn, $start_date, $end_date, $employee_filter = null, $country_filter = 0) {
     $employee_condition = "";
+    $country_condition = "";
     $params = [$start_date, $end_date];
     $types = "ss";
     
@@ -86,32 +88,41 @@ function getOrdersByRegion($conn, $start_date, $end_date, $employee_filter = nul
         }
     }
     
-    $sql = "SELECT 
-                c.countryName, 
-                COUNT(DISTINCT o.id) as order_count,
-                SUM(o.total_amount) as total_amount,
-                (SELECT SUM(oi_sub.quantity) 
-                 FROM order_items oi_sub 
-                 JOIN orders o_sub ON oi_sub.order_id = o_sub.id
-                 JOIN customer cu_sub ON o_sub.customer_id = cu_sub.id
-                 WHERE o_sub.order_date BETWEEN ? AND ?
-                 AND cu_sub.cs_country = cu.cs_country
-                 $employee_condition) as total_quantity
-            FROM orders o
-            JOIN customer cu ON o.customer_id = cu.id
-            JOIN country c ON cu.cs_country = c.id
-            WHERE o.order_date BETWEEN ? AND ?
-            $employee_condition
-            GROUP BY cu.cs_country
-            ORDER BY total_quantity DESC
-            LIMIT 10";
+    // 添加国家/地区筛选条件
+    if (is_numeric($country_filter) && $country_filter > 0) {
+        $country_filter = intval($country_filter);
+        $country_condition = " AND cu.cs_country = $country_filter";
+    }
     
-    // 添加额外的参数用于子查询
-    $params = array_merge([$start_date, $end_date], $params);
-    $types = "ss" . $types;
+    // 如果选择了特定国家/地区,则SQL语句不需要分组和排序,直接返回该国家/地区的数据
+    if ($country_filter > 0) {
+        $sql = "SELECT 
+                    c.countryName, 
+                    COUNT(DISTINCT o.id) as order_count,
+                    SUM(o.total_amount) as total_amount
+                FROM orders o
+                JOIN customer cu ON o.customer_id = cu.id
+                JOIN country c ON cu.cs_country = c.id
+                WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
+                $employee_condition
+                $country_condition
+                GROUP BY cu.cs_country";
+    } else {
+        // 否则返回前10个地区的数据
+        $sql = "SELECT 
+                    c.countryName, 
+                    COUNT(DISTINCT o.id) as order_count,
+                    SUM(o.total_amount) as total_amount
+                FROM orders o
+                JOIN customer cu ON o.customer_id = cu.id
+                JOIN country c ON cu.cs_country = c.id
+                WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
+                $employee_condition
+                GROUP BY cu.cs_country
+                ORDER BY total_amount DESC
+                LIMIT 10";
+    }
     
-
-
     $stmt = $conn->prepare($sql);
     $stmt->bind_param($types, ...$params);
     $stmt->execute();
@@ -125,9 +136,10 @@ function getOrdersByRegion($conn, $start_date, $end_date, $employee_filter = nul
  * @param string $current_start 当前周期开始日期
  * @param string $current_end 当前周期结束日期
  * @param array|int|null $employee_filter 业务员ID或ID数组,用于过滤数据
+ * @param int $country_filter 国家/地区ID,默认为0表示全部地区
  * @return array 地区销售同比环比数据
  */
-function getRegionSalesComparison($conn, $current_start, $current_end, $employee_filter = null) {
+function getRegionSalesComparison($conn, $current_start, $current_end, $employee_filter = null, $country_filter = 0) {
     // 计算上一个相同时长的周期
     $current_start_date = new DateTime($current_start);
     $current_end_date = new DateTime($current_end);
@@ -164,6 +176,16 @@ function getRegionSalesComparison($conn, $current_start, $current_end, $employee
         }
     }
     
+    // 添加国家/地区筛选条件
+    $country_condition = "";
+    if (is_numeric($country_filter) && $country_filter > 0) {
+        $country_filter = intval($country_filter);
+        $country_condition = " AND cu.cs_country = $country_filter";
+    }
+    
+    // 如果选择了特定国家/地区,就不需要LIMIT了
+    $limit_clause = ($country_filter > 0) ? "" : "LIMIT 5";
+    
     // 获取当前周期数据
     $sql = "SELECT 
                 c.countryName, 
@@ -172,11 +194,12 @@ function getRegionSalesComparison($conn, $current_start, $current_end, $employee
             FROM orders o
             JOIN customer cu ON o.customer_id = cu.id
             JOIN country c ON cu.cs_country = c.id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             $employee_condition
+            $country_condition
             GROUP BY cu.cs_country
             ORDER BY total_amount DESC
-            LIMIT 5";
+            $limit_clause";
     
     $stmt = $conn->prepare($sql);
     $stmt->bind_param("ss", $current_start, $current_end);
@@ -241,13 +264,27 @@ function getRegionSalesComparison($conn, $current_start, $current_end, $employee
  */
 function renderCustomerCountryDistributionChart($country_labels, $country_data) {
     ?>
-    <div class="chart-container">
+    <div class="chart-container country-distribution-chart">
         <div class="chart-header">
             <h2 class="chart-title">客户国家分布</h2>
         </div>
         <canvas id="countryDistributionChart"></canvas>
     </div>
     
+    <style>
+        /* 响应式布局:手机端全宽,PC端1/3宽度 */
+        .country-distribution-chart {
+            width: 100%;
+            margin: 0 auto;
+        }
+        
+        @media (min-width: 768px) {
+            .country-distribution-chart {
+                max-width: 33.333%;
+            }
+        }
+    </style>
+    
     <script>
         // 客户国家分布图
         var countryDistributionCtx = document.getElementById('countryDistributionChart').getContext('2d');
@@ -290,18 +327,31 @@ function renderCustomerCountryDistributionChart($country_labels, $country_data)
  * 
  * @param array $region_labels 地区标签
  * @param array $region_orders 地区订单数量
- * @param array $region_quantities 地区产品数量
  * @return void
  */
-function renderRegionOrdersChart($region_labels, $region_orders, $region_quantities) {
+function renderRegionOrdersChart($region_labels, $region_orders) {
     ?>
-    <div class="chart-container">
-        <div class="chart-header">
-            <h2 class="chart-title">地区订单分析</h2>
-        </div>
+    <div class="chart-header">
+        <h2 class="chart-title">地区订单分析</h2>
+    </div>
+    <div class="region-orders-chart-container">
         <canvas id="regionOrdersChart"></canvas>
     </div>
     
+    <style>
+        /* 响应式布局:调整图表高度 */
+        .region-orders-chart-container {
+            width: 100%;
+            height: auto;
+        }
+        
+        @media (min-width: 768px) {
+            .region-orders-chart-container {
+                height: 33vh; /* 视窗高度的1/3 */
+            }
+        }
+    </style>
+    
     <script>
         // 地区订单分析图
         var regionOrdersCtx = document.getElementById('regionOrdersChart').getContext('2d');
@@ -315,21 +365,13 @@ function renderRegionOrdersChart($region_labels, $region_orders, $region_quantit
                         data: <?php echo json_encode($region_orders); ?>,
                         backgroundColor: 'rgba(54, 162, 235, 0.6)',
                         borderColor: 'rgba(54, 162, 235, 1)',
-                        borderWidth: 1,
-                        yAxisID: 'y-orders'
-                    },
-                    {
-                        label: '产品订购数量',
-                        data: <?php echo json_encode($region_quantities); ?>,
-                        backgroundColor: 'rgba(255, 99, 132, 0.6)',
-                        borderColor: 'rgba(255, 99, 132, 1)',
-                        borderWidth: 1,
-                        yAxisID: 'y-quantity'
+                        borderWidth: 1
                     }
                 ]
             },
             options: {
                 responsive: true,
+                maintainAspectRatio: false, // 允许图表高度自适应
                 scales: {
                     x: {
                         title: {
@@ -337,26 +379,12 @@ function renderRegionOrdersChart($region_labels, $region_orders, $region_quantit
                             text: '地区'
                         }
                     },
-                    'y-orders': {
-                        type: 'linear',
-                        position: 'left',
+                    y: {
                         title: {
                             display: true,
                             text: '订单数量'
                         },
                         beginAtZero: true
-                    },
-                    'y-quantity': {
-                        type: 'linear',
-                        position: 'right',
-                        title: {
-                            display: true,
-                            text: '产品订购数量'
-                        },
-                        beginAtZero: true,
-                        grid: {
-                            drawOnChartArea: false
-                        }
                     }
                 }
             }
@@ -377,50 +405,68 @@ function renderRegionSalesComparisonTable($comparison_data) {
         <div class="chart-header">
             <h2 class="chart-title">地区销售同比分析</h2>
         </div>
-        <table class="data-table">
-            <thead>
-                <tr>
-                    <th>国家/地区</th>
-                    <th>当前订单数</th>
-                    <th>上期订单数</th>
-                    <th>订单增长率</th>
-                    <th>当前销售额</th>
-                    <th>上期销售额</th>
-                    <th>销售额增长率</th>
-                </tr>
-            </thead>
-            <tbody>
-                <?php foreach ($comparison_data as $row): ?>
-                <tr>
-                    <td><?php echo htmlspecialchars($row['countryName']); ?></td>
-                    <td><?php echo number_format($row['current_orders']); ?></td>
-                    <td><?php echo number_format($row['prev_orders']); ?></td>
-                    <td class="<?php echo $row['order_growth'] >= 0 ? 'positive' : 'negative'; ?>">
-                        <?php echo number_format($row['order_growth'], 2); ?>%
-                    </td>
-                    <td>¥<?php echo number_format($row['current_amount'], 2); ?></td>
-                    <td>¥<?php echo number_format($row['prev_amount'], 2); ?></td>
-                    <td class="<?php echo $row['amount_growth'] >= 0 ? 'positive' : 'negative'; ?>">
-                        <?php echo number_format($row['amount_growth'], 2); ?>%
-                    </td>
-                </tr>
-                <?php endforeach; ?>
-            </tbody>
-        </table>
+        <div class="region-sales-comparison-container">
+            <table class="data-table">
+                <thead>
+                    <tr>
+                        <th>国家/地区</th>
+                        <th>当前订单数</th>
+                        <th>上期订单数</th>
+                        <th>订单增长率</th>
+                        <th>当前销售额</th>
+                        <th>上期销售额</th>
+                        <th>销售额增长率</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    <?php foreach ($comparison_data as $row): ?>
+                    <tr>
+                        <td><?php echo htmlspecialchars($row['countryName']); ?></td>
+                        <td><?php echo number_format($row['current_orders']); ?></td>
+                        <td><?php echo number_format($row['prev_orders']); ?></td>
+                        <td class="<?php echo $row['order_growth'] >= 0 ? 'positive' : 'negative'; ?>">
+                            <?php echo number_format($row['order_growth'], 2); ?>%
+                        </td>
+                        <td>¥<?php echo number_format($row['current_amount'], 2); ?></td>
+                        <td>¥<?php echo number_format($row['prev_amount'], 2); ?></td>
+                        <td class="<?php echo $row['amount_growth'] >= 0 ? 'positive' : 'negative'; ?>">
+                            <?php echo number_format($row['amount_growth'], 2); ?>%
+                        </td>
+                    </tr>
+                    <?php endforeach; ?>
+                </tbody>
+            </table>
+        </div>
     </div>
+    
+    <style>
+        /* 响应式布局:调整表格容器 */
+        .region-sales-comparison-container {
+            width: 100%;
+            overflow-x: auto;
+        }
+        
+        @media (min-width: 768px) {
+            .region-sales-comparison-container {
+                max-height: 33vh; /* 视窗高度的1/3 */
+                overflow-y: auto;
+            }
+        }
+    </style>
     <?php
 }
 
 /**
- * 获取地区总销售额及增长率
+ * 获取地区总销售额
  * 
  * @param mysqli $conn 数据库连接
  * @param string $start_date 开始日期
  * @param string $end_date 结束日期
  * @param array|int|null $employee_filter 业务员ID或ID数组,用于过滤数据
+ * @param int $country_filter 国家/地区ID,默认为0表示全部地区
  * @return array 总销售额和增长率
  */
-function getRegionTotalSales($conn, $start_date, $end_date, $employee_filter = null) {
+function getRegionTotalSales($conn, $start_date, $end_date, $employee_filter = null, $country_filter = 0) {
     // 如果有业务员过滤条件
     $employee_condition = "";
     
@@ -444,12 +490,19 @@ function getRegionTotalSales($conn, $start_date, $end_date, $employee_filter = n
         }
     }
     
+    // 添加国家/地区筛选条件
+    $country_condition = "";
+    if (is_numeric($country_filter) && $country_filter > 0) {
+        $country_condition = " AND cu.cs_country = " . intval($country_filter);
+    }
+    
     // 计算当前周期销售额
     $sql = "SELECT SUM(o.total_amount) as total_amount
             FROM orders o
             JOIN customer cu ON o.customer_id = cu.id
-            WHERE o.order_date BETWEEN ? AND ?
-            $employee_condition";
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
+            $employee_condition
+            $country_condition";
     
     $stmt = $conn->prepare($sql);
     $stmt->bind_param("ss", $start_date, $end_date);
@@ -498,9 +551,10 @@ function getRegionTotalSales($conn, $start_date, $end_date, $employee_filter = n
  * @param string $start_date 开始日期
  * @param string $end_date 结束日期
  * @param array|int|null $employee_filter 业务员ID或ID数组,用于过滤数据
+ * @param int $country_filter 国家/地区ID,默认为0表示全部地区
  * @return array 活跃国家信息
  */
-function getActiveCountries($conn, $start_date, $end_date, $employee_filter = null) {
+function getActiveCountries($conn, $start_date, $end_date, $employee_filter = null, $country_filter = 0) {
     // 如果有业务员过滤条件
     $employee_condition = "";
     
@@ -524,11 +578,26 @@ function getActiveCountries($conn, $start_date, $end_date, $employee_filter = nu
         }
     }
     
-    $sql = "SELECT COUNT(DISTINCT cu.cs_country) as country_count
-            FROM orders o
-            JOIN customer cu ON o.customer_id = cu.id
-            WHERE o.order_date BETWEEN ? AND ?
-            $employee_condition";
+    // 添加国家/地区筛选条件
+    $country_condition = "";
+    if (is_numeric($country_filter) && $country_filter > 0) {
+        $country_condition = " AND cu.cs_country = " . intval($country_filter);
+        // 如果指定了国家/地区,则活跃国家数为1或0
+        $sql = "SELECT COUNT(*) as country_count
+                FROM orders o
+                JOIN customer cu ON o.customer_id = cu.id
+                WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
+                $employee_condition
+                $country_condition
+                LIMIT 1";
+    } else {
+        // 否则计算所有活跃国家
+        $sql = "SELECT COUNT(DISTINCT cu.cs_country) as country_count
+                FROM orders o
+                JOIN customer cu ON o.customer_id = cu.id
+                WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
+                $employee_condition";
+    }
     
     $stmt = $conn->prepare($sql);
     $stmt->bind_param("ss", $start_date, $end_date);
@@ -581,7 +650,7 @@ function getAverageOrderByRegion($conn, $start_date, $end_date, $employee_filter
             FROM orders o
             JOIN customer cu ON o.customer_id = cu.id
             JOIN country c ON cu.cs_country = c.id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             $employee_condition
             GROUP BY cu.cs_country
             HAVING order_count >= 5
@@ -660,7 +729,7 @@ function getRegionCategoryPreferences($conn, $start_date, $end_date, $employee_f
             JOIN order_items oi ON o.id = oi.order_id
             JOIN products p ON oi.product_id = p.id
             JOIN product_categories pc ON p.category_id = pc.id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             $employee_condition
             GROUP BY cu.cs_country, p.category_id
             ORDER BY c.countryName, total_quantity DESC";
@@ -713,9 +782,10 @@ function getRegionCategoryPreferences($conn, $start_date, $end_date, $employee_f
  * @param string $end_date 结束日期
  * @param string $period 时间粒度 (day/week/month)
  * @param array|int|null $employee_filter 业务员ID或ID数组,用于过滤数据
+ * @param int $country_filter 国家/地区ID,默认为0表示全部地区
  * @return array 地区销售增长趋势数据
  */
-function getRegionGrowthTrends($conn, $start_date, $end_date, $period = 'month', $employee_filter = null) {
+function getRegionGrowthTrends($conn, $start_date, $end_date, $period = 'month', $employee_filter = null, $country_filter = 0) {
     $period_format = getPeriodFormat($period);
     
     // 如果有业务员过滤条件
@@ -741,6 +811,13 @@ function getRegionGrowthTrends($conn, $start_date, $end_date, $period = 'month',
         }
     }
     
+    // 添加国家/地区筛选条件
+    $country_condition = "";
+    if (is_numeric($country_filter) && $country_filter > 0) {
+        $country_filter = intval($country_filter);
+        $country_condition = " AND cu.cs_country = $country_filter";
+    }
+    
     $sql = "SELECT 
                 c.countryName,
                 DATE_FORMAT(o.order_date, ?) as time_period,
@@ -748,8 +825,9 @@ function getRegionGrowthTrends($conn, $start_date, $end_date, $period = 'month',
             FROM orders o
             JOIN customer cu ON o.customer_id = cu.id
             JOIN country c ON cu.cs_country = c.id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             $employee_condition
+            $country_condition
             GROUP BY cu.cs_country, time_period
             ORDER BY c.countryName, time_period";
     
@@ -773,17 +851,22 @@ function getRegionGrowthTrends($conn, $start_date, $end_date, $period = 'month',
         $trends[$row['countryName']][$row['time_period']] = $row['total_amount'];
     }
     
-    // 只保留前5个主要市场
-    $top_markets = array_slice(array_keys($trends), 0, 5);
-    $filtered_trends = [];
-    
-    foreach ($top_markets as $market) {
-        $filtered_trends[$market] = $trends[$market];
+    // 只有在没有国家/地区筛选条件时才筛选前10个市场
+    if ($country_filter == 0) {
+        // 只保留前10个主要市场
+        $top_markets = array_slice(array_keys($trends), 0, 10);
+        $filtered_trends = [];
+        
+        foreach ($top_markets as $market) {
+            $filtered_trends[$market] = $trends[$market];
+        }
+        
+        $trends = $filtered_trends;
     }
     
     return [
         'time_periods' => $time_periods,
-        'trends' => $filtered_trends
+        'trends' => $trends
     ];
 }
 
@@ -792,9 +875,10 @@ function getRegionGrowthTrends($conn, $start_date, $end_date, $period = 'month',
  * 
  * @param mysqli $conn 数据库连接
  * @param array|int|null $employee_filter 业务员ID或ID数组,用于过滤数据
+ * @param int $country_filter 国家/地区ID,默认为0表示全部地区
  * @return array 地区季节性销售分析数据
  */
-function getRegionSeasonalAnalysis($conn, $employee_filter = null) {
+function getRegionSeasonalAnalysis($conn, $employee_filter = null, $country_filter = 0) {
     // 如果有业务员过滤条件
     $employee_condition = "";
     
@@ -818,6 +902,13 @@ function getRegionSeasonalAnalysis($conn, $employee_filter = null) {
         }
     }
     
+    // 添加国家/地区筛选条件
+    $country_condition = "";
+    if (is_numeric($country_filter) && $country_filter > 0) {
+        $country_filter = intval($country_filter);
+        $country_condition = " AND cu.cs_country = $country_filter";
+    }
+    
     $sql = "SELECT 
                 c.countryName,
                 MONTH(o.order_date) as month,
@@ -825,8 +916,9 @@ function getRegionSeasonalAnalysis($conn, $employee_filter = null) {
             FROM orders o
             JOIN customer cu ON o.customer_id = cu.id
             JOIN country c ON cu.cs_country = c.id
-            WHERE o.order_date >= DATE_SUB(CURDATE(), INTERVAL 2 YEAR)
+            WHERE o.is_deleted = 0 AND o.order_date >= DATE_SUB(CURDATE(), INTERVAL 2 YEAR)
             $employee_condition
+            $country_condition
             GROUP BY cu.cs_country, month
             ORDER BY c.countryName, month";
     
@@ -843,17 +935,29 @@ function getRegionSeasonalAnalysis($conn, $employee_filter = null) {
         $seasonal[$row['countryName']][$row['month']] += $row['total_amount'];
     }
     
-    // 只保留前5个主要市场
-    $top_markets = array_slice(array_keys($seasonal), 0, 5);
-    $filtered_seasonal = [];
-    
-    foreach ($top_markets as $market) {
-        $filtered_seasonal[$market] = array_values($seasonal[$market]);
+    // 只有在没有国家/地区筛选条件时才筛选前10个市场
+    if ($country_filter == 0) {
+        // 只保留前10个主要市场
+        $top_markets = array_slice(array_keys($seasonal), 0, 10);
+        $filtered_seasonal = [];
+        
+        foreach ($top_markets as $market) {
+            $filtered_seasonal[$market] = array_values($seasonal[$market]);
+        }
+        
+        $seasonal = $filtered_seasonal;
+    } else {
+        // 如果有国家筛选,转换为数组值形式
+        $filtered_seasonal = [];
+        foreach ($seasonal as $market => $months_data) {
+            $filtered_seasonal[$market] = array_values($months_data);
+        }
+        $seasonal = $filtered_seasonal;
     }
     
     return [
         'months' => ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
-        'data' => $filtered_seasonal
+        'data' => $seasonal
     ];
 }
 
@@ -864,9 +968,10 @@ function getRegionSeasonalAnalysis($conn, $employee_filter = null) {
  * @param string $start_date 开始日期
  * @param string $end_date 结束日期
  * @param array|int|null $employee_filter 业务员ID或ID数组,用于过滤数据
+ * @param int $country_filter 国家/地区ID,默认为0表示全部地区
  * @return array 地区销售预测数据
  */
-function getRegionSalesForecast($conn, $start_date, $end_date, $employee_filter = null) {
+function getRegionSalesForecast($conn, $start_date, $end_date, $employee_filter = null, $country_filter = 0) {
     // 如果有业务员过滤条件
     $employee_condition = "";
     
@@ -890,6 +995,13 @@ function getRegionSalesForecast($conn, $start_date, $end_date, $employee_filter
         }
     }
     
+    // 添加国家/地区筛选条件
+    $country_condition = "";
+    if (is_numeric($country_filter) && $country_filter > 0) {
+        $country_filter = intval($country_filter);
+        $country_condition = " AND cu.cs_country = $country_filter";
+    }
+    
     // 获取过去12个月的销售数据作为基础
     $sql = "SELECT 
                 c.countryName,
@@ -899,8 +1011,9 @@ function getRegionSalesForecast($conn, $start_date, $end_date, $employee_filter
             FROM orders o
             JOIN customer cu ON o.customer_id = cu.id
             JOIN country c ON cu.cs_country = c.id
-            WHERE o.order_date >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
+            WHERE o.is_deleted = 0 AND o.order_date >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
             $employee_condition
+            $country_condition
             GROUP BY cu.cs_country, year, month
             ORDER BY c.countryName, year, month";
     
@@ -947,8 +1060,13 @@ function getRegionSalesForecast($conn, $start_date, $end_date, $employee_filter
     // 合并历史和预测时间点
     $all_chart_periods = array_merge($all_periods, $future_periods);
     
-    // 只选取主要的5个市场做预测
-    $top_markets = array_slice(array_keys($historical), 0, 5);
+    // 只有在没有国家/地区筛选条件时才筛选前10个市场
+    $top_markets = array_keys($historical);
+    if ($country_filter == 0) {
+        // 只选取主要的10个市场做预测
+        $top_markets = array_slice($top_markets, 0, 10);
+    }
+    
     $forecast_data = [];
     
     foreach ($top_markets as $market) {
@@ -1194,7 +1312,23 @@ function renderRegionGrowthTrendsChart($growth_data) {
     <div class="chart-header">
         <h2 class="chart-title">地区销售增长趋势</h2>
     </div>
-    <canvas id="growthTrendsChart"></canvas>
+    <div class="region-growth-chart-container">
+        <canvas id="growthTrendsChart"></canvas>
+    </div>
+    
+    <style>
+        /* 响应式布局:调整图表高度 */
+        .region-growth-chart-container {
+            width: 100%;
+            height: auto;
+        }
+        
+        @media (min-width: 768px) {
+            .region-growth-chart-container {
+                height: 33vh; /* 视窗高度的1/3 */
+            }
+        }
+    </style>
     
     <script>
         // 地区销售增长趋势图
@@ -1207,6 +1341,7 @@ function renderRegionGrowthTrendsChart($growth_data) {
             },
             options: {
                 responsive: true,
+                maintainAspectRatio: false, // 允许图表高度自适应
                 scales: {
                     x: {
                         title: {
@@ -1263,7 +1398,23 @@ function renderRegionSeasonalAnalysisChart($seasonal_data) {
     <div class="chart-header">
         <h2 class="chart-title">地区季节性销售分析</h2>
     </div>
-    <canvas id="seasonalAnalysisChart"></canvas>
+    <div class="region-seasonal-chart-container">
+        <canvas id="seasonalAnalysisChart"></canvas>
+    </div>
+    
+    <style>
+        /* 响应式布局:调整图表高度 */
+        .region-seasonal-chart-container {
+            width: 100%;
+            height: auto;
+        }
+        
+        @media (min-width: 768px) {
+            .region-seasonal-chart-container {
+                height: 33vh; /* 视窗高度的1/3 */
+            }
+        }
+    </style>
     
     <script>
         // 地区季节性销售分析图
@@ -1276,6 +1427,7 @@ function renderRegionSeasonalAnalysisChart($seasonal_data) {
             },
             options: {
                 responsive: true,
+                maintainAspectRatio: false, // 允许图表高度自适应
                 scales: {
                     x: {
                         title: {
@@ -1360,7 +1512,23 @@ function renderRegionSalesForecastChart($forecast_data) {
     <div class="chart-header">
         <h2 class="chart-title">地区销售预测 (未来6个月)</h2>
     </div>
-    <canvas id="forecastChart"></canvas>
+    <div class="region-forecast-chart-container">
+        <canvas id="forecastChart"></canvas>
+    </div>
+    
+    <style>
+        /* 响应式布局:调整图表高度 */
+        .region-forecast-chart-container {
+            width: 100%;
+            height: auto;
+        }
+        
+        @media (min-width: 768px) {
+            .region-forecast-chart-container {
+                height: 33vh; /* 视窗高度的1/3 */
+            }
+        }
+    </style>
     
     <script>
         // 地区销售预测图
@@ -1373,6 +1541,7 @@ function renderRegionSalesForecastChart($forecast_data) {
             },
             options: {
                 responsive: true,
+                maintainAspectRatio: false, // 允许图表高度自适应
                 scales: {
                     x: {
                         title: {
@@ -1407,35 +1576,49 @@ function renderRegionSalesForecastChart($forecast_data) {
  * 
  * @param array $region_labels 地区标签
  * @param array $region_order_counts 地区订单数量
- * @param array $region_quantities 地区产品数量
  * @param array $region_amounts 地区销售金额
  * @return void
  */
-function renderTopRegionsTable($region_labels, $region_order_counts, $region_quantities, $region_amounts) {
+function renderTopRegionsTable($region_labels, $region_order_counts, $region_amounts) {
     ?>
-    <table class="data-table">
-        <thead>
-            <tr>
-                <th>排名</th>
-                <th>国家/地区</th>
-                <th>订单数</th>
-                <th>产品数量</th>
-                <th>销售金额</th>
-                <th>平均订单金额</th>
-            </tr>
-        </thead>
-        <tbody>
-            <?php for ($i = 0; $i < count($region_labels); $i++): ?>
+    <div class="top-regions-table-container">
+        <table class="data-table">
+            <thead>
                 <tr>
-                    <td><?php echo $i + 1; ?></td>
-                    <td><?php echo htmlspecialchars($region_labels[$i]); ?></td>
-                    <td><?php echo number_format($region_order_counts[$i]); ?></td>
-                    <td><?php echo number_format($region_quantities[$i]); ?></td>
-                    <td>¥<?php echo number_format($region_amounts[$i], 2); ?></td>
-                    <td>¥<?php echo number_format($region_order_counts[$i] > 0 ? $region_amounts[$i] / $region_order_counts[$i] : 0, 2); ?></td>
+                    <th>排名</th>
+                    <th>国家/地区</th>
+                    <th>订单数</th>
+                    <th>销售金额</th>
+                    <th>平均订单金额</th>
                 </tr>
-            <?php endfor; ?>
-        </tbody>
-    </table>
+            </thead>
+            <tbody>
+                <?php for ($i = 0; $i < count($region_labels); $i++): ?>
+                    <tr>
+                        <td><?php echo $i + 1; ?></td>
+                        <td><?php echo htmlspecialchars($region_labels[$i]); ?></td>
+                        <td><?php echo number_format($region_order_counts[$i]); ?></td>
+                        <td>¥<?php echo number_format($region_amounts[$i], 2); ?></td>
+                        <td>¥<?php echo number_format($region_order_counts[$i] > 0 ? $region_amounts[$i] / $region_order_counts[$i] : 0, 2); ?></td>
+                    </tr>
+                <?php endfor; ?>
+            </tbody>
+        </table>
+    </div>
+    
+    <style>
+        /* 响应式布局:调整表格容器 */
+        .top-regions-table-container {
+            width: 100%;
+            overflow-x: auto;
+        }
+        
+        @media (min-width: 768px) {
+            .top-regions-table-container {
+                max-height: 33vh; /* 视窗高度的1/3 */
+                overflow-y: auto;
+            }
+        }
+    </style>
     <?php
 } 

+ 12 - 12
statistics_sales.php

@@ -24,7 +24,7 @@ function getSalesOverview($conn, $start_date, $end_date) {
                 SUM(oi.quantity) as total_items_sold
             FROM orders o
             LEFT JOIN order_items oi ON o.id = oi.order_id 
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             AND o.order_status != 0"; // 排除已取消订单
     
     $stmt = $conn->prepare($sql);
@@ -42,7 +42,7 @@ function getOrderConversionStats($conn, $start_date, $end_date) {
                 COUNT(*) as count,
                 SUM(total_amount) as amount
             FROM orders 
-            WHERE order_date BETWEEN ? AND ?
+            WHERE is_deleted = 0 AND order_date BETWEEN ? AND ?
             GROUP BY order_status";
     
     $stmt = $conn->prepare($sql);
@@ -64,7 +64,7 @@ function getProductCategorySales($conn, $start_date, $end_date) {
             JOIN order_items oi ON o.id = oi.order_id
             JOIN products p ON oi.product_id = p.id
             JOIN product_categories pc ON p.category_id = pc.id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             AND o.order_status != 0
             GROUP BY pc.id
             ORDER BY total_revenue DESC";
@@ -87,7 +87,7 @@ function getCustomerDistribution($conn, $start_date, $end_date) {
             FROM orders o
             JOIN customer cu ON o.customer_id = cu.id
             JOIN country c ON cu.cs_country = c.id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             AND o.order_status != 0
             GROUP BY c.id
             ORDER BY total_revenue DESC";
@@ -110,7 +110,7 @@ function getEmployeePerformance($conn, $start_date, $end_date) {
                 AVG(o.total_amount) as avg_order_value
             FROM orders o
             JOIN employee e ON o.employee_id = e.id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND o.order_date BETWEEN ? AND ?
             AND o.order_status != 0
             GROUP BY e.id
             ORDER BY total_revenue DESC";
@@ -130,7 +130,7 @@ function getPaymentStatusStats($conn, $start_date, $end_date) {
                 COUNT(*) as count,
                 SUM(total_amount) as amount
             FROM orders 
-            WHERE order_date BETWEEN ? AND ?
+            WHERE is_deleted = 0 AND order_date BETWEEN ? AND ?
             AND order_status != 0
             GROUP BY payment_status";
     
@@ -155,7 +155,7 @@ function getMonthlySalesTrend($conn, $start_date, $end_date) {
                 SUM(total_amount) as revenue,
                 COUNT(DISTINCT customer_id) as unique_customers
             FROM orders 
-            WHERE order_date BETWEEN ? AND ?
+            WHERE is_deleted = 0 AND order_date BETWEEN ? AND ?
             AND order_status != 0
             GROUP BY DATE_FORMAT(order_date, '%Y-%m')
             ORDER BY month";
@@ -192,7 +192,7 @@ function getDetailedOrderTrend($conn, $start_date, $end_date, $period = 'day') {
                 COUNT(DISTINCT o.customer_id) as unique_customers
             FROM orders o
             LEFT JOIN order_items oi ON o.id = oi.order_id
-            WHERE o.order_date BETWEEN ? AND ?
+            WHERE o.is_deleted = 0 AND (oi.is_deleted = 0 OR oi.is_deleted IS NULL) AND o.order_date BETWEEN ? AND ?
             AND o.order_status != 0
             GROUP BY time_period
             ORDER BY MIN(o.order_date)";
@@ -845,7 +845,7 @@ function getEmployeeStats($conn, $employee_id, $start_date, $end_date) {
                 AVG(o.total_amount) as avg_order_value,
                 SUM(CASE WHEN o.order_status = 5 THEN 1 ELSE 0 END) * 100.0 / COUNT(*) as completion_rate
             FROM orders o
-            WHERE o.employee_id = ?
+            WHERE o.is_deleted = 0 AND o.employee_id = ?
             AND o.order_date BETWEEN ? AND ?
             AND o.order_status != 0";
     
@@ -864,7 +864,7 @@ function renderEmployeeSalesTrend($conn, $employee_id, $start_date, $end_date) {
                 COUNT(DISTINCT id) as orders,
                 SUM(total_amount) as revenue
             FROM orders 
-            WHERE employee_id = ?
+            WHERE is_deleted = 0 AND employee_id = ?
             AND order_date BETWEEN ? AND ?
             AND order_status != 0
             GROUP BY DATE_FORMAT(order_date, '%Y-%m-%d')
@@ -959,7 +959,7 @@ function renderEmployeeCustomerDistribution($conn, $employee_id, $start_date, $e
             FROM orders o
             JOIN customer cu ON o.customer_id = cu.id
             JOIN country c ON cu.cs_country = c.id
-            WHERE o.employee_id = ?
+            WHERE o.is_deleted = 0 AND o.employee_id = ?
             AND o.order_date BETWEEN ? AND ?
             AND o.order_status != 0
             GROUP BY c.id
@@ -1055,7 +1055,7 @@ function renderEmployeeProductAnalysis($conn, $employee_id, $start_date, $end_da
             JOIN order_items oi ON o.id = oi.order_id
             JOIN products p ON oi.product_id = p.id
             JOIN product_categories pc ON p.category_id = pc.id
-            WHERE o.employee_id = ?
+            WHERE o.is_deleted = 0 AND oi.is_deleted = 0 AND o.employee_id = ?
             AND o.order_date BETWEEN ? AND ?
             AND o.order_status != 0
             GROUP BY pc.id

+ 145 - 202
statistics_utils.php

@@ -347,31 +347,9 @@ function renderNewCustomersByEmployeeChart($employee_data) {
         echo '<div class="alert alert-info">该时间段内没有业务员新增客户数据</div>';
         return;
     }
-    
-    // 准备图表数据
-    $employee_names = [];
-    $customer_counts = [];
-    
-    foreach ($employee_data as $row) {
-        $employee_names[] = $row['employee_name'];
-        $customer_counts[] = $row['customer_count'];
-    }
-    
-    // 生成图表背景色
-    $colors = generateChartColors(count($employee_data));
-    $backgroundColors = [];
-    $borderColors = [];
-    
-    foreach ($colors as $color) {
-        $backgroundColors[] = $color[0];
-        $borderColors[] = $color[1];
-    }
     ?>
     
-    <div class="analysis-grid">
-        <div>
-            <canvas id="employeeNewCustomersChart"></canvas>
-        </div>
+    <div class="auto-chart-grid">
         <div class="table-responsive">
             <table class="data-table">
                 <thead>
@@ -391,41 +369,6 @@ function renderNewCustomersByEmployeeChart($employee_data) {
             </table>
         </div>
     </div>
-    
-    <script>
-    var employeeNewCustomersCtx = document.getElementById('employeeNewCustomersChart').getContext('2d');
-    new Chart(employeeNewCustomersCtx, {
-        type: 'bar',
-        data: {
-            labels: <?php echo json_encode($employee_names); ?>,
-            datasets: [{
-                label: '新增客户数量',
-                data: <?php echo json_encode($customer_counts); ?>,
-                backgroundColor: <?php echo json_encode($backgroundColors); ?>,
-                borderColor: <?php echo json_encode($borderColors); ?>,
-                borderWidth: 1
-            }]
-        },
-        options: {
-            responsive: true,
-            scales: {
-                y: {
-                    beginAtZero: true,
-                    title: {
-                        display: true,
-                        text: '客户数量'
-                    }
-                }
-            },
-            plugins: {
-                title: {
-                    display: true,
-                    text: '业务员新增客户统计'
-                }
-            }
-        }
-    });
-    </script>
     <?php
 }
 
@@ -585,160 +528,160 @@ function renderNewCustomerProductPurchases($product_data) {
     
     <script>
     <?php
-    // 准备图表数据
-    $product_names = [];
-    $product_quantities = [];
-    $product_revenues = [];
-    
-    // 只取前10个产品用于图表显示
-    $top_products = array_slice($products, 0, 10);
-    
-    foreach ($top_products as $product) {
-        $product_names[] = $product['product_name'];
-        $product_quantities[] = $product['total_quantity'];
-        $product_revenues[] = $product['total_revenue'];
-    }
-    
-    // 生成图表背景色
-    $colors = generateChartColors(count($top_products));
-    $backgroundColors = [];
-    
-    foreach ($colors as $color) {
-        $backgroundColors[] = $color[0];
-    }
+//    // 准备图表数据
+//    $product_names = [];
+//    $product_quantities = [];
+//    $product_revenues = [];
+//
+//    // 只取前10个产品用于图表显示
+//    $top_products = array_slice($products, 0, 10);
+//
+//    foreach ($top_products as $product) {
+//        $product_names[] = $product['product_name'];
+//        $product_quantities[] = $product['total_quantity'];
+//        $product_revenues[] = $product['total_revenue'];
+//    }
+//
+//    // 生成图表背景色
+//    $colors = generateChartColors(count($top_products));
+//    $backgroundColors = [];
+//
+//    foreach ($colors as $color) {
+//        $backgroundColors[] = $color[0];
+//    }
     ?>
     
-    var newCustomerProductCtx = document.getElementById('newCustomerProductChart').getContext('2d');
-    new Chart(newCustomerProductCtx, {
-        type: 'bar',
-        data: {
-            labels: <?php echo json_encode($product_names); ?>,
-            datasets: [
-                {
-                    label: '销售数量',
-                    data: <?php echo json_encode($product_quantities); ?>,
-                    backgroundColor: 'rgba(54, 162, 235, 0.7)',
-                    borderColor: 'rgba(54, 162, 235, 1)',
-                    borderWidth: 1,
-                    yAxisID: 'y-quantity'
-                },
-                {
-                    label: '销售金额',
-                    data: <?php echo json_encode($product_revenues); ?>,
-                    backgroundColor: 'rgba(255, 99, 132, 0.7)',
-                    borderColor: 'rgba(255, 99, 132, 1)',
-                    borderWidth: 1,
-                    yAxisID: 'y-revenue',
-                    type: 'line',
-                    fill: false
-                }
-            ]
-        },
-        options: {
-            responsive: true,
-            scales: {
-                'y-quantity': {
-                    type: 'linear',
-                    position: 'left',
-                    title: {
-                        display: true,
-                        text: '销售数量'
-                    },
-                    beginAtZero: true
-                },
-                'y-revenue': {
-                    type: 'linear',
-                    position: 'right',
-                    title: {
-                        display: true,
-                        text: '销售金额'
-                    },
-                    beginAtZero: true,
-                    grid: {
-                        drawOnChartArea: false
-                    }
-                }
-            },
-            plugins: {
-                title: {
-                    display: true,
-                    text: '新客户热门购买产品 (Top 10)'
-                }
-            }
-        }
-    });
+    //var newCustomerProductCtx = document.getElementById('newCustomerProductChart').getContext('2d');
+    //new Chart(newCustomerProductCtx, {
+    //    type: 'bar',
+    //    data: {
+    //        labels: <?php //echo json_encode($product_names); ?>//,
+    //        datasets: [
+    //            {
+    //                label: '销售数量',
+    //                data: <?php //echo json_encode($product_quantities); ?>//,
+    //                backgroundColor: 'rgba(54, 162, 235, 0.7)',
+    //                borderColor: 'rgba(54, 162, 235, 1)',
+    //                borderWidth: 1,
+    //                yAxisID: 'y-quantity'
+    //            },
+    //            {
+    //                label: '销售金额',
+    //                data: <?php //echo json_encode($product_revenues); ?>//,
+    //                backgroundColor: 'rgba(255, 99, 132, 0.7)',
+    //                borderColor: 'rgba(255, 99, 132, 1)',
+    //                borderWidth: 1,
+    //                yAxisID: 'y-revenue',
+    //                type: 'line',
+    //                fill: false
+    //            }
+    //        ]
+    //    },
+    //    options: {
+    //        responsive: true,
+    //        scales: {
+    //            'y-quantity': {
+    //                type: 'linear',
+    //                position: 'left',
+    //                title: {
+    //                    display: true,
+    //                    text: '销售数量'
+    //                },
+    //                beginAtZero: true
+    //            },
+    //            'y-revenue': {
+    //                type: 'linear',
+    //                position: 'right',
+    //                title: {
+    //                    display: true,
+    //                    text: '销售金额'
+    //                },
+    //                beginAtZero: true,
+    //                grid: {
+    //                    drawOnChartArea: false
+    //                }
+    //            }
+    //        },
+    //        plugins: {
+    //            title: {
+    //                display: true,
+    //                text: '新客户热门购买产品 (Top 10)'
+    //            }
+    //        }
+    //    }
+    //});
     </script>
     
     <!-- 新客户产品类别分布图 -->
-    <div class="chart-container">
-        <div>
-            <canvas id="newCustomerCategoryChart"></canvas>
-        </div>
-    </div>
+<!--    <div class="chart-container">-->
+<!--        <div>-->
+<!--            <canvas id="newCustomerCategoryChart"></canvas>-->
+<!--        </div>-->
+<!--    </div>-->
     
     <script>
     <?php
-    // 按产品类别分组
-    $categories = [];
-    $category_data = [];
-    
-    foreach ($products as $product) {
-        $category = $product['category_name'] ?: '未分类';
-        if (!isset($category_data[$category])) {
-            $category_data[$category] = [
-                'quantity' => 0,
-                'revenue' => 0
-            ];
-        }
-        $category_data[$category]['quantity'] += $product['total_quantity'];
-        $category_data[$category]['revenue'] += $product['total_revenue'];
-    }
-    
-    $category_names = array_keys($category_data);
-    $category_quantities = array_column($category_data, 'quantity');
-    $category_revenues = array_column($category_data, 'revenue');
-    
-    // 计算占比
-    $total_revenue = array_sum($category_revenues);
-    $revenue_percentages = [];
-    
-    foreach ($category_revenues as $revenue) {
-        $revenue_percentages[] = round(($revenue / $total_revenue) * 100, 1);
-    }
-    
-    // 生成图表背景色
-    $category_colors = generateChartColors(count($category_data), false);
-    $category_bg_colors = array_column($category_colors, 0);
+//    // 按产品类别分组
+//    $categories = [];
+//    $category_data = [];
+//
+//    foreach ($products as $product) {
+//        $category = $product['category_name'] ?: '未分类';
+//        if (!isset($category_data[$category])) {
+//            $category_data[$category] = [
+//                'quantity' => 0,
+//                'revenue' => 0
+//            ];
+//        }
+//        $category_data[$category]['quantity'] += $product['total_quantity'];
+//        $category_data[$category]['revenue'] += $product['total_revenue'];
+//    }
+//
+//    $category_names = array_keys($category_data);
+//    $category_quantities = array_column($category_data, 'quantity');
+//    $category_revenues = array_column($category_data, 'revenue');
+//
+//    // 计算占比
+//    $total_revenue = array_sum($category_revenues);
+//    $revenue_percentages = [];
+//
+//    foreach ($category_revenues as $revenue) {
+//        $revenue_percentages[] = round(($revenue / $total_revenue) * 100, 1);
+//    }
+//
+//    // 生成图表背景色
+//    $category_colors = generateChartColors(count($category_data), false);
+//    $category_bg_colors = array_column($category_colors, 0);
     ?>
     
-    var newCustomerCategoryCtx = document.getElementById('newCustomerCategoryChart').getContext('2d');
-    new Chart(newCustomerCategoryCtx, {
-        type: 'pie',
-        data: {
-            labels: <?php echo json_encode($category_names); ?>,
-            datasets: [{
-                data: <?php echo json_encode($revenue_percentages); ?>,
-                backgroundColor: <?php echo json_encode($category_bg_colors); ?>,
-                borderWidth: 1
-            }]
-        },
-        options: {
-            responsive: true,
-            plugins: {
-                title: {
-                    display: true,
-                    text: '新客户产品类别销售占比'
-                },
-                tooltip: {
-                    callbacks: {
-                        label: function(context) {
-                            return context.label + ': ' + context.raw + '%';
-                        }
-                    }
-                }
-            }
-        }
-    });
+    //var newCustomerCategoryCtx = document.getElementById('newCustomerCategoryChart').getContext('2d');
+    //new Chart(newCustomerCategoryCtx, {
+    //    type: 'pie',
+    //    data: {
+    //        labels: <?php //echo json_encode($category_names); ?>//,
+    //        datasets: [{
+    //            data: <?php //echo json_encode($revenue_percentages); ?>//,
+    //            backgroundColor: <?php //echo json_encode($category_bg_colors); ?>//,
+    //            borderWidth: 1
+    //        }]
+    //    },
+    //    options: {
+    //        responsive: true,
+    //        plugins: {
+    //            title: {
+    //                display: true,
+    //                text: '新客户产品类别销售占比'
+    //            },
+    //            tooltip: {
+    //                callbacks: {
+    //                    label: function(context) {
+    //                        return context.label + ': ' + context.raw + '%';
+    //                    }
+    //                }
+    //            }
+    //        }
+    //    }
+    //});
     </script>
     <?php
 }