File manager - Edit - /var/www/order.cmtc.ac.th/admin/statistics.php
Back
<?php session_start(); include('../config/db.php'); // ✅ ตรวจสอบสิทธิ์เข้าหน้า Admin if(!isset($_SESSION['admin'])) { header("Location: login.php"); exit; } // ✅ ดึงสถิติรวม $total_views = $conn->query("SELECT COUNT(*) AS total FROM product_views")->fetch_assoc()['total'] ?? 0; $total_orders = $conn->query(" SELECT SUM(i.qty) AS total FROM order_items i JOIN orders o ON o.id = i.order_id WHERE i.confirm_status = 'ยืนยัน' AND i.item_status = 'ปกติ' ")->fetch_assoc()['total'] ?? 0; // ✅ ดึงข้อมูลรายสินค้า $stats = $conn->query(" SELECT p.id, p.name, p.stock, p.price, COUNT(v.id) AS views, COALESCE(SUM(i.qty),0) AS ordered FROM products p LEFT JOIN product_views v ON v.product_id = p.id LEFT JOIN order_items i ON i.product_id = p.id AND i.confirm_status!='ยกเลิก' AND i.item_status='ปกติ' GROUP BY p.id ORDER BY views DESC "); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>สถิติระบบจองเหรียญ</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600&display=swap" rel="stylesheet"> <style> body { font-family:'Kanit', sans-serif; background-color:#f8f9fa; } .card { border-radius:16px; box-shadow:0 3px 10px rgba(0,0,0,0.1); } .table th { background-color:#44000E; color:#fff; } .progress { height:8px; border-radius:6px; } footer { background:#44000E; color:#fff; text-align:center; padding:15px; margin-top:50px; } </style> </head> <body> <?php include("menu.php"); ?> <div class="container py-5"> <h2 class="text-center mb-4 fw-bold text-primary">📊 รายงานสถิติการจองและเข้าชมสินค้า</h2> <!-- ✅ สรุปยอดรวม --> <div class="row mb-4"> <div class="col-md-6"> <div class="card p-3 text-center bg-light"> <h5 class="text-muted mb-1">จำนวนเข้าชมทั้งหมด</h5> <h2 class="fw-bold text-success"><?=number_format($total_views)?></h2> </div> </div> <div class="col-md-6"> <div class="card p-3 text-center bg-light"> <h5 class="text-muted mb-1">จำนวนจองสินค้าทั้งหมด</h5> <h2 class="fw-bold text-info"><?=number_format($total_orders)?></h2> </div> </div> </div> <!-- ✅ ตารางแสดงข้อมูลรายสินค้า --> <div class="card p-4"> <h5 class="mb-3 fw-bold">สถิติแยกรายสินค้า</h5> <div class="table-responsive"> <table class="table table-bordered align-middle text-center"> <thead> <tr> <th>ลำดับ</th> <th>ชื่อสินค้า</th> <th>คงเหลือ</th> <th>จองแล้ว</th> <th>เข้าชม</th> <th>เปอร์เซ็นต์การจอง</th> </tr> </thead> <tbody> <?php $i=1; while($row = $stats->fetch_assoc()): $total = $row['stock'] + $row['ordered']; $percent = ($total > 0) ? round(($row['ordered'] / $total) * 100) : 0; if ($percent <= 30) { $barColor = '#28a745'; } elseif ($percent <= 70) { $barColor = '#ffc107'; } else { $barColor = '#dc3545'; } ?> <tr> <td><?=$i++?></td> <td class="text-start"><?=$row['name']?></td> <td><?=$row['stock']?></td> <td><?=$row['ordered']?></td> <td><?=$row['views']?></td> <td style="min-width:150px;"> <div class="progress"> <div class="progress-bar" style="width: <?=$percent?>%; background-color: <?=$barColor?>;" title="<?=$percent?>%"> </div> </div> <small><?=$percent?>%</small> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.77 |
proxy
|
phpinfo
|
Settings