İçeriğe geç
Tüm kodlar

ER3NSHOP

Kurulum sihirbazlı online mağaza sistemi

65 satır · 3 KBHamİndir
<?php
$q = get('q', '');
$where = '1 = 1';
$params = [];
if ($q !== '') {
    $where .= ' AND (c.name LIKE ? OR c.email LIKE ? OR c.phone LIKE ?)';
    array_push($params, "%$q%", "%$q%", "%$q%");
}

$total = db_value("SELECT COUNT(*) FROM customers c WHERE $where", $params);
$pager = paginate($total, ADMIN_PER_PAGE, get_int('sayfa', 1));
$customers = db_all(
    "SELECT c.*, COUNT(o.id) AS order_count, COALESCE(SUM(CASE WHEN o.status != 'iptal' THEN o.total END), 0) AS spent
     FROM customers c LEFT JOIN orders o ON o.customer_id = c.id
     WHERE $where GROUP BY c.id ORDER BY c.id DESC LIMIT {$pager['limit']} OFFSET {$pager['offset']}",
    $params
);

admin_header('Müşteriler');
?>

<form class="flex gap-2">
    <input name="q" value="<?= e($q) ?>" placeholder="Ad, e-posta, telefon" class="input w-72 py-2">
    <button class="btn-light btn-sm"><?= icon('search', 'size-4') ?></button>
</form>

<div class="card mt-6 overflow-x-auto">
    <table class="w-full min-w-[700px] text-left text-sm">
        <thead class="border-b border-zinc-200 text-xs text-zinc-500">
            <tr>
                <th class="px-5 py-3 font-medium">Müşteri</th>
                <th class="px-5 py-3 font-medium">Telefon</th>
                <th class="px-5 py-3 font-medium">Kayıt</th>
                <th class="px-5 py-3 text-right font-medium">Sipariş</th>
                <th class="px-5 py-3 text-right font-medium">Harcama</th>
            </tr>
        </thead>
        <tbody class="divide-y divide-zinc-100">
            <?php foreach ($customers as $customer): ?>
                <tr class="cursor-pointer hover:bg-zinc-50" onclick="location.href='<?= admin_url('musteri?id=' . $customer['id']) ?>'">
                    <td class="px-5 py-3.5">
                        <div class="flex items-center gap-3">
                            <span class="flex size-9 items-center justify-center rounded-full bg-zinc-100 text-xs font-semibold text-zinc-600"><?= e(mb_strtoupper(mb_substr($customer['name'], 0, 1))) ?></span>
                            <div>
                                <p class="font-medium"><?= e($customer['name']) ?></p>
                                <p class="text-xs text-zinc-500"><?= e($customer['email']) ?></p>
                            </div>
                        </div>
                    </td>
                    <td class="px-5 py-3.5 text-zinc-600"><?= e($customer['phone'] ?: '—') ?></td>
                    <td class="px-5 py-3.5 text-zinc-600"><?= date_tr($customer['created_at']) ?></td>
                    <td class="px-5 py-3.5 text-right"><?= (int) $customer['order_count'] ?></td>
                    <td class="px-5 py-3.5 text-right font-semibold"><?= money($customer['spent']) ?></td>
                </tr>
            <?php endforeach ?>
            <?php if (!$customers): ?>
                <tr><td colspan="5" class="px-5 py-16 text-center text-zinc-500">Müşteri bulunamadı.</td></tr>
            <?php endif ?>
        </tbody>
    </table>
</div>

<?php pagination($pager) ?>

<?php admin_footer() ?>

Lisans bilgisi projenin LICENSE dosyasında.