File manager - Edit - /home/webapp69.cm.in.th/u69319090034/Shop 034/seller_dashboard.php
Back
<?php // หน้าหลักสำหรับ ผู้ขายสินค้า (seller_dashboard.php) require_once 'auth.php'; // ตรวจสอบว่าเป็น Seller หรือ Admin หรือไม่ requireSellerLogin(); $user = getCurrentUser(); $sellerId = $user['id'] ?? 0; $isAdmin = isAdminLoggedIn(); // ดึงสถิติต่างๆ สำหรับ Dashboard ผู้ขาย (แยกตามร้านค้า) try { if ($isAdmin) { $totalProducts = $conn->query("SELECT COUNT(*) FROM products")->fetchColumn(); $totalOrders = $conn->query("SELECT COUNT(*) FROM orders")->fetchColumn(); $totalSales = $conn->query("SELECT SUM(total_amount) FROM orders WHERE status != 'cancelled'")->fetchColumn() ?: 0; $latestOrders = $conn->query("SELECT * FROM orders ORDER BY created_at DESC LIMIT 5")->fetchAll(); } else { // นับสินค้าเฉพาะของร้านผู้ขายคนนี้ $stmtProdCount = $conn->prepare("SELECT COUNT(*) FROM products WHERE seller_id = :seller_id"); $stmtProdCount->execute([':seller_id' => $sellerId]); $totalProducts = $stmtProdCount->fetchColumn(); // นับออเดอร์เฉพาะที่มีสินค้าของร้านนี้ $stmtOrdersCount = $conn->prepare(" SELECT COUNT(DISTINCT o.id) FROM orders o JOIN order_items oi ON o.id = oi.order_id JOIN product_variants pv ON oi.product_variant_id = pv.id JOIN products p ON pv.product_id = p.id WHERE p.seller_id = :seller_id "); $stmtOrdersCount->execute([':seller_id' => $sellerId]); $totalOrders = $stmtOrdersCount->fetchColumn(); // รวมยอดขายเฉพาะสินค้าของร้านนี้ $stmtSalesSum = $conn->prepare(" SELECT SUM(oi.price * oi.quantity) FROM order_items oi JOIN orders o ON oi.order_id = o.id JOIN product_variants pv ON oi.product_variant_id = pv.id JOIN products p ON pv.product_id = p.id WHERE p.seller_id = :seller_id AND o.status != 'cancelled' "); $stmtSalesSum->execute([':seller_id' => $sellerId]); $totalSales = $stmtSalesSum->fetchColumn() ?: 0; // รายการออเดอร์ล่าสุดเฉพาะของร้านนี้ $stmtLatestOrders = $conn->prepare(" SELECT DISTINCT o.* FROM orders o JOIN order_items oi ON o.id = oi.order_id JOIN product_variants pv ON oi.product_variant_id = pv.id JOIN products p ON pv.product_id = p.id WHERE p.seller_id = :seller_id ORDER BY o.created_at DESC LIMIT 5 "); $stmtLatestOrders->execute([':seller_id' => $sellerId]); $latestOrders = $stmtLatestOrders->fetchAll(); } } catch (PDOException $e) { $totalProducts = 0; $totalOrders = 0; $totalSales = 0; $latestOrders = []; } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ระบบหลังบ้านผู้ขาย - AMARA STUDIO</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Sarabun:wght@300;400;500;600;700&display=swap"> <style> *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } :root { --primary: #c5a880; --primary-hover: #b0936b; --dark: #121214; --sidebar-bg: #1a1a24; --card-bg: #ffffff; --text: #2d3748; --font-eng: 'Outfit', sans-serif; --font-th: 'Sarabun', sans-serif; } body { font-family: var(--font-th), var(--font-eng); background: #f4f6f9; color: var(--text); display: flex; min-height: 100vh; } /* Sidebar Nav */ .sidebar { width: 260px; background: var(--sidebar-bg); color: white; padding: 30px 20px; display: flex; flex-direction: column; } .sidebar-logo { font-family: var(--font-eng); font-size: 22px; font-weight: 800; color: white; text-decoration: none; letter-spacing: 2px; margin-bottom: 40px; display: block; } .sidebar-logo span { color: var(--primary); } .nav-list { list-style: none; } .nav-item { margin-bottom: 8px; } .nav-link { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: rgba(255, 255, 255, 0.7); text-decoration: none; border-radius: 10px; font-weight: 500; transition: all 0.2s; } .nav-link:hover, .nav-link.active { background: rgba(197, 168, 128, 0.15); color: var(--primary); } /* Main Content */ .main-content { flex: 1; padding: 35px 40px; overflow-y: auto; } .top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; } .page-title { font-size: 24px; font-weight: 700; } .seller-badge { background: rgba(197, 168, 128, 0.2); color: #8c6e43; padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 600; } /* Stats Grid */ .stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 35px; } .stat-card { background: white; padding: 24px; border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.03); display: flex; align-items: center; justify-content: space-between; } .stat-val { font-size: 28px; font-weight: 800; color: var(--dark); margin-top: 4px; } .stat-lbl { font-size: 13px; color: #718096; font-weight: 600; } .stat-icon { font-size: 32px; background: #f7fafc; width: 60px; height: 60px; border-radius: 14px; display: flex; align-items: center; justify-content: center; } /* Table Area */ .table-card { background: white; border-radius: 16px; padding: 25px; box-shadow: 0 4px 12px rgba(0,0,0,0.03); } .table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } table { width: 100%; border-collapse: collapse; } th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid #edf2f7; font-size: 14px; } th { color: #718096; font-weight: 600; font-size: 13px; text-transform: uppercase; } .badge-status { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; } .badge-pending { background: #feebc8; color: #744210; } .badge-processing { background: #ebf8ff; color: #2b6cb0; } .badge-shipped { background: #c6f6d5; color: #22543d; } .btn-action { display: inline-block; padding: 8px 16px; background: var(--dark); color: white; text-decoration: none; border-radius: 8px; font-size: 13px; font-weight: 600; transition: background 0.2s; } .btn-action:hover { background: var(--primary); } </style> </head> <body> <aside class="sidebar"> <a href="index.php" class="sidebar-logo">AMARA<span>STUDIO</span></a> <ul class="nav-list"> <li class="nav-item"><a href="seller_dashboard.php" class="nav-link active">📊 ภาพรวมผู้ขาย</a></li> <li class="nav-item"><a href="admin_product.php" class="nav-link">📦 จัดการสินค้า</a></li> <li class="nav-item"><a href="admin_orders.php" class="nav-link">📋 รายการสั่งซื้อ</a></li> <li class="nav-item"><a href="manual.php" class="nav-link" target="_blank">📖 คู่มือการใช้งาน</a></li> <li class="nav-item"><a href="index.php" class="nav-link">🌐 หน้าร้านค้า</a></li> </ul> <div style="margin-top: auto; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.1);"> <p style="font-size: 13px; color: rgba(255,255,255,0.5);">ผู้ขาย:</p> <p style="font-weight: 600; font-size: 14px; color: white; margin-bottom: 12px;"><?= htmlspecialchars($user['fullname'] ?? $user['username']) ?></p> <a href="logout.php" style="color: #fc8181; text-decoration: none; font-size: 13px; font-weight: 600;">🚪 ออกจากระบบ</a> </div> </aside> <main class="main-content"> <div class="top-bar"> <div> <h1 class="page-title">แดชบอร์ดผู้ขาย (Seller Dashboard)</h1> <p style="color: #718096; font-size: 14px;">ยินดีต้อนรับคุณ <?= htmlspecialchars($user['fullname']) ?></p> </div> <div> <a href="admin_product.php" class="btn-action">+ เพิ่มสินค้าใหม่</a> </div> </div> <div class="stats-grid"> <div class="stat-card"> <div> <div class="stat-lbl">ยอดขายรวม</div> <div class="stat-val">฿<?= number_format($totalSales, 2) ?></div> </div> <div class="stat-icon">💰</div> </div> <div class="stat-card"> <div> <div class="stat-lbl">จำนวนคำสั่งซื้อ</div> <div class="stat-val"><?= number_format($totalOrders) ?></div> </div> <div class="stat-icon">📦</div> </div> <div class="stat-card"> <div> <div class="stat-lbl">รายการสินค้าในร้าน</div> <div class="stat-val"><?= number_format($totalProducts) ?></div> </div> <div class="stat-icon">👗</div> </div> </div> <div class="table-card"> <div class="table-header"> <h2 style="font-size: 18px; font-weight: 700;">คำสั่งซื้อล่าสุด</h2> <a href="admin_orders.php" style="color: var(--primary); text-decoration: none; font-size: 14px; font-weight: 600;">ดูทั้งหมด →</a> </div> <table> <thead> <tr> <th>รหัสสั่งซื้อ</th> <th>ชื่อลูกค้า</th> <th>ยอดรวม</th> <th>สถานะ</th> <th>วันที่สั่งซื้อ</th> </tr> </thead> <tbody> <?php if (empty($latestOrders)): ?> <tr><td colspan="5" style="text-align: center; color: #a0aec0;">ยังไม่มีรายการสั่งซื้อ</td></tr> <?php else: ?> <?php foreach ($latestOrders as $ord): ?> <tr> <td>#ORD-<?= str_pad($ord['id'], 5, '0', STR_PAD_LEFT) ?></td> <td><?= htmlspecialchars($ord['customer_name']) ?></td> <td><strong>฿<?= number_format($ord['total_amount'], 2) ?></strong></td> <td> <span class="badge-status badge-<?= $ord['status'] ?>"> <?= $ord['status'] ?> </span> </td> <td><?= date('d/m/Y H:i', strtotime($ord['created_at'])) ?></td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </main> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings