function getTableStatusKey (order: IAppOrder): TTableDisplayStatusKey { const isOrdered = order.batches[0]?.items?.length > 0 const isPaid = order.payments.length > 0 if (order.status === 'cancelled') { return isPaid ? 'delete_order' : 'cancel_table' } // 已有結帳但還沒結完 if (isPaid && order.status !== 'paid') { return 'waiting_pay' } if (order.status === 'pending') { return isOrdered ? 'waiting_pay' : 'waiting_order' } if (order.status === 'paid') { return 'paid' } return 'unknow' } function getTakeawayStatusKey (order: IAppOrder): TTakeawayDisplayStatusKey { const isOrdered = order.batches[0]?.items?.length > 0 const isPaid = order.payments.length > 0 if (order.status === 'cancelled') { return isPaid ? 'delete_order' : 'cancel_order' } // 已有結帳但還沒結完 if (isPaid && order.status !== 'paid') { return 'waiting_pay' } // 先處理通用的 takeawayStatus if (order.takeawayStatus === 'confirmed') { // 餐廳已確認,顯示「備餐中」 return 'preparing_meal' } if (order.takeawayStatus === 'ready') { // 餐點已完成,顯示「待取餐」 return 'waiting_pick_up' } if (order.takeawayStatus === 'completed') { // 客人已取餐,顯示「已取餐」 return 'picked_up' } // 處理 status pending if (order.status === 'pending') { if (!isOrdered) { // batch 中沒東西,直接顯示「未點餐」 return 'waiting_order' } return 'waiting_pay' } // 處理 status paid if (order.status === 'paid') { if (order.takeawayStatus === 'pending') { // 餐廳還沒確認,顯示「待接單」 return 'waiting_accept' } } return 'unknow' } function getDeliveryStatusKey (order: IAppOrder): TDeliveryDisplayStatusKey { const isPaid = order.status === 'paid' || order.payments.length > 0 const isMerchentDelivery = false // TODO: 如何判斷是店家自己送(貨到付款) if (order.status === 'cancelled' || order.takeawayStatus === 'cancelled') { return isPaid ? 'delete_order' : 'cancel_order' } // 已有結帳但還沒結完 if (isPaid && order.status !== 'paid') { return 'waiting_pay' } if (order.takeawayStatus === 'pending') { // 餐廳還沒確認,顯示「待接單」 // 店家 key 的單會自動 call confirm api // 所以這個 takeawayStatus pending 只會在很短暫的時間出現,之後就會直接變成 confirmed // 客人下的單才會等店家接單 return 'waiting_accept' } if (order.takeawayStatus === 'confirmed') { // 餐廳已確認,顯示「備餐中」 return 'preparing_meal' } if (order.takeawayStatus === 'ready') { // 餐點已完成,顯示「待取餐」 return 'waiting_pick_up' } if (order.takeawayStatus === 'completed') { // client 下單,已結帳的訂單顯示「配送中」,否則顯示「待結帳」等外送員帶現金錢回來結帳 return isPaid ? 'in_delivery' : 'waiting_pay' } if (order.takeawayStatus === 'delivered') { // client 下單,由串接的外送 webhook 更改為 delivered,顯示「已送達」,若是店家自己送(貨到付款)則顯示「已完成」 return isMerchentDelivery ? 'complete' : 'arrived' } return 'unknow' } export const getStatusKeys = { table: getTableStatusKey, takeaway: getTakeawayStatusKey, delivery: getDeliveryStatusKey, storeDelivery: getDeliveryStatusKey, shop: getDeliveryStatusKey, } // 排序資料並將可以辨識是否唯一的資料加入 dataId export default function getDisplayStatusKey (order: IAppOrder): TDisplayStatusKey { if (order.deliveryType == null) return 'unknow' const stautsConfig = getStatusKeys[order.deliveryType] return stautsConfig(order) }