123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- /**
- * 地区统计分析展示页面
- */
- require_once 'conn.php';
- require_once 'statistics_utils.php';
- require_once 'statistics_region.php';
- // 检查登录状态
- if (!isset($_SESSION['employee_id'])) {
- checkLogin();
- }
- // 获取日期范围参数
- $date_params = getDateRangeParams();
- $start_date = $date_params['start_date_sql'];
- $end_date = $date_params['end_date_sql'];
- $date_range = $date_params['date_range'];
- // 页面头部
- include('statistics_header.php');
- ?>
- <div class="container">
- <div class="page-header">
- <h1 class="page-title">地区统计分析</h1>
- </div>
-
- <!-- 日期筛选 -->
- <div class="filter-form">
- <form method="get" class="filter-form-inline">
- <div class="form-group">
- <label for="date_range">选择日期范围</label>
- <select class="form-control" id="date_range" name="date_range" onchange="toggleCustomDates()">
- <option value="current_month" <?php echo $date_range == 'current_month' ? 'selected' : ''; ?>>本月</option>
- <option value="last_month" <?php echo $date_range == 'last_month' ? 'selected' : ''; ?>>上月</option>
- <option value="current_year" <?php echo $date_range == 'current_year' ? 'selected' : ''; ?>>今年</option>
- <option value="last_30_days" <?php echo $date_range == 'last_30_days' ? 'selected' : ''; ?>>最近30天</option>
- <option value="last_90_days" <?php echo $date_range == 'last_90_days' ? 'selected' : ''; ?>>最近90天</option>
- <option value="custom" <?php echo $date_range == 'custom' ? 'selected' : ''; ?>>自定义日期范围</option>
- </select>
- </div>
- <div class="form-group custom-date-inputs" style="display: <?php echo $date_range == 'custom' ? 'inline-block' : 'none'; ?>">
- <label for="start_date">开始日期</label>
- <input type="date" class="form-control" id="start_date" name="start_date" value="<?php echo $date_params['custom_start']; ?>">
- </div>
- <div class="form-group custom-date-inputs" style="display: <?php echo $date_range == 'custom' ? 'inline-block' : 'none'; ?>">
- <label for="end_date">结束日期</label>
- <input type="date" class="form-control" id="end_date" name="end_date" value="<?php echo $date_params['custom_end']; ?>">
- </div>
- <div class="form-group">
- <button type="submit" class="btn">应用筛选</button>
- </div>
- </form>
- </div>
-
- <!-- 地区销售数据概览 -->
- <div class="stats-overview">
- <div class="row">
- <div class="col-md-4">
- <div class="stat-card">
- <h3>总销售额</h3>
- <?php
- $total_sales = getRegionTotalSales($conn, $start_date, $end_date);
- 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>";
- ?>
- </div>
- </div>
- <div class="col-md-4">
- <div class="stat-card">
- <h3>活跃国家数</h3>
- <?php
- $active_countries = getActiveCountries($conn, $start_date, $end_date);
- echo "<div class='stat-value'>" . $active_countries['count'] . "</div>";
- ?>
- </div>
- </div>
- <div class="col-md-4">
- <div class="stat-card">
- <h3>平均订单金额</h3>
- <?php
- $avg_order = getAverageOrderByRegion($conn, $start_date, $end_date);
- echo "<div class='stat-value'>¥" . number_format($avg_order['global_avg'], 2) . "</div>";
- ?>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 客户国家分布 -->
- <div class="chart-container">
- <?php
- $country_distribution = getCustomerCountryDistribution($conn);
- $country_labels = [];
- $country_data = [];
-
- while ($row = $country_distribution->fetch_assoc()) {
- $country_labels[] = $row['countryName'];
- $country_data[] = $row['customer_count'];
- }
- renderCustomerCountryDistributionChart($country_labels, $country_data);
- ?>
- </div>
-
- <!-- 地区订单分析 -->
- <div class="chart-container">
- <?php
- $region_orders = getOrdersByRegion($conn, $start_date, $end_date);
- $region_labels = [];
- $region_order_counts = [];
- $region_quantities = [];
-
- while ($row = $region_orders->fetch_assoc()) {
- $region_labels[] = $row['countryName'];
- $region_order_counts[] = $row['order_count'];
- $region_quantities[] = $row['total_quantity'];
- }
- renderRegionOrdersChart($region_labels, $region_order_counts, $region_quantities);
- ?>
- </div>
-
- <!-- 地区平均订单金额分析 -->
- <div class="chart-container">
- <?php
- $avg_order_data = getAverageOrderByRegion($conn, $start_date, $end_date);
- renderAverageOrderByRegionChart($avg_order_data['regions']);
- ?>
- </div>
-
- <!-- 各地区产品类别偏好 -->
- <div class="chart-container">
- <?php
- $category_preferences = getRegionCategoryPreferences($conn, $start_date, $end_date);
- renderRegionCategoryPreferencesChart($category_preferences);
- ?>
- </div>
-
- <!-- 地区销售增长趋势 -->
- <div class="chart-container">
- <?php
- $growth_trends = getRegionGrowthTrends($conn, $start_date, $end_date, $date_params['period']);
- renderRegionGrowthTrendsChart($growth_trends);
- ?>
- </div>
-
- <!-- 地区销售同比分析 -->
- <div class="chart-container">
- <?php
- $comparison_data = getRegionSalesComparison($conn, $start_date, $end_date);
- renderRegionSalesComparisonTable($comparison_data);
- ?>
- </div>
-
- <!-- 地区季节性分析 -->
- <div class="chart-container">
- <?php
- $seasonal_analysis = getRegionSeasonalAnalysis($conn);
- renderRegionSeasonalAnalysisChart($seasonal_analysis);
- ?>
- </div>
-
- <!-- 地区销售预测 -->
- <div class="chart-container">
- <?php
- $forecast_data = getRegionSalesForecast($conn, $start_date, $end_date);
- renderRegionSalesForecastChart($forecast_data);
- ?>
- </div>
- </div>
- <style>
- .positive {
- color: #28a745;
- font-weight: bold;
- }
- .negative {
- color: #dc3545;
- font-weight: bold;
- }
- .stat-card {
- background-color: #f8f9fa;
- border-radius: 8px;
- padding: 20px;
- margin-bottom: 20px;
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
- }
- .stat-value {
- font-size: 24px;
- font-weight: bold;
- margin: 10px 0;
- }
- .stat-trend {
- font-size: 16px;
- }
- .chart-container {
- background-color: #fff;
- border-radius: 8px;
- padding: 20px;
- margin-bottom: 30px;
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
- }
- .chart-title {
- margin-top: 0;
- margin-bottom: 20px;
- font-size: 18px;
- font-weight: bold;
- }
- .filter-form {
- background-color: #f8f9fa;
- border-radius: 8px;
- padding: 15px;
- margin-bottom: 30px;
- }
- .filter-form-inline {
- display: flex;
- flex-wrap: wrap;
- align-items: end;
- gap: 15px;
- }
- .form-group {
- margin-bottom: 10px;
- }
- </style>
- <script>
- function toggleCustomDates() {
- const dateRange = document.getElementById('date_range').value;
- const customDateInputs = document.querySelectorAll('.custom-date-inputs');
-
- if (dateRange === 'custom') {
- customDateInputs.forEach(el => el.style.display = 'inline-block');
- } else {
- customDateInputs.forEach(el => el.style.display = 'none');
- }
- }
- </script>
- <?php
- // 页面底部
- include('statistics_footer.php');
- ?>
|