[PROMOTE] 晉升 dev 交易出貨交付狀態與多語系支援至 demo

1. 新增 orders.delivery_status 欄位以記錄整筆交易之最終出貨結果(相容舊機台)。
2. 整合 TransactionService 出貨判定輔助方法(自動由個別貨道上報計算整體狀態)。
3. 升級後台銷售紀錄清單、側邊滑出明細面板與 Excel/CSV 報表匯出功能,區分「付款狀態」與「出貨狀態」。
4. 完成繁、英、日三語系完美排序對齊。
This commit is contained in:
sky121113 2026-05-29 12:18:43 +08:00
commit 19ad440d34
9 changed files with 159 additions and 10 deletions

View File

@ -882,7 +882,8 @@ class SalesController extends Controller
__('Discount Amount'),
__('Payment Amount'),
__('Payment Type'),
__('Status'),
__('Payment Status'),
__('Dispense Status'),
__('Invoice Number'),
__('Staff Name'),
__('Staff ID'),
@ -922,6 +923,16 @@ class SalesController extends Controller
$totalQty = $order->items->sum('quantity');
// 轉換訂單狀態標籤,與前端 tab-orders.blade.php / detail 面板一致
$statusLabelMap = [
'pending' => __('Pending'),
'paid' => __('Paid'),
'completed' => __('Completed'),
'cancelled' => __('Cancelled'),
'refunded' => __('Refunded'),
];
$paymentStatusLabel = $statusLabelMap[$order->status] ?? $order->status;
$row = [
$order->order_no,
$order->created_at->format('Y-m-d H:i:s'),
@ -933,7 +944,8 @@ class SalesController extends Controller
number_format($order->discount_amount, 2, '.', ''),
number_format($order->pay_amount, 2, '.', ''),
$order->payment_type_label,
__($order->status),
$paymentStatusLabel,
$order->delivery_status_label,
$order->invoice->invoice_no ?? '---',
$order->staffCardLog->staffCard->name ?? '---',
$order->staffCardLog->staffCard->employee_id ?? '---',

View File

@ -17,6 +17,11 @@ class Order extends Model
public const PAYMENT_STATUS_FAILED = 0;
public const PAYMENT_STATUS_SUCCESS = 1;
// 出貨狀態
public const DELIVERY_STATUS_FAILED = 0;
public const DELIVERY_STATUS_SUCCESS = 1;
public const DELIVERY_STATUS_PARTIAL = 2;
protected $fillable = [
'company_id',
'flow_id',
@ -41,6 +46,7 @@ class Order extends Model
'machine_time',
'status',
'metadata',
'delivery_status',
];
protected $casts = [
@ -53,6 +59,7 @@ class Order extends Model
'machine_time' => 'datetime',
'metadata' => 'array',
'payment_type' => 'integer',
'delivery_status' => 'integer',
];
/**
@ -148,4 +155,24 @@ class Order extends Model
{
return $this->belongsTo(WelcomeGift::class);
}
/**
* 取得所有出貨狀態的對照標籤
*/
public static function getDeliveryStatusLabels(): array
{
return [
self::DELIVERY_STATUS_FAILED => __('Dispense Failed'),
self::DELIVERY_STATUS_SUCCESS => __('Dispense Success'),
self::DELIVERY_STATUS_PARTIAL => __('Partial Dispense Success'),
];
}
/**
* 取得目前出貨狀態標籤 (Accessor)
*/
public function getDeliveryStatusLabelAttribute(): string
{
return self::getDeliveryStatusLabels()[$this->delivery_status] ?? __('Unknown');
}
}

View File

@ -71,6 +71,7 @@ class TransactionService
'payment_at' => now(),
'status' => 'completed',
'metadata' => $data['metadata'] ?? null,
'delivery_status' => (int) ($data['delivery_status'] ?? Order::DELIVERY_STATUS_SUCCESS),
]);
// Create Order Items
@ -250,6 +251,9 @@ class TransactionService
// 確保提取 payment_type 與 flow_id (可能在 root 或 order 內)
$orderData['flow_id'] = $flowId;
if (!isset($orderData['delivery_status']) && !empty($data['dispense'])) {
$orderData['delivery_status'] = $this->resolveDeliveryStatusFromDispense($data['dispense']);
}
if (!isset($orderData['payment_type']) && isset($data['payment_type'])) {
$orderData['payment_type'] = $data['payment_type'];
}
@ -385,4 +389,33 @@ class TransactionService
return $order;
});
}
/**
* Resolve order-level delivery status from item-level dispense results.
*/
protected function resolveDeliveryStatusFromDispense(array $dispense): int
{
$dispenseList = isset($dispense[0]) ? $dispense : [$dispense];
$statuses = collect($dispenseList)
->filter(fn ($item) => is_array($item) && array_key_exists('dispense_status', $item))
->map(fn ($item) => (int) $item['dispense_status']);
if ($statuses->isEmpty()) {
return Order::DELIVERY_STATUS_SUCCESS;
}
$successCount = $statuses
->filter(fn ($status) => $status === Order::DELIVERY_STATUS_SUCCESS)
->count();
if ($successCount === $statuses->count()) {
return Order::DELIVERY_STATUS_SUCCESS;
}
if ($successCount === 0) {
return Order::DELIVERY_STATUS_FAILED;
}
return Order::DELIVERY_STATUS_PARTIAL;
}
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('orders', function (Blueprint $table) {
$table->tinyInteger('delivery_status')->default(1)->comment('出貨狀態: 0:出貨失敗, 1:出貨成功, 2:部分出貨成功')->after('payment_status');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('orders', function (Blueprint $table) {
$table->dropColumn('delivery_status');
});
}
};

View File

@ -1341,6 +1341,7 @@
"Page 7": "Page 7",
"Page Lock Status": "Page Lock Status",
"Parameters": "Parameters",
"Partial Dispense Success": "Partial Dispense Success",
"Pass Code": "Pass Code",
"Pass Code (8 Digits)": "Pass Code (8 Digits)",
"Pass Code Management": "Pass Code Management",
@ -1363,6 +1364,7 @@
"Payment Configuration deleted successfully.": "Payment Configuration deleted successfully.",
"Payment Configuration updated successfully.": "Payment Configuration updated successfully.",
"Payment Selection": "Payment Selection",
"Payment Status": "Payment Status",
"Payment Type": "Payment Type",
"Pending": "Pending",
"Per Page": "Per Page",

View File

@ -1341,6 +1341,7 @@
"Page 7": "ページ 7 (ロックページ)",
"Page Lock Status": "ページロックステータス",
"Parameters": "パラメータ設定",
"Partial Dispense Success": "一部出庫成功",
"Pass Code": "パスコード",
"Pass Code (8 Digits)": "パスコード (8桁)",
"Pass Code Management": "パスコード管理",
@ -1363,6 +1364,7 @@
"Payment Configuration deleted successfully.": "決済設定が正常に削除されました。",
"Payment Configuration updated successfully.": "決済設定が正常に更新されました。",
"Payment Selection": "支払選択",
"Payment Status": "決済ステータス",
"Payment Type": "支払方法",
"Pending": "保留中",
"Per Page": "1ページあたり表示",

View File

@ -1341,6 +1341,7 @@
"Page 7": "鎖定頁",
"Page Lock Status": "頁面鎖定狀態",
"Parameters": "參數設定",
"Partial Dispense Success": "部分出貨成功",
"Pass Code": "通行碼",
"Pass Code (8 Digits)": "通行碼 (8 位數)",
"Pass Code Management": "通行碼管理",
@ -1363,6 +1364,7 @@
"Payment Configuration deleted successfully.": "金流設定已成功刪除。",
"Payment Configuration updated successfully.": "金流設定已成功更新。",
"Payment Selection": "付款選擇",
"Payment Status": "付款狀態",
"Payment Type": "支付方式",
"Pending": "待處理",
"Per Page": "每頁顯示",

View File

@ -25,9 +25,9 @@
<div class="flex-1 overflow-y-auto p-6 sm:p-8 space-y-10">
{{-- 基本狀態卡片 --}}
<div class="grid grid-cols-2 gap-6 p-6 bg-slate-50/50 dark:bg-slate-800/30 rounded-[2rem] border border-slate-100 dark:border-slate-800">
<div class="grid grid-cols-3 gap-6 p-6 bg-slate-50/50 dark:bg-slate-800/30 rounded-[2rem] border border-slate-100 dark:border-slate-800">
<div class="space-y-2">
<p class="text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-widest">{{ __('Order Status') }}</p>
<p class="text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-widest">{{ __('Payment Status') }}</p>
<div>
@php
$statusMap = [
@ -56,6 +56,20 @@
{{ $order->payment_type_label }}
</p>
</div>
<div class="space-y-2">
<p class="text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-widest">{{ __('Dispense Status') }}</p>
<div>
@php
$deliveryStatusMap = [
0 => ['label' => __('Dispense Failed'), 'color' => 'rose'],
1 => ['label' => __('Dispense Success'), 'color' => 'emerald'],
2 => ['label' => __('Partial Dispense Success'), 'color' => 'amber'],
];
$ds = $deliveryStatusMap[$order->delivery_status] ?? ['label' => __('Unknown'), 'color' => 'slate'];
@endphp
<x-status-badge :color="$ds['color']" :label="$ds['label']" size="sm" />
</div>
</div>
</div>
{{-- 交易資訊 --}}

View File

@ -169,7 +169,11 @@
</th>
<th
class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800">
{{ __('Status') }}
{{ __('Payment Status') }}
</th>
<th
class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800">
{{ __('Dispense Status') }}
</th>
<th
class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800">
@ -263,13 +267,25 @@
'refunded' => ['label' => __('Refunded'), 'color' => 'rose'],
];
$s = $statusMap[$order->status] ?? ['label' => $order->status, 'color' => 'slate'];
$invoiceSearchValue = $order->invoice ? $order->invoice->invoice_no : $order->order_no;
$targetUrl = route('admin.sales.index', ['tab' => 'invoices', 'search' => $invoiceSearchValue]);
@endphp
<x-status-badge :color="$s['color']" :label="$s['label']" size="xs" />
</td>
<td class="px-6 py-6 whitespace-nowrap">
@php
$deliveryStatusMap = [
0 => ['label' => __('Dispense Failed'), 'color' => 'rose'],
1 => ['label' => __('Dispense Success'), 'color' => 'emerald'],
2 => ['label' => __('Partial Dispense Success'), 'color' => 'amber'],
];
$ds = $deliveryStatusMap[$order->delivery_status] ?? ['label' => __('Unknown'), 'color' => 'slate'];
@endphp
<x-status-badge :color="$ds['color']" :label="$ds['label']" size="xs" />
</td>
<td class="px-6 py-6 whitespace-nowrap">
@php
$invoiceSearchValue = $order->invoice ? $order->invoice->invoice_no : $order->order_no;
$targetUrl = route('admin.sales.index', ['tab' => 'invoices', 'search' => $invoiceSearchValue]);
@endphp
@if($order->invoice)
<div @click.stop="switchTab('invoices', '{{ $targetUrl }}')"
class="flex items-center gap-1.5 text-sm font-extrabold text-slate-600 dark:text-slate-400 cursor-pointer hover:text-cyan-500 transition-colors group/invoice"
@ -302,8 +318,8 @@
</tr>
@empty
<tr>
<td colspan="7" class="py-20 text-center">
<x-empty-state mode="table" colspan="7" :message="__('No transaction orders found')" />
<td colspan="8" class="py-20 text-center">
<x-empty-state mode="table" colspan="8" :message="__('No transaction orders found')" />
</td>
</tr>
@endforelse
@ -413,6 +429,19 @@
{{ $order->invoice->invoice_no ?? '---' }}
</p>
</div>
<div>
<p class="text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-widest mb-1">{{
__('Dispense Status') }}</p>
@php
$deliveryStatusMap = [
0 => ['label' => __('Dispense Failed'), 'color' => 'rose'],
1 => ['label' => __('Dispense Success'), 'color' => 'emerald'],
2 => ['label' => __('Partial Dispense Success'), 'color' => 'amber'],
];
$ds = $deliveryStatusMap[$order->delivery_status] ?? ['label' => __('Unknown'), 'color' => 'slate'];
@endphp
<x-status-badge :color="$ds['color']" :label="$ds['label']" size="xs" />
</div>
</div>
{{-- Action Buttons --}}