İçeriğe geç
Tüm kodlar

ER3NSHOP

Kurulum sihirbazlı online mağaza sistemi

150 satır · 8,7 KBHamİndir
<?php
$order = db_find('orders', get_int('id'));
if (!$order) {
    flash('Sipariş bulunamadı.', 'error');
    go(admin_url('siparisler'));
}

if (is_post()) {
    csrf_check();

    // Ödeme durumunu elle değiştirme (havale geldi, iade yapıldı...)
    if (post('action') === 'payment' && isset(payment_statuses()[post('payment_status')])) {
        db_update('orders', ['payment_status' => post('payment_status')], $order['id']);
        order_log($order['id'], $order['status'], 'Ödeme durumu: ' . payment_statuses()[post('payment_status')][0]);
        log_action('Ödeme durumunu değiştirdi', '#' . $order['order_no'] . ' · ' . payment_statuses()[post('payment_status')][0]);
        finish('Ödeme durumu güncellendi.', admin_url('siparis?id=' . $order['id']));
    }

    $status = post('status', $order['status']);
    $note = mb_substr(post('note', ''), 0, 255);
    if ($status !== $order['status'] || $note !== '') {
        order_set_status($order, $status, $note);
        flash('Sipariş güncellendi.');
    }
    go(admin_url('siparis?id=' . $order['id']));
}

$items = order_items($order['id']);
$history = order_history($order['id']);
$customer = $order['customer_id'] ? db_find('customers', $order['customer_id']) : null;
$order_count = $customer ? db_value('SELECT COUNT(*) FROM orders WHERE customer_id = ?', [$customer['id']]) : 0;

admin_header('Sipariş #' . $order['order_no'], order_status_badge($order['status']) . '<a href="' . admin_url('siparisler') . '" class="btn-light btn-sm">' . icon('left', 'size-4', '2') . 'Siparişler</a>');
?>

<div class="grid gap-6 xl:grid-cols-3">
    <div class="space-y-6 xl:col-span-2">
        <div class="card overflow-hidden">
            <div class="flex items-center justify-between border-b border-zinc-100 px-5 py-4">
                <h2 class="font-semibold">Ürünler</h2>
                <span class="text-sm text-zinc-500"><?= date_tr($order['created_at'], true) ?></span>
            </div>
            <ul class="divide-y divide-zinc-100">
                <?php foreach ($items as $item): ?>
                    <li class="flex items-center gap-4 px-5 py-4">
                        <span class="size-14 shrink-0 overflow-hidden rounded-lg bg-zinc-100"><?= image_tag($item['image'], $item['name'], 'h-full w-full object-cover', 'text-lg') ?></span>
                        <div class="min-w-0 flex-1">
                            <?php if ($item['product_id']): ?>
                                <a href="<?= admin_url('urun?id=' . $item['product_id']) ?>" class="font-medium hover:underline"><?= e($item['name']) ?></a>
                            <?php else: ?>
                                <p class="font-medium"><?= e($item['name']) ?></p>
                            <?php endif ?>
                            <p class="text-sm text-zinc-500"><?= $item['variant'] ? e($item['variant']) . ' · ' : '' ?><?= $item['qty'] ?> × <?= money($item['price']) ?></p>
                        </div>
                        <p class="font-semibold"><?= money($item['total']) ?></p>
                    </li>
                <?php endforeach ?>
            </ul>
            <div class="border-t border-zinc-100 bg-zinc-50/60 px-5 py-4">
                <?php include PARTS . '/order-totals.php' ?>
            </div>
        </div>

        <div class="card p-5">
            <h2 class="font-semibold">Sipariş geçmişi</h2>
            <ol class="mt-5 space-y-5 border-l border-zinc-200 pl-5">
                <?php foreach ($history as $row): ?>
                    <li class="relative">
                        <span class="absolute top-1 -left-[25px] size-2.5 rounded-full bg-ink ring-4 ring-white"></span>
                        <div class="flex flex-wrap items-center gap-2"><?= order_status_badge($row['status']) ?><span class="text-xs text-zinc-400"><?= date_tr($row['created_at'], true) ?></span></div>
                        <?php if ($row['note']): ?><p class="mt-1.5 text-sm text-zinc-600"><?= e($row['note']) ?></p><?php endif ?>
                    </li>
                <?php endforeach ?>
            </ol>
        </div>
    </div>

    <div class="space-y-6">
        <form method="post" class="card space-y-4 p-5">
            <?= csrf_field() ?>
            <h2 class="font-semibold">Durumu güncelle</h2>
            <select name="status" class="input">
                <?php foreach (order_statuses() as $key => [$label]): ?>
                    <option value="<?= $key ?>" <?= $order['status'] === $key ? 'selected' : '' ?>><?= $label ?></option>
                <?php endforeach ?>
            </select>
            <input name="note" class="input" placeholder="Not (örn. kargo takip no)">
            <button class="btn-primary w-full">Kaydet</button>
            <p class="text-xs text-zinc-500">İptal edilen siparişlerin stoğu otomatik geri eklenir.</p>
        </form>

        <div class="card p-5">
            <h2 class="font-semibold">Müşteri</h2>
            <div class="mt-4 space-y-2 text-sm text-zinc-600">
                <p class="font-medium text-ink"><?= e($order['name']) ?></p>
                <p class="flex items-center gap-2"><?= icon('mail', 'size-4 text-zinc-400') ?><a href="mailto:<?= e($order['email']) ?>" class="hover:underline"><?= e($order['email']) ?></a></p>
                <p class="flex items-center gap-2"><?= icon('phone', 'size-4 text-zinc-400') ?><a href="tel:<?= e($order['phone']) ?>" class="hover:underline"><?= e($order['phone']) ?></a></p>
            </div>
            <?php if ($customer): ?>
                <a href="<?= admin_url('musteri?id=' . $customer['id']) ?>" class="mt-4 inline-flex text-sm font-medium text-ink hover:underline">Üye · <?= $order_count ?> sipariş →</a>
            <?php else: ?>
                <p class="mt-4 text-xs text-zinc-400">Üye olmadan sipariş verdi.</p>
            <?php endif ?>
        </div>

        <div class="card p-5">
            <h2 class="font-semibold">Teslimat adresi</h2>
            <p class="mt-4 text-sm leading-6 text-zinc-600"><?= nl2br(e($order['address'])) ?><br><?= e($order['district']) ?> / <?= e($order['city']) ?></p>
            <?php if ($order['note']): ?>
                <p class="mt-4 rounded-lg bg-amber-50 px-3 py-2 text-sm text-amber-800">Not: <?= e($order['note']) ?></p>
            <?php endif ?>
        </div>

        <div class="card p-5">
            <div class="flex items-center justify-between gap-3">
                <h2 class="font-semibold">Ödeme</h2>
                <?= payment_status_badge($order['payment_status']) ?>
            </div>
            <p class="mt-4 text-sm text-zinc-600"><?= payment_label($order['payment']) ?></p>

            <?php foreach (order_payments($order['id']) as $payment): ?>
                <div class="mt-4 rounded-xl border border-zinc-200 p-3 text-xs">
                    <div class="flex items-center justify-between gap-2">
                        <span class="font-semibold"><?= e(card_gateways()[$payment['provider']][0] ?? $payment['provider']) ?></span>
                        <?= payment_status_badge($payment['status']) ?>
                    </div>
                    <dl class="mt-2 space-y-1 text-zinc-500">
                        <div class="flex justify-between gap-2"><dt>Tutar</dt><dd class="text-zinc-800"><?= money($payment['amount']) ?><?= $payment['installment'] > 1 ? ' · ' . (int) $payment['installment'] . ' taksit' : '' ?></dd></div>
                        <div class="flex justify-between gap-2"><dt>Referans</dt><dd class="font-mono text-zinc-800"><?= e($payment['reference']) ?></dd></div>
                        <?php if ($payment['transaction_id'] && $payment['status'] === 'paid'): ?><div class="flex justify-between gap-2"><dt>İşlem no</dt><dd class="font-mono text-zinc-800"><?= e($payment['transaction_id']) ?></dd></div><?php endif ?>
                        <div class="flex justify-between gap-2"><dt>Tarih</dt><dd class="text-zinc-800"><?= date_tr($payment['updated_at'] ?: $payment['created_at'], true) ?></dd></div>
                        <?php if ($payment['error']): ?><div class="pt-1 text-rose-600"><?= e($payment['error']) ?></div><?php endif ?>
                    </dl>
                </div>
            <?php endforeach ?>

            <form method="post" class="mt-4 flex gap-2">
                <?= csrf_field() ?>
                <select name="payment_status" class="input py-2 text-sm">
                    <?php foreach (payment_statuses() as $key => [$label]): ?>
                        <option value="<?= $key ?>" <?= $order['payment_status'] === $key ? 'selected' : '' ?>><?= $label ?></option>
                    <?php endforeach ?>
                </select>
                <button name="action" value="payment" class="btn-light btn-sm shrink-0">Güncelle</button>
            </form>
        </div>
    </div>
</div>

<?php admin_footer() ?>

Lisans bilgisi projenin LICENSE dosyasında.