修复支付状态问题
This commit is contained in:
@@ -85,7 +85,7 @@ class PayOrders {
|
||||
? \AKSRT\Core\DomainModel::order_status_labels()
|
||||
: [];
|
||||
|
||||
// Type tabs (legacy order subsubsub parity).
|
||||
// Type tabs.
|
||||
$type_tabs = [
|
||||
'' => __('全部类型', 'aksrt'),
|
||||
'resource' => __('内容付费', 'aksrt'),
|
||||
@@ -177,9 +177,9 @@ class PayOrders {
|
||||
}
|
||||
echo '</form>';
|
||||
|
||||
// Hygiene actions (legacy clear_order / delete).
|
||||
// Closed-order cleanup.
|
||||
echo '<p style="margin:8px 0 12px;">';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:inline;" onsubmit="return confirm(\'' . esc_js(__('将删除 14 天前所有已关闭/已过期订单,不可恢复。确认清理?', 'aksrt')) . '\');">';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:inline;" onsubmit="return confirm(\'' . esc_js(__('将删除 14 天前所有已关闭订单,不可恢复。确认清理?', 'aksrt')) . '\');">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_clear_closed_orders" />';
|
||||
echo '<input type="hidden" name="days" value="14" />';
|
||||
wp_nonce_field('aksrt_pay_clear_closed_orders');
|
||||
@@ -219,23 +219,7 @@ class PayOrders {
|
||||
echo '<td style="display:flex;gap:6px;flex-wrap:wrap;align-items:center;">';
|
||||
echo '<a class="button button-small" href="' . esc_url($this->page_url('aksrt_orders', ['order' => $order_number])) . '">' . esc_html__('详情', 'aksrt') . '</a>';
|
||||
$this->render_order_quick_status_buttons($order_number, $status_key);
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:4px;align-items:center;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_update_order_status" />';
|
||||
echo '<input type="hidden" name="order_number" value="' . esc_attr($order_number) . '" />';
|
||||
wp_nonce_field('aksrt_pay_update_order_status_' . $order_number);
|
||||
echo '<select name="new_status">';
|
||||
foreach ($labels as $key => $label) {
|
||||
printf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
esc_attr($key),
|
||||
selected($status_key, $key, false),
|
||||
esc_html($label)
|
||||
);
|
||||
}
|
||||
echo '</select>';
|
||||
submit_button(__('更新', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
if (in_array($status_key, ['cancelled', 'expired'], true)) {
|
||||
if ($status_key === 'closed') {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:inline;" onsubmit="return confirm(\'' . esc_js(__('确认永久删除此订单?不可恢复。', 'aksrt')) . '\');">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_delete_order" />';
|
||||
echo '<input type="hidden" name="order_number" value="' . esc_attr($order_number) . '" />';
|
||||
@@ -325,18 +309,6 @@ class PayOrders {
|
||||
echo '<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:10px;">';
|
||||
$this->render_order_quick_status_buttons($order_number, $status, true);
|
||||
echo '</div>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:8px;align-items:center;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_update_order_status" />';
|
||||
echo '<input type="hidden" name="order_number" value="' . esc_attr($order_number) . '" />';
|
||||
echo '<input type="hidden" name="redirect_order" value="' . esc_attr($order_number) . '" />';
|
||||
wp_nonce_field('aksrt_pay_update_order_status_' . $order_number);
|
||||
echo '<select name="new_status">';
|
||||
foreach ($labels as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
submit_button(__('保存状态', 'aksrt'), 'primary', '', false);
|
||||
echo '</form>';
|
||||
}
|
||||
|
||||
public function handle_update_order_status(): void {
|
||||
@@ -350,7 +322,7 @@ class PayOrders {
|
||||
|
||||
$ok = false;
|
||||
if ($order_number !== '' && $new_status !== '' && class_exists('\AKSRT\Payment\OrderRepository')) {
|
||||
$ok = \AKSRT\Payment\OrderRepository::get_instance()->update_status($order_number, $new_status, ['force' => true]);
|
||||
$ok = \AKSRT\Payment\OrderRepository::get_instance()->update_status($order_number, $new_status);
|
||||
}
|
||||
|
||||
$args = ['aksrt_pay_msg' => $ok ? 'order_updated' : 'order_failed'];
|
||||
@@ -411,8 +383,8 @@ class PayOrders {
|
||||
if ($order_number !== '' && class_exists('\AKSRT\Payment\OrderRepository')) {
|
||||
$order = \AKSRT\Payment\OrderRepository::get_instance()->get($order_number);
|
||||
$status = is_array($order) ? (string) ($order['status'] ?? '') : '';
|
||||
// Only allow hard-delete of closed/expired rows (safety).
|
||||
if (in_array($status, ['cancelled', 'expired'], true)) {
|
||||
// Only allow hard-delete of closed rows (safety).
|
||||
if ($status === 'closed') {
|
||||
$ok = \AKSRT\Payment\OrderRepository::get_instance()->delete_order($order_number);
|
||||
}
|
||||
}
|
||||
@@ -423,23 +395,18 @@ class PayOrders {
|
||||
}
|
||||
|
||||
private function render_order_quick_status_buttons(string $order_number, string $current_status, bool $redirect_detail = false): void {
|
||||
$actions = [
|
||||
'completed' => __('完成', 'aksrt'),
|
||||
'refunded' => __('退款', 'aksrt'),
|
||||
'cancelled' => __('关闭', 'aksrt'),
|
||||
$labels = [
|
||||
'paid' => __('确认收款', 'aksrt'),
|
||||
'refunding' => __('发起退款', 'aksrt'),
|
||||
'refunded' => __('确认退款', 'aksrt'),
|
||||
'closed' => __('关闭订单', 'aksrt'),
|
||||
];
|
||||
foreach ($actions as $status => $label) {
|
||||
if ($status === $current_status) {
|
||||
continue;
|
||||
}
|
||||
$confirm = '';
|
||||
if ($status === 'refunded') {
|
||||
$confirm = __('确认将该订单标记为已退款?', 'aksrt');
|
||||
} elseif ($status === 'cancelled') {
|
||||
$confirm = __('确认关闭该订单?', 'aksrt');
|
||||
} elseif ($status === 'completed') {
|
||||
$confirm = __('确认完成该订单?', 'aksrt');
|
||||
}
|
||||
$transitions = \AKSRT\Core\DomainModel::order_transitions();
|
||||
foreach ((array) ($transitions[$current_status] ?? []) as $status) {
|
||||
$label = $status === 'paid' && $current_status === 'refunding'
|
||||
? __('取消退款', 'aksrt')
|
||||
: ($labels[$status] ?? $status);
|
||||
$confirm = sprintf(__('确认将订单状态改为“%s”?', 'aksrt'), $label);
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:inline;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_update_order_status" />';
|
||||
echo '<input type="hidden" name="order_number" value="' . esc_attr($order_number) . '" />';
|
||||
@@ -500,7 +467,7 @@ class PayOrders {
|
||||
),
|
||||
'orders_clear_empty' => __('没有可清理的关闭订单。', 'aksrt'),
|
||||
'order_deleted' => __('订单已删除。', 'aksrt'),
|
||||
'order_delete_failed' => __('订单删除失败(仅允许删除已关闭/过期订单)。', 'aksrt'),
|
||||
'order_delete_failed' => __('订单删除失败(仅允许删除已关闭订单)。', 'aksrt'),
|
||||
'shipping_updated' => __('物流状态已更新。', 'aksrt'),
|
||||
'shipping_failed' => __('物流状态更新失败。', 'aksrt'),
|
||||
'shipping_created' => __('发货记录已创建。', 'aksrt'),
|
||||
|
||||
Reference in New Issue
Block a user