File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/views/admin/orders/show.php
Back
<?php $statusMap = [ 'pending_payment' => ['status-pending', 'รอชำระเงิน'], 'payment_confirmed' => ['status-approved', 'ชำระเงินแล้ว'], 'preparing' => ['status-preparing', 'กำลังแพ็ค'], 'shipping' => ['status-shipping', 'จัดส่งแล้ว'], 'completed' => ['status-completed', 'สำเร็จ'], 'cancelled' => ['status-danger', 'ยกเลิก'], 'refunded' => ['status-secondary', 'คืนเงิน'], ]; [$pillClass, $pillLabel] = $statusMap[$order['order_status']] ?? ['status-secondary', $order['order_status']]; ?> <div class="mb-3"> <a href="<?= url('/admin/orders') ?>" class="btn btn-outline-secondary btn-sm py-1 px-3"> <i class="bi bi-arrow-left me-1"></i>กลับรายการคำสั่งซื้อ </a> </div> <!-- ── Detail Summary Header ───────────────────────────── --> <div class="admin-detail-summary-header"> <div class="d-flex align-items-center gap-3"> <div> <div class="d-flex align-items-center gap-2 flex-wrap"> <h5 class="fw-bold mb-0 text-dark font-monospace">Order #<?= e($order['order_no']) ?></h5> <span class="status-pill <?= $pillClass ?>"><?= $pillLabel ?></span> <?php if ($order['payment_status'] === 'paid'): ?> <span class="status-pill status-active"><i class="bi bi-check-circle-fill me-1"></i>ชำระเงินแล้ว</span> <?php else: ?> <span class="status-pill status-pending"><i class="bi bi-clock me-1"></i><?= e($order['payment_status'] ?? 'pending') ?></span> <?php endif; ?> </div> <div class="text-muted small mt-1"> ร้านค้า: <strong><?= e($order['store_name']) ?></strong> • สั่งซื้อเมื่อ: <?= date('d M Y • H:i', strtotime($order['created_at'])) ?> </div> </div> </div> <div class="d-flex align-items-center gap-2"> <span class="badge bg-light text-muted border px-3 py-2"> <i class="bi bi-shield-lock me-1 text-primary"></i> Read-Only Audit View </span> </div> </div> <div class="row g-4"> <!-- Left Order Line Items & Customer Details --> <div class="col-lg-8"> <!-- Items Table Card --> <div class="admin-table-container mb-4"> <div class="admin-table-header"> <div class="d-flex align-items-center gap-2"> <i class="bi bi-box-seam text-primary"></i> <span class="fw-bold text-dark" style="font-size: 0.9rem;">รายการสินค้าในคำสั่งซื้อ</span> <span class="badge bg-light text-muted border ms-1"><?= count($order['items'] ?? []) ?> รายการ</span> </div> </div> <div class="table-responsive"> <table class="admin-table"> <thead> <tr> <th>สินค้า</th> <th class="text-end">ราคาต่อหน่วย</th> <th class="text-center">จำนวน</th> <th class="text-end">รวมยอด</th> </tr> </thead> <tbody> <?php foreach ($order['items'] ?? [] as $item): ?> <tr> <td> <div class="fw-semibold text-dark"><?= e($item['product_name']) ?></div> <?php if (!empty($item['sku_variation'])): ?> <div class="text-muted small font-monospace"><?= e($item['sku_variation']) ?></div> <?php endif; ?> </td> <td class="text-end font-monospace">฿<?= number_format((float)$item['unit_price'], 2) ?></td> <td class="text-center font-monospace"><?= (int)$item['quantity'] ?></td> <td class="text-end fw-semibold font-monospace">฿<?= number_format((float)$item['subtotal'], 2) ?></td> </tr> <?php endforeach; ?> </tbody> <tfoot class="bg-light"> <tr> <td colspan="3" class="text-end text-muted small">ค่าจัดส่งสินค้า (Shipping Fee)</td> <td class="text-end font-monospace small">฿<?= number_format((float)$order['shipping_fee'], 2) ?></td> </tr> <tr> <td colspan="3" class="text-end fw-bold text-dark">ยอดรวมทั้งหมด (Total Amount)</td> <td class="text-end fw-bold text-primary font-monospace fs-6">฿<?= number_format((float)$order['total_amount'], 2) ?></td> </tr> </tfoot> </table> </div> </div> <!-- Customer & Shipping Information --> <div class="row g-3 mb-4"> <div class="col-md-6"> <div class="admin-detail-card h-100 mb-0"> <div class="admin-detail-card-header"> <span><i class="bi bi-person text-primary me-2"></i>ข้อมูลผู้ซื้อ (Customer)</span> </div> <div class="admin-detail-card-body small"> <div class="fw-bold text-dark mb-1"><?= e($order['customer_name']) ?></div> <div class="text-muted mb-1"><i class="bi bi-telephone me-1"></i><?= e($order['customer_phone'] ?? '—') ?></div> <div class="text-muted"><i class="bi bi-envelope me-1"></i><?= e($order['customer_email'] ?? '—') ?></div> </div> </div> </div> <div class="col-md-6"> <div class="admin-detail-card h-100 mb-0"> <div class="admin-detail-card-header"> <span><i class="bi bi-geo-alt text-primary me-2"></i>ที่อยู่สำหรับจัดส่ง</span> </div> <div class="admin-detail-card-body small text-muted lh-base"> <?= nl2br(e($order['shipping_address'] ?? '—')) ?> </div> </div> </div> </div> <!-- Investigation History & Activity Log --> <div class="admin-detail-card"> <div class="admin-detail-card-header"> <span><i class="bi bi-clock-history text-primary me-2"></i>ประวัติการตรวจสอบของ Admin (Investigation Trail)</span> </div> <div class="admin-detail-card-body p-3"> <?php if (empty($history)): ?> <p class="text-muted small text-center my-2">ยังไม่มีบันทึกโน้ตการตรวจสอบในคำสั่งซื้อนี้</p> <?php else: ?> <div class="admin-timeline"> <?php foreach ($history as $h): ?> <div class="admin-timeline-item"> <div class="admin-timeline-point"></div> <div class="small fw-semibold text-dark"> @<?= e($h['admin_username'] ?? 'Admin') ?> <span class="text-muted fw-normal" style="font-size: 0.72rem;">• <?= date('d M Y H:i', strtotime($h['created_at'])) ?></span> </div> <div class="small text-muted bg-light p-2 rounded-2 mt-1"> <?= nl2br(e($h['detail'])) ?> </div> </div> <?php endforeach; ?> </div> <?php endif; ?> </div> </div> </div> <!-- Right Financial Flow, Payment Slip Verification & Investigation Box --> <div class="col-lg-4"> <!-- Payment & Slip Verification Card --> <?php if (!empty($payment)): ?> <div class="admin-detail-card mb-4 border-<?= in_array($order['payment_status'], ['awaiting_verification', 'pending']) ? 'warning' : 'light' ?>"> <div class="admin-detail-card-header d-flex justify-content-between align-items-center"> <span><i class="bi bi-credit-card text-primary me-2"></i>การชำระเงิน & สลิป</span> <a href="<?= url('/admin/payments/' . e($order['order_no'])) ?>" class="small text-decoration-none fw-semibold"> ดูแบบละเอียด → </a> </div> <div class="admin-detail-card-body p-3"> <div class="d-flex justify-content-between align-items-center mb-2 pb-2 border-bottom"> <span class="text-muted small">สถานะการชำระ:</span> <div> <?php if ($order['payment_status'] === 'confirmed' || $order['payment_status'] === 'paid'): ?> <span class="badge bg-success"><i class="bi bi-check-circle me-1"></i>ยืนยันแล้ว</span> <?php elseif ($order['payment_status'] === 'awaiting_verification'): ?> <span class="badge bg-primary"><i class="bi bi-hourglass-split me-1"></i>รอตรวจสอบ</span> <?php elseif ($order['payment_status'] === 'failed'): ?> <span class="badge bg-danger">ล้มเหลว</span> <?php else: ?> <span class="badge bg-warning text-dark"><i class="bi bi-clock me-1"></i><?= e($order['payment_status']) ?></span> <?php endif; ?> </div> </div> <?php $latestAttempt = !empty($payment['attempts']) ? end($payment['attempts']) : null; ?> <?php if (!empty($latestAttempt)): ?> <div class="mb-3"> <div class="fw-bold small text-dark mb-1">สลิปการโอนล่าสุด (ครั้งที่ <?= (int)$latestAttempt['attempt_no'] ?>):</div> <?php if (!empty($latestAttempt['slip_image'])): ?> <div class="text-center my-2 p-2 bg-light rounded border"> <a href="<?= asset('/uploads/slips/' . e($latestAttempt['slip_image'])) ?>" target="_blank"> <img src="<?= asset('/uploads/slips/' . e($latestAttempt['slip_image'])) ?>" alt="slip" class="img-fluid rounded" style="max-height: 180px; object-fit: contain; cursor: pointer;"> </a> <div class="mt-1"> <a href="<?= asset('/uploads/slips/' . e($latestAttempt['slip_image'])) ?>" target="_blank" class="small text-primary text-decoration-none"> <i class="bi bi-zoom-in me-1"></i>คลิกเพื่อดูภาพขยาย </a> </div> </div> <?php endif; ?> <div class="small text-muted"> <div>อัปโหลดเมื่อ: <?= date('d/m/Y H:i', strtotime($latestAttempt['created_at'])) ?></div> <?php if (!empty($latestAttempt['note'])): ?> <div class="mt-1 text-dark">หมายเหตุ: <?= e($latestAttempt['note']) ?></div> <?php endif; ?> <?php if (!empty($latestAttempt['reject_reason'])): ?> <div class="alert alert-danger py-1 px-2 small mt-1 mb-0">เหตุผลปฏิเสธ: <?= e($latestAttempt['reject_reason']) ?></div> <?php endif; ?> </div> </div> <?php else: ?> <div class="text-center py-3 text-muted small"> <i class="bi bi-inbox fs-3 d-block text-muted mb-1"></i> ยังไม่มีประวัติการแนบสลิป </div> <?php endif; ?> <!-- Verify Actions --> <?php if (AdminMiddleware::can('payment.verify') || AdminMiddleware::can('finance.view')): ?> <?php if ($order['payment_status'] !== 'confirmed' && $order['payment_status'] !== 'paid' && $order['payment_status'] !== 'refunded' && $order['order_status'] !== 'cancelled'): ?> <div class="d-flex gap-2 pt-2 border-top"> <button type="button" class="btn btn-success btn-sm w-100 fw-bold order-verify-btn" data-action="confirm" data-attempt-id="<?= (int)($latestAttempt['id'] ?? 0) ?>" data-payment-id="<?= (int)$payment['id'] ?>" data-order-no="<?= e($order['order_no']) ?>"> <i class="bi bi-check-circle me-1"></i>ยืนยันการชำระเงิน </button> <button type="button" class="btn btn-outline-danger btn-sm px-3 order-verify-btn" data-action="reject" data-attempt-id="<?= (int)($latestAttempt['id'] ?? 0) ?>" data-payment-id="<?= (int)$payment['id'] ?>" data-order-no="<?= e($order['order_no']) ?>"> <i class="bi bi-x-circle me-1"></i>ปฏิเสธ </button> </div> <?php endif; ?> <?php endif; ?> </div> </div> <?php endif; ?> <!-- Transparent Financial Breakdown Card --> <div class="admin-detail-card mb-4"> <div class="admin-detail-card-header"> <span><i class="bi bi-currency-exchange text-primary me-2"></i>ความโปร่งใสทางการเงิน (Financial Flow)</span> </div> <div class="admin-detail-card-body p-3"> <dl class="row mb-0 small"> <dt class="col-6 text-muted mb-2">ยอดชำระสุทธิ (Gross)</dt> <dd class="col-6 text-end fw-bold text-dark font-monospace mb-2"> ฿<?= number_format((float)$order['total_amount'], 2) ?> </dd> <dt class="col-6 text-muted mb-2">ค่าธรรมเนียม (Commission)</dt> <dd class="col-6 text-end fw-semibold text-warning font-monospace mb-2"> ฿<?= number_format((float)($order['commission_amount'] ?? 0), 2) ?> </dd> <dt class="col-6 text-muted mb-2">โอนเข้าผู้ขาย (Net Revenue)</dt> <dd class="col-6 text-end fw-bold text-success font-monospace mb-2"> ฿<?= number_format((float)($order['net_revenue'] ?? 0), 2) ?> </dd> <dt class="col-6 text-muted mb-0">ช่องทางชำระเงิน</dt> <dd class="col-6 text-end mb-0"> <span class="badge bg-light text-dark border"><?= e($order['payment_method'] ?? 'PromptPay') ?></span> </dd> </dl> </div> </div> <!-- Admin Investigation Note Action Box --> <?php if (AdminMiddleware::can('order.investigate')): ?> <div class="admin-detail-card"> <div class="admin-detail-card-header"> <span><i class="bi bi-pencil-square text-primary me-2"></i>บันทึกการตรวจสอบ (Admin Note)</span> </div> <div class="admin-detail-card-body p-3"> <form action="<?= url('/admin/orders/' . e($order['order_no']) . '/note') ?>" method="POST"> <?= Security::csrfField() ?> <div class="mb-3"> <textarea name="note" class="form-control form-control-sm" rows="4" placeholder="บันทึกผลการประสานงาน, สาเหตุการร้องเรียน, การตรวจสอบหลักฐานการชำระเงิน..." required></textarea> <div class="form-text small">บันทึกนี้จะถูกเก็บในประวัติการตรวจสอบเฉพาะ Admin เท่านั้น</div> </div> <button type="submit" class="btn btn-primary btn-sm w-100"> <i class="bi bi-journal-plus me-1"></i>เพิ่มบันทึกการตรวจสอบ </button> </form> </div> </div> <?php endif; ?> </div> </div> <!-- Order Verify Modal --> <div class="modal fade" id="orderVerifyModal" tabindex="-1" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content"> <form id="orderVerifyForm" method="POST" action="<?= url('/admin/payments/verify') ?>"> <?= Security::csrfField() ?> <input type="hidden" name="attempt_id" id="modalVerifyAttemptId" value="0"> <input type="hidden" name="payment_id" id="modalVerifyPaymentId" value="0"> <input type="hidden" name="action" id="modalVerifyAction" value=""> <input type="hidden" name="order_no" value="<?= e($order['order_no']) ?>"> <input type="hidden" name="redirect_to" value="<?= url('/admin/orders/' . e($order['order_no'])) ?>"> <div class="modal-header border-0 pb-0"> <h5 class="modal-title fw-bold" id="modalVerifyTitle"></h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body pt-2"> <div id="modalVerifyConfirmNote" class="mb-3"> <label class="form-label small fw-bold text-muted">หมายเหตุ (ถ้ามี)</label> <textarea name="note" class="form-control form-control-sm" rows="2" placeholder="บันทึกเพิ่มเติม..."></textarea> </div> <div id="modalVerifyRejectReason" class="mb-3 d-none"> <label class="form-label small fw-bold text-danger">เหตุผลในการปฏิเสธ <span class="text-danger">*</span></label> <textarea name="reason" id="modalVerifyReasonInput" class="form-control form-control-sm" rows="3" placeholder="ระบุเหตุผลที่ชัดเจน..."></textarea> </div> <div id="modalVerifyWarningConfirm" class="alert alert-success py-2 small d-none"> <i class="bi bi-check-circle me-1"></i>การยืนยันจะเปลี่ยนสถานะออเดอร์เป็น <strong>กำลังเตรียมสินค้า (Preparing)</strong> ทันที </div> <div id="modalVerifyWarningReject" class="alert alert-warning py-2 small d-none"> <i class="bi bi-exclamation-triangle me-1"></i>ลูกค้าจะได้รับการแจ้งเตือนและสามารถอัปโหลดสลิปใหม่ได้ </div> </div> <div class="modal-footer border-0 pt-0"> <button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">ยกเลิก</button> <button type="submit" class="btn btn-sm fw-bold px-4" id="modalVerifySubmitBtn"></button> </div> </form> </div> </div> </div> <script> document.querySelectorAll('.order-verify-btn').forEach(btn => { btn.addEventListener('click', () => { const action = btn.dataset.action; const attemptId = btn.dataset.attemptId || 0; const paymentId = btn.dataset.paymentId || 0; document.getElementById('modalVerifyAttemptId').value = attemptId; document.getElementById('modalVerifyPaymentId').value = paymentId; document.getElementById('modalVerifyAction').value = action; const isConfirm = action === 'confirm'; document.getElementById('modalVerifyTitle').textContent = isConfirm ? 'ยืนยันการชำระเงิน' : 'ปฏิเสธสลิปการโอนเงิน'; document.getElementById('modalVerifyConfirmNote').classList.toggle('d-none', !isConfirm); document.getElementById('modalVerifyRejectReason').classList.toggle('d-none', isConfirm); document.getElementById('modalVerifyWarningConfirm').classList.toggle('d-none', !isConfirm); document.getElementById('modalVerifyWarningReject').classList.toggle('d-none', isConfirm); const submitBtn = document.getElementById('modalVerifySubmitBtn'); submitBtn.textContent = isConfirm ? 'ยืนยันการชำระเงิน' : 'ปฏิเสธสลิป'; submitBtn.className = 'btn btn-sm fw-bold px-4 ' + (isConfirm ? 'btn-success' : 'btn-danger'); new bootstrap.Modal(document.getElementById('orderVerifyModal')).show(); }); }); document.getElementById('orderVerifyForm').addEventListener('submit', async function(e) { e.preventDefault(); const btn = document.getElementById('modalVerifySubmitBtn'); btn.disabled = true; btn.textContent = 'กำลังดำเนินการ...'; try { const res = await fetch(this.action, { method: 'POST', headers: { 'X-Requested-With': 'XMLHttpRequest' }, body: new FormData(this) }); const data = await res.json(); if (data.success) { location.reload(); } else { alert(data.message || 'เกิดข้อผิดพลาด'); btn.disabled = false; } } catch { alert('เกิดข้อผิดพลาดในการเชื่อมต่อ'); btn.disabled = false; } }); </script>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.23 |
proxy
|
phpinfo
|
Settings