sales_stats.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. /**
  3. * 销售统计分析展示页面
  4. */
  5. require_once 'conn.php';
  6. require_once 'statistics_utils.php';
  7. require_once 'statistics_sales.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. $period = $date_params['period'];
  18. // 页面头部
  19. include('statistics_header.php');
  20. ?>
  21. <style>
  22. .container {
  23. max-width: 1200px;
  24. margin: 0 auto;
  25. padding: 20px;
  26. }
  27. .page-header {
  28. margin-bottom: 30px;
  29. }
  30. .page-title {
  31. font-size: 24px;
  32. color: #333;
  33. margin: 0;
  34. }
  35. .filter-form {
  36. background: #f5f5f5;
  37. padding: 20px;
  38. border-radius: 8px;
  39. margin-bottom: 30px;
  40. }
  41. .filter-form-inline {
  42. display: flex;
  43. flex-wrap: wrap;
  44. gap: 15px;
  45. align-items: flex-end;
  46. }
  47. .form-group {
  48. margin-bottom: 10px;
  49. }
  50. .form-group label {
  51. display: block;
  52. margin-bottom: 5px;
  53. color: #666;
  54. }
  55. .form-control {
  56. padding: 8px 12px;
  57. border: 1px solid #ddd;
  58. border-radius: 4px;
  59. font-size: 14px;
  60. }
  61. .btn {
  62. background: #4a90e2;
  63. color: white;
  64. padding: 8px 16px;
  65. border: none;
  66. border-radius: 4px;
  67. cursor: pointer;
  68. }
  69. .btn:hover {
  70. background: #357abd;
  71. }
  72. .chart-container {
  73. background: white;
  74. border-radius: 8px;
  75. box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  76. padding: 20px;
  77. margin-bottom: 30px;
  78. }
  79. .chart-header {
  80. margin-bottom: 20px;
  81. }
  82. .chart-title {
  83. font-size: 18px;
  84. color: #333;
  85. margin: 0;
  86. }
  87. .stats-grid {
  88. display: grid;
  89. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  90. gap: 20px;
  91. margin-bottom: 30px;
  92. }
  93. .stat-card {
  94. background: white;
  95. padding: 20px;
  96. border-radius: 8px;
  97. box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  98. text-align: center;
  99. }
  100. .stat-card h3 {
  101. font-size: 16px;
  102. color: #666;
  103. margin: 0 0 10px 0;
  104. }
  105. .stat-value {
  106. font-size: 24px;
  107. color: #4a90e2;
  108. font-weight: bold;
  109. }
  110. .analysis-grid {
  111. display: grid;
  112. grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  113. gap: 20px;
  114. margin-bottom: 30px;
  115. }
  116. .table-responsive {
  117. overflow-x: auto;
  118. }
  119. .data-table {
  120. width: 100%;
  121. border-collapse: collapse;
  122. }
  123. .data-table th,
  124. .data-table td {
  125. padding: 12px;
  126. text-align: left;
  127. border-bottom: 1px solid #ddd;
  128. }
  129. .data-table th {
  130. background: #f5f5f5;
  131. font-weight: bold;
  132. }
  133. .data-table tr:hover {
  134. background: #f9f9f9;
  135. }
  136. </style>
  137. <div class="container">
  138. <div class="page-header">
  139. <h1 class="page-title">销售统计分析</h1>
  140. </div>
  141. <!-- 日期筛选 -->
  142. <div class="filter-form">
  143. <form method="get" class="filter-form-inline">
  144. <div class="form-group">
  145. <label for="date_range">选择日期范围</label>
  146. <select class="form-control" id="date_range" name="date_range" onchange="toggleCustomDates()">
  147. <option value="current_month" <?php echo $date_range == 'current_month' ? 'selected' : ''; ?>>本月</option>
  148. <option value="last_month" <?php echo $date_range == 'last_month' ? 'selected' : ''; ?>>上月</option>
  149. <option value="current_year" <?php echo $date_range == 'current_year' ? 'selected' : ''; ?>>今年</option>
  150. <option value="last_30_days" <?php echo $date_range == 'last_30_days' ? 'selected' : ''; ?>>最近30天</option>
  151. <option value="last_90_days" <?php echo $date_range == 'last_90_days' ? 'selected' : ''; ?>>最近90天</option>
  152. <option value="custom" <?php echo $date_range == 'custom' ? 'selected' : ''; ?>>自定义日期范围</option>
  153. </select>
  154. </div>
  155. <div class="form-group custom-date-inputs" style="display: <?php echo $date_range == 'custom' ? 'inline-block' : 'none'; ?>">
  156. <label for="start_date">开始日期</label>
  157. <input type="date" class="form-control" id="start_date" name="start_date" value="<?php echo $date_params['custom_start']; ?>">
  158. </div>
  159. <div class="form-group custom-date-inputs" style="display: <?php echo $date_range == 'custom' ? 'inline-block' : 'none'; ?>">
  160. <label for="end_date">结束日期</label>
  161. <input type="date" class="form-control" id="end_date" name="end_date" value="<?php echo $date_params['custom_end']; ?>">
  162. </div>
  163. <div class="form-group">
  164. <label for="period">时间粒度</label>
  165. <select class="form-control" id="period" name="period">
  166. <option value="day" <?php echo $period == 'day' ? 'selected' : ''; ?>>日</option>
  167. <option value="week" <?php echo $period == 'week' ? 'selected' : ''; ?>>周</option>
  168. <option value="month" <?php echo $period == 'month' ? 'selected' : ''; ?>>月</option>
  169. </select>
  170. </div>
  171. <div class="form-group">
  172. <button type="submit" class="btn">应用筛选</button>
  173. </div>
  174. </form>
  175. </div>
  176. <!-- 销售概览 -->
  177. <div class="chart-container">
  178. <div class="chart-header">
  179. <h2 class="chart-title">销售概览</h2>
  180. </div>
  181. <div class="card-body">
  182. <?php
  183. $sales_overview = getSalesOverview($conn, $start_date, $end_date);
  184. renderSalesOverviewCards($sales_overview);
  185. ?>
  186. </div>
  187. </div>
  188. <!-- 销售转化率分析 -->
  189. <div class="chart-container">
  190. <div class="chart-header">
  191. <h2 class="chart-title">销售转化率分析</h2>
  192. </div>
  193. <?php
  194. $conversion_stats = getOrderConversionStats($conn, $start_date, $end_date);
  195. renderConversionAnalysis($conversion_stats);
  196. ?>
  197. </div>
  198. <!-- 产品类别销售分析 -->
  199. <div class="chart-container">
  200. <div class="chart-header">
  201. <h2 class="chart-title">产品类别销售分析</h2>
  202. </div>
  203. <?php
  204. $category_sales = getProductCategorySales($conn, $start_date, $end_date);
  205. renderCategorySalesChart($category_sales);
  206. ?>
  207. </div>
  208. <!-- 客户地区分布 -->
  209. <div class="chart-container">
  210. <div class="chart-header">
  211. <h2 class="chart-title">客户地区分布</h2>
  212. </div>
  213. <?php
  214. $customer_distribution = getCustomerDistribution($conn, $start_date, $end_date);
  215. renderCustomerDistributionChart($customer_distribution);
  216. ?>
  217. </div>
  218. <!-- 销售员业绩排行 -->
  219. <div class="chart-container">
  220. <div class="chart-header">
  221. <h2 class="chart-title">销售员业绩排行</h2>
  222. </div>
  223. <?php
  224. $employee_performance = getEmployeePerformance($conn, $start_date, $end_date);
  225. renderEmployeePerformanceTable($employee_performance);
  226. ?>
  227. </div>
  228. <!-- 月度销售趋势 -->
  229. <div class="chart-container">
  230. <?php
  231. $monthly_sales = getMonthlySalesTrend($conn, $start_date, $end_date);
  232. $monthly_labels = [];
  233. $monthly_orders = [];
  234. $monthly_revenue = [];
  235. while ($row = $monthly_sales->fetch_assoc()) {
  236. $monthly_labels[] = $row['month'];
  237. $monthly_orders[] = $row['orders'];
  238. $monthly_revenue[] = $row['revenue'];
  239. }
  240. renderMonthlySalesTrendChart($monthly_labels, $monthly_orders, $monthly_revenue);
  241. ?>
  242. </div>
  243. <!-- 支付状态分析 -->
  244. <div class="chart-container">
  245. <div class="chart-header">
  246. <h2 class="chart-title">支付状态分析</h2>
  247. </div>
  248. <?php
  249. $payment_stats = getPaymentStatusStats($conn, $start_date, $end_date);
  250. renderPaymentStatusChart($payment_stats);
  251. ?>
  252. </div>
  253. <!-- 详细订单趋势 -->
  254. <div class="chart-container">
  255. <?php
  256. $detailed_trends = getDetailedOrderTrend($conn, $start_date, $end_date, $period);
  257. $time_labels = [];
  258. $time_orders = [];
  259. $time_quantities = [];
  260. while ($row = $detailed_trends->fetch_assoc()) {
  261. $time_labels[] = $row['time_period'];
  262. $time_orders[] = $row['order_count'];
  263. $time_quantities[] = $row['total_quantity'];
  264. }
  265. renderDetailedOrderTrendChart($time_labels, $time_orders, $time_quantities, $period);
  266. ?>
  267. </div>
  268. </div>
  269. <script>
  270. function toggleCustomDates() {
  271. const dateRange = document.getElementById('date_range').value;
  272. const customDateInputs = document.querySelectorAll('.custom-date-inputs');
  273. customDateInputs.forEach(el => {
  274. el.style.display = dateRange === 'custom' ? 'inline-block' : 'none';
  275. });
  276. }
  277. </script>
  278. <?php
  279. include('statistics_footer.php');
  280. ?>