region_stats.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * 地区统计分析展示页面
  4. */
  5. require_once 'conn.php';
  6. require_once 'statistics_utils.php';
  7. require_once 'statistics_region.php';
  8. // 检查登录状态
  9. if (!isset($_SESSION['employee_id'])) {
  10. checkLogin();
  11. }
  12. // 获取日期范围参数
  13. $date_params = getDateRangeParams();
  14. $start_date = $date_params['start_date_sql'];
  15. $end_date = $date_params['end_date_sql'];
  16. $date_range = $date_params['date_range'];
  17. // 页面头部
  18. include('statistics_header.php');
  19. ?>
  20. <div class="container">
  21. <div class="page-header">
  22. <h1 class="page-title">地区统计分析</h1>
  23. </div>
  24. <!-- 日期筛选 -->
  25. <div class="filter-form">
  26. <form method="get" class="filter-form-inline">
  27. <div class="form-group">
  28. <label for="date_range">选择日期范围</label>
  29. <select class="form-control" id="date_range" name="date_range" onchange="toggleCustomDates()">
  30. <option value="current_month" <?php echo $date_range == 'current_month' ? 'selected' : ''; ?>>本月</option>
  31. <option value="last_month" <?php echo $date_range == 'last_month' ? 'selected' : ''; ?>>上月</option>
  32. <option value="current_year" <?php echo $date_range == 'current_year' ? 'selected' : ''; ?>>今年</option>
  33. <option value="last_30_days" <?php echo $date_range == 'last_30_days' ? 'selected' : ''; ?>>最近30天</option>
  34. <option value="last_90_days" <?php echo $date_range == 'last_90_days' ? 'selected' : ''; ?>>最近90天</option>
  35. <option value="custom" <?php echo $date_range == 'custom' ? 'selected' : ''; ?>>自定义日期范围</option>
  36. </select>
  37. </div>
  38. <div class="form-group custom-date-inputs" style="display: <?php echo $date_range == 'custom' ? 'inline-block' : 'none'; ?>">
  39. <label for="start_date">开始日期</label>
  40. <input type="date" class="form-control" id="start_date" name="start_date" value="<?php echo $date_params['custom_start']; ?>">
  41. </div>
  42. <div class="form-group custom-date-inputs" style="display: <?php echo $date_range == 'custom' ? 'inline-block' : 'none'; ?>">
  43. <label for="end_date">结束日期</label>
  44. <input type="date" class="form-control" id="end_date" name="end_date" value="<?php echo $date_params['custom_end']; ?>">
  45. </div>
  46. <div class="form-group">
  47. <button type="submit" class="btn">应用筛选</button>
  48. </div>
  49. </form>
  50. </div>
  51. <!-- 地区销售数据概览 -->
  52. <div class="stats-overview">
  53. <div class="row">
  54. <div class="col-md-4">
  55. <div class="stat-card">
  56. <h3>总销售额</h3>
  57. <?php
  58. $total_sales = getRegionTotalSales($conn, $start_date, $end_date);
  59. echo "<div class='stat-value'>¥" . number_format($total_sales['total_amount'], 2) . "</div>";
  60. echo "<div class='stat-trend " . ($total_sales['growth'] >= 0 ? 'positive' : 'negative') . "'>";
  61. echo ($total_sales['growth'] >= 0 ? '+' : '') . number_format($total_sales['growth'], 2) . "%</div>";
  62. ?>
  63. </div>
  64. </div>
  65. <div class="col-md-4">
  66. <div class="stat-card">
  67. <h3>活跃国家数</h3>
  68. <?php
  69. $active_countries = getActiveCountries($conn, $start_date, $end_date);
  70. echo "<div class='stat-value'>" . $active_countries['count'] . "</div>";
  71. ?>
  72. </div>
  73. </div>
  74. <div class="col-md-4">
  75. <div class="stat-card">
  76. <h3>平均订单金额</h3>
  77. <?php
  78. $avg_order = getAverageOrderByRegion($conn, $start_date, $end_date);
  79. echo "<div class='stat-value'>¥" . number_format($avg_order['global_avg'], 2) . "</div>";
  80. ?>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. <!-- 客户国家分布 -->
  86. <div class="chart-container">
  87. <?php
  88. $country_distribution = getCustomerCountryDistribution($conn);
  89. $country_labels = [];
  90. $country_data = [];
  91. while ($row = $country_distribution->fetch_assoc()) {
  92. $country_labels[] = $row['countryName'];
  93. $country_data[] = $row['customer_count'];
  94. }
  95. renderCustomerCountryDistributionChart($country_labels, $country_data);
  96. ?>
  97. </div>
  98. <!-- 地区订单分析 -->
  99. <div class="chart-container">
  100. <?php
  101. $region_orders = getOrdersByRegion($conn, $start_date, $end_date);
  102. $region_labels = [];
  103. $region_order_counts = [];
  104. $region_quantities = [];
  105. while ($row = $region_orders->fetch_assoc()) {
  106. $region_labels[] = $row['countryName'];
  107. $region_order_counts[] = $row['order_count'];
  108. $region_quantities[] = $row['total_quantity'];
  109. }
  110. renderRegionOrdersChart($region_labels, $region_order_counts, $region_quantities);
  111. ?>
  112. </div>
  113. <!-- 地区平均订单金额分析 -->
  114. <div class="chart-container">
  115. <?php
  116. $avg_order_data = getAverageOrderByRegion($conn, $start_date, $end_date);
  117. renderAverageOrderByRegionChart($avg_order_data['regions']);
  118. ?>
  119. </div>
  120. <!-- 各地区产品类别偏好 -->
  121. <div class="chart-container">
  122. <?php
  123. $category_preferences = getRegionCategoryPreferences($conn, $start_date, $end_date);
  124. renderRegionCategoryPreferencesChart($category_preferences);
  125. ?>
  126. </div>
  127. <!-- 地区销售增长趋势 -->
  128. <div class="chart-container">
  129. <?php
  130. $growth_trends = getRegionGrowthTrends($conn, $start_date, $end_date, $date_params['period']);
  131. renderRegionGrowthTrendsChart($growth_trends);
  132. ?>
  133. </div>
  134. <!-- 地区销售同比分析 -->
  135. <div class="chart-container">
  136. <?php
  137. $comparison_data = getRegionSalesComparison($conn, $start_date, $end_date);
  138. renderRegionSalesComparisonTable($comparison_data);
  139. ?>
  140. </div>
  141. <!-- 地区季节性分析 -->
  142. <div class="chart-container">
  143. <?php
  144. $seasonal_analysis = getRegionSeasonalAnalysis($conn);
  145. renderRegionSeasonalAnalysisChart($seasonal_analysis);
  146. ?>
  147. </div>
  148. <!-- 地区销售预测 -->
  149. <div class="chart-container">
  150. <?php
  151. $forecast_data = getRegionSalesForecast($conn, $start_date, $end_date);
  152. renderRegionSalesForecastChart($forecast_data);
  153. ?>
  154. </div>
  155. </div>
  156. <style>
  157. .positive {
  158. color: #28a745;
  159. font-weight: bold;
  160. }
  161. .negative {
  162. color: #dc3545;
  163. font-weight: bold;
  164. }
  165. .stat-card {
  166. background-color: #f8f9fa;
  167. border-radius: 8px;
  168. padding: 20px;
  169. margin-bottom: 20px;
  170. box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  171. }
  172. .stat-value {
  173. font-size: 24px;
  174. font-weight: bold;
  175. margin: 10px 0;
  176. }
  177. .stat-trend {
  178. font-size: 16px;
  179. }
  180. .chart-container {
  181. background-color: #fff;
  182. border-radius: 8px;
  183. padding: 20px;
  184. margin-bottom: 30px;
  185. box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  186. }
  187. .chart-title {
  188. margin-top: 0;
  189. margin-bottom: 20px;
  190. font-size: 18px;
  191. font-weight: bold;
  192. }
  193. .filter-form {
  194. background-color: #f8f9fa;
  195. border-radius: 8px;
  196. padding: 15px;
  197. margin-bottom: 30px;
  198. }
  199. .filter-form-inline {
  200. display: flex;
  201. flex-wrap: wrap;
  202. align-items: end;
  203. gap: 15px;
  204. }
  205. .form-group {
  206. margin-bottom: 10px;
  207. }
  208. </style>
  209. <script>
  210. function toggleCustomDates() {
  211. const dateRange = document.getElementById('date_range').value;
  212. const customDateInputs = document.querySelectorAll('.custom-date-inputs');
  213. if (dateRange === 'custom') {
  214. customDateInputs.forEach(el => el.style.display = 'inline-block');
  215. } else {
  216. customDateInputs.forEach(el => el.style.display = 'none');
  217. }
  218. }
  219. </script>
  220. <?php
  221. // 页面底部
  222. include('statistics_footer.php');
  223. ?>