进行了一些小优化
This commit is contained in:
@@ -82,7 +82,6 @@
|
||||
.aksrt-orders-page__card-value span { color: var(--orders-muted); font-size: 11px; }
|
||||
.aksrt-orders-page__card-actions { display: flex; gap: 7px; align-items: center; justify-content: flex-end; padding: 9px 14px; border-top: 1px solid var(--orders-line); }
|
||||
.aksrt-orders-page__countdown { margin-right: auto; color: var(--color-warning, #c87819); font-size: 11px; font-variant-numeric: tabular-nums; }
|
||||
.aksrt-orders-page__card-actions .is-entitlement { background: var(--color-success, #168560); }
|
||||
|
||||
.aksrt-orders-page__pagination { display: flex; justify-content: center; gap: 6px; margin-top: 20px; }
|
||||
.aksrt-orders-page__page-chip { display: grid; width: 31px; height: 31px; place-items: center; border: 1px solid var(--orders-line); border-radius: 8px; color: var(--orders-muted); font-size: 12px; text-decoration: none; }
|
||||
|
||||
@@ -98,7 +98,6 @@
|
||||
html += '<button class="btn-outline" type="button" data-aksrt-modal-close>关闭</button>';
|
||||
if (allowedActions.can_cancel) html += '<button class="btn-ghost" type="button" data-aksrt-order-cancel="' + escapeHtml(order.order_number) + '">关闭订单</button>';
|
||||
if (allowedActions.can_pay) html += '<button class="btn-primary" type="button" data-aksrt-order-pay="' + escapeHtml(order.order_number) + '" data-aksrt-order-method="' + escapeHtml((order.payment_method || {}).value || "") + '">继续支付</button>';
|
||||
if (allowedActions.can_open && order.permalink) html += '<a class="btn-primary" href="' + escapeHtml(order.permalink) + '">' + escapeHtml(order.entitlement_label || "打开已购内容") + "</a>";
|
||||
html += "</footer>";
|
||||
session.content.innerHTML = html;
|
||||
}
|
||||
@@ -174,7 +173,6 @@
|
||||
var html = '<button class="btn-outline" type="button" data-aksrt-order-detail="' + escapeHtml(order.order_number) + '">订单详情</button>';
|
||||
if (allowedActions.can_cancel) html += '<button class="btn-ghost" type="button" data-aksrt-order-cancel="' + escapeHtml(order.order_number) + '">关闭订单</button>';
|
||||
if (allowedActions.can_pay) html += '<button class="btn-primary" type="button" data-aksrt-order-pay="' + escapeHtml(order.order_number) + '" data-aksrt-order-method="' + escapeHtml((order.payment_method || {}).value || "") + '">继续支付</button>';
|
||||
if (allowedActions.can_open && order.permalink) html += '<a class="btn-primary is-entitlement" href="' + escapeHtml(order.permalink) + '">' + escapeHtml(order.entitlement_label || "打开已购内容") + "</a>";
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,6 @@ $status_options = [
|
||||
<button class="btn-outline" type="button" data-aksrt-order-detail="<?php echo esc_attr($number); ?>"><?php esc_html_e('订单详情', 'aksrt'); ?></button>
|
||||
<?php if (!empty($actions['can_cancel'])) : ?><button class="btn-ghost" type="button" data-aksrt-order-cancel="<?php echo esc_attr($number); ?>"><?php esc_html_e('关闭订单', 'aksrt'); ?></button><?php endif; ?>
|
||||
<?php if (!empty($actions['can_pay'])) : ?><button class="btn-primary" type="button" data-aksrt-order-pay="<?php echo esc_attr($number); ?>" data-aksrt-order-method="<?php echo esc_attr((string) ($order['payment_method']['value'] ?? '')); ?>"><?php esc_html_e('继续支付', 'aksrt'); ?></button><?php endif; ?>
|
||||
<?php if (!empty($actions['can_open'])) : ?><a class="btn-primary is-entitlement" href="<?php echo esc_url((string) ($order['permalink'] ?? '')); ?>"><?php echo esc_html((string) ($order['entitlement_label'] ?? __('打开已购内容', 'aksrt'))); ?></a><?php endif; ?>
|
||||
</footer>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -21,9 +21,6 @@ class UserOrders {
|
||||
/** @var array<string,string> */
|
||||
private array $post_image_cache = [];
|
||||
|
||||
/** @var array<string,string> */
|
||||
private array $post_permalink_cache = [];
|
||||
|
||||
/** @var array<string,string> */
|
||||
private array $type_labels_cache = [];
|
||||
|
||||
@@ -187,12 +184,10 @@ class UserOrders {
|
||||
$type_label = $this->type_labels_cache[$product_type] ?? __('订单', 'aksrt');
|
||||
$title = $this->resolve_title($meta, $product_type, $product_id, $type_label);
|
||||
$image = $this->resolve_image($meta, $product_id);
|
||||
$permalink = $this->resolve_entitlement_url($product_type, $product_id, $meta);
|
||||
$group = $this->status_group($status);
|
||||
$payment_method = sanitize_key((string) ($order['payment_method'] ?? ''));
|
||||
$can_pay = $group === OrderCenterQuery::STATUS_PENDING && $payment_method !== 'manual_review';
|
||||
$can_cancel = $group === OrderCenterQuery::STATUS_PENDING;
|
||||
$can_open = $group === OrderCenterQuery::STATUS_PAID && $permalink !== '';
|
||||
$order_number = (string) ($order['order_number'] ?? '');
|
||||
$updated_at = $this->resolve_updated_at($order);
|
||||
|
||||
@@ -213,7 +208,6 @@ class UserOrders {
|
||||
'product_id' => $product_id,
|
||||
'product_name' => $title,
|
||||
'image' => $image,
|
||||
'permalink' => $permalink,
|
||||
'created_at' => (string) ($order['created_at'] ?? ''),
|
||||
'payment_method' => [
|
||||
'value' => $payment_method,
|
||||
@@ -222,10 +216,8 @@ class UserOrders {
|
||||
'allowed_actions' => [
|
||||
'can_pay' => $can_pay,
|
||||
'can_cancel' => $can_cancel,
|
||||
'can_open' => $can_open,
|
||||
],
|
||||
'time_left' => $this->get_order_countdown((string) ($order['expires_at'] ?? ''), $status),
|
||||
'entitlement_label' => $this->entitlement_label($product_type),
|
||||
'updated_at' => $updated_at,
|
||||
'status_version' => $this->resolve_status_version($order, $updated_at),
|
||||
'invalidation_tags' => array_values(array_filter([
|
||||
@@ -338,35 +330,6 @@ class UserOrders {
|
||||
return '';
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $meta */
|
||||
private function resolve_entitlement_url(string $type, int $product_id, array $meta): string {
|
||||
$post_id = $product_id ?: (int) ($meta['post_id'] ?? 0);
|
||||
$cache_key = $type . ':' . $post_id;
|
||||
if (array_key_exists($cache_key, $this->post_permalink_cache)) {
|
||||
return $this->post_permalink_cache[$cache_key];
|
||||
}
|
||||
|
||||
if ($type === DomainModel::ORDER_PRODUCT_VIP) {
|
||||
$url = function_exists('aksrt_get_user_center_tab_url') ? aksrt_get_user_center_tab_url('vip') : '';
|
||||
} elseif (in_array($type, [DomainModel::ORDER_PRODUCT_RECHARGE, DomainModel::ORDER_PRODUCT_POINTS], true)) {
|
||||
$url = function_exists('aksrt_get_user_center_tab_url') ? aksrt_get_user_center_tab_url('credits') : '';
|
||||
} else {
|
||||
$url = $post_id > 0 ? get_permalink($post_id) : '';
|
||||
}
|
||||
|
||||
$this->post_permalink_cache[$cache_key] = is_string($url) ? $url : '';
|
||||
return $this->post_permalink_cache[$cache_key];
|
||||
}
|
||||
|
||||
private function entitlement_label(string $type): string {
|
||||
return match ($type) {
|
||||
DomainModel::ORDER_PRODUCT_VIP => __('查看会员权益', 'aksrt'),
|
||||
DomainModel::ORDER_PRODUCT_RECHARGE => __('查看余额', 'aksrt'),
|
||||
DomainModel::ORDER_PRODUCT_POINTS => __('查看积分', 'aksrt'),
|
||||
default => __('打开已购内容', 'aksrt'),
|
||||
};
|
||||
}
|
||||
|
||||
private function payment_method_label(string $method): string {
|
||||
$labels = [
|
||||
'balance' => __('站内余额', 'aksrt'),
|
||||
|
||||
@@ -220,6 +220,7 @@ test('asset purchases share the order center and refresh every wallet surface',
|
||||
CLOSED: [],
|
||||
})
|
||||
assert.match(userOrders, /return isset\(DomainModel::order_status_labels\(\)\[\$status\]\) \? \$status : ''/)
|
||||
assert.doesNotMatch(userOrders, /can_open|entitlement_label|resolve_entitlement_url|post_permalink_cache/)
|
||||
assert.match(repository, /SUM\(CASE WHEN status = %s THEN 1 ELSE 0 END\) AS paid/)
|
||||
assert.doesNotMatch(repository, /\$completed_statuses|\$completed_placeholders/)
|
||||
assert.match(adminRepository, /\$valid_statuses = array_keys\(\\AKSRT\\Core\\DomainModel::order_status_labels\(\)\)/)
|
||||
|
||||
@@ -371,6 +371,9 @@ test('profile routes load versioned leaf styles and keep dialogs hidden initiall
|
||||
assert.match(ordersCss, /\.aksrt-orders-page__status-filters, \.aksrt-orders-page__type-filters/);
|
||||
assert.doesNotMatch(ordersCss, /\.aksrt-orders-page__tabs|\.aksrt-orders-page__tab(?:\s|\.|:|\{)/);
|
||||
assert.match(orderCenterJs, /if \(panel\) panel\.hidden = expanded;/);
|
||||
assert.doesNotMatch(profileOrders, /can_open|entitlement_label|is-entitlement/);
|
||||
assert.doesNotMatch(orderCenterJs, /can_open|entitlement_label|is-entitlement/);
|
||||
assert.doesNotMatch(ordersCss, /is-entitlement/);
|
||||
assert.match(userCenterJs, /name === 'follow' \|\| name === 'orders'/);
|
||||
assert.match(userCenterJs, /\['order_status', 'order_type', 'order_number', 'order_page'\]/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user