fix(orders): wire detail progress timeline and two-step cancel
Order progress was stuck on "订单创建" because timeline only read sparse timestamp columns and status transitions didn't always stamp them. Drive timeline from current status + related records, backfill lifecycle timestamps on update_status, and replace window.confirm cancel with a 关闭订单 → 确认取消 button step in the detail modal.
This commit is contained in:
1 parent
64d0dc66da
commit
ad40d9a7ca
4 files changed
+327
-61
No files matched your search
+39
-22
@@ -556,44 +556,61 @@ trait Part1 {
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shop-side timeline; keep behaviour aligned with UserOrders.
|
||||
*
|
||||
* @param array<string, mixed> $order
|
||||
* @param array<int, array> $shipping_records
|
||||
* @param array<int, array> $after_sale_records
|
||||
* @return array<int, array{time:string,label:string,key?:string}>
|
||||
*/
|
||||
private function build_order_timeline(array $order, array $shipping_records, array $after_sale_records): array {
|
||||
$timeline = [];
|
||||
$date_fields = [
|
||||
'created_at' => __('订单创建', 'aksrt'),
|
||||
'paid_at' => __('完成支付', 'aksrt'),
|
||||
'delivered_at' => __('订单发货', 'aksrt'),
|
||||
'completed_at' => __('交易完成', 'aksrt'),
|
||||
'cancelled_at' => __('订单取消', 'aksrt'),
|
||||
'refunded_at' => __('完成退款', 'aksrt'),
|
||||
];
|
||||
|
||||
foreach ($date_fields as $key => $label) {
|
||||
if (!empty($order[$key])) {
|
||||
$timeline[] = [
|
||||
'time' => (string) $order[$key],
|
||||
'label' => $label,
|
||||
];
|
||||
// Prefer the unified order-center builder when available.
|
||||
if (class_exists('\AKSRT\Payment\UserOrders')) {
|
||||
$view = \AKSRT\Payment\UserOrders::get_instance()->decorate_order_view($order, true);
|
||||
if (is_array($view['timeline'] ?? null)) {
|
||||
return $view['timeline'];
|
||||
}
|
||||
}
|
||||
|
||||
$timeline = [];
|
||||
$created = (string) ($order['created_at'] ?? '');
|
||||
if ($created !== '') {
|
||||
$timeline[] = ['key' => 'created', 'time' => $created, 'label' => __('订单创建', 'aksrt')];
|
||||
}
|
||||
$status = (string) ($order['status'] ?? '');
|
||||
$paid_like = [
|
||||
\AKSRT\Payment\Order::STATUS_PAID,
|
||||
\AKSRT\Payment\Order::STATUS_DELIVERED,
|
||||
\AKSRT\Payment\Order::STATUS_COMPLETED,
|
||||
\AKSRT\Payment\Order::STATUS_PENDING_REVIEW,
|
||||
\AKSRT\Payment\Order::STATUS_REFUNDED,
|
||||
\AKSRT\Payment\Order::STATUS_REFUNDING,
|
||||
];
|
||||
if (!empty($order['paid_at']) || in_array($status, $paid_like, true)) {
|
||||
$timeline[] = [
|
||||
'key' => 'paid',
|
||||
'time' => (string) ($order['paid_at'] ?? $created),
|
||||
'label' => __('完成支付', 'aksrt'),
|
||||
];
|
||||
}
|
||||
foreach ($shipping_records as $record) {
|
||||
$timeline[] = [
|
||||
'time' => (string) ($record['created_at'] ?? ''),
|
||||
'key' => 'shipping',
|
||||
'time' => (string) ($record['created_at'] ?? ''),
|
||||
'label' => sprintf(__('物流更新:%s', 'aksrt'), $record['tracking_no'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($after_sale_records as $record) {
|
||||
$timeline[] = [
|
||||
'time' => (string) ($record['created_at'] ?? ''),
|
||||
'key' => 'after_sale',
|
||||
'time' => (string) ($record['created_at'] ?? ''),
|
||||
'label' => sprintf(__('售后申请:%s', 'aksrt'), $record['reason'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
usort($timeline, static function ($a, $b) {
|
||||
return strcmp($a['time'] ?? '', $b['time'] ?? '');
|
||||
return strcmp((string) ($a['time'] ?? ''), (string) ($b['time'] ?? ''));
|
||||
});
|
||||
|
||||
return $timeline;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user