File manager - Edit - /home/webapp69.cm.in.th/u69319090039/Shop39/app/Models/OrderStatusHistory.php
Back
<?php /** * OrderStatusHistory - Model for order status history/timeline */ class OrderStatusHistory { /** Status labels map */ public static array $labels = [ 'pending' => 'Pending (รอยืนยัน)', 'order_accepted' => 'Order Accepted (รับออเดอร์แล้ว)', 'waiting_payment' => 'Waiting Payment (รอชำระเงิน)', 'paid' => 'Paid (ชำระเงินแล้ว)', 'preparing' => 'Preparing Order (กำลังจัดเตรียม)', 'shipping' => 'Shipping (กำลังจัดส่ง)', 'delivered' => 'Delivered (จัดส่งสำเร็จ)', 'completed' => 'Completed (สำเร็จเรียบร้อย)', 'cancelled' => 'Cancelled (ยกเลิก)', 'refunded' => 'Refunded (คืนเงิน)', ]; /** * Add a new status history record. */ public static function add( int $orderId, string $statusKey, ?string $previousStatus = null, ?string $description = null, string $changedBy = 'Seller', ?string $location = null ): bool { $db = Database::getInstance(); $statusName = self::$labels[$statusKey] ?? ucfirst($statusKey); $sql = "INSERT INTO order_status_history (order_id, previous_status, status_key, status_name, location, description, changed_by, event_time) VALUES (:oid, :prev, :skey, :sname, :loc, :desc, :cby, NOW())"; $stmt = $db->prepare($sql); return $stmt->execute([ 'oid' => $orderId, 'prev' => $previousStatus, 'skey' => $statusKey, 'sname' => $statusName, 'loc' => $location ?? '', 'desc' => $description ?? '', 'cby' => $changedBy ]); } /** * Get full history for an order. */ public static function getHistory(int $orderId): array { $db = Database::getInstance(); $stmt = $db->prepare("SELECT * FROM order_status_history WHERE order_id = :oid ORDER BY id ASC"); $stmt->execute(['oid' => $orderId]); return $stmt->fetchAll(); } /** * Check if a specific status already exists in history */ public static function hasStatus(int $orderId, string $statusKey): bool { $db = Database::getInstance(); $stmt = $db->prepare("SELECT id FROM order_status_history WHERE order_id = :oid AND status_key = :skey LIMIT 1"); $stmt->execute(['oid' => $orderId, 'skey' => $statusKey]); return (bool)$stmt->fetch(); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.22 |
proxy
|
phpinfo
|
Settings