254 lines
14 KiB
PHP
254 lines
14 KiB
PHP
<?php
|
||
/**
|
||
* Template Name: AKSRT - Orders
|
||
* Template Post Type: page
|
||
*
|
||
* Enhanced: 5 tabs, logistics timeline, receipt confirm,
|
||
* review button, re-purchase, gift/discount details (§6.10).
|
||
*
|
||
* @package AKSRT
|
||
*/
|
||
|
||
defined('ABSPATH') || exit;
|
||
|
||
get_header();
|
||
|
||
if (!is_user_logged_in()) {
|
||
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
|
||
wp_safe_redirect($login_url);
|
||
exit;
|
||
}
|
||
|
||
$user_id = get_current_user_id();
|
||
$per_page = 20;
|
||
$paged = max(1, (int) ($_GET['order_page'] ?? 1));
|
||
$tab = sanitize_key((string) ($_GET['tab'] ?? ''));
|
||
$status = sanitize_key((string) ($_GET['order_status'] ?? ''));
|
||
|
||
$tab_status_map = [
|
||
'pending' => AKSRT_Order::STATUS_PENDING,
|
||
'shipped' => AKSRT_Order::STATUS_DELIVERED,
|
||
'received' => AKSRT_Order::STATUS_COMPLETED,
|
||
'review' => AKSRT_Order::STATUS_PENDING_REVIEW,
|
||
'after' => AKSRT_Order::STATUS_REFUNDING,
|
||
];
|
||
if ($tab !== '' && isset($tab_status_map[$tab])) {
|
||
$status = $tab_status_map[$tab];
|
||
}
|
||
|
||
$orders_view = function_exists('aksrt_get_orders_page_view')
|
||
? aksrt_get_orders_page_view($user_id, $paged, $per_page, $status)
|
||
: ['items' => [], 'total' => 0, 'total_pages' => 1, 'page' => 1];
|
||
|
||
$orders = (array) ($orders_view['items'] ?? []);
|
||
$total_pages = max(1, (int) ($orders_view['total_pages'] ?? 1));
|
||
|
||
$shop = class_exists('AKSRT_Shop') ? AKSRT_Shop::get_instance() : null;
|
||
$shipping = class_exists('AKSRT_Shipping') ? AKSRT_Shipping::get_instance() : null;
|
||
|
||
$tabs = [
|
||
'' => __('全部', 'aksrt'),
|
||
'pending' => __('待支付', 'aksrt'),
|
||
'shipped' => __('待收货', 'aksrt'),
|
||
'review' => __('待评价', 'aksrt'),
|
||
'after' => __('售后', 'aksrt'),
|
||
];
|
||
?>
|
||
|
||
<main id="main-content" class="site-main content-shell" tabindex="-1">
|
||
<div class="container aksrt-orders-page" data-aksrt-order-center>
|
||
<div class="aksrt-orders-page__header">
|
||
<h1><?php esc_html_e('我的订单', 'aksrt'); ?></h1>
|
||
</div>
|
||
|
||
<!-- 5-tab navigation -->
|
||
<div class="aksrt-orders-page__tabs">
|
||
<?php foreach ($tabs as $tab_key => $tab_label) :
|
||
$is_active = $tab === $tab_key;
|
||
$tab_url = $tab_key !== '' ? add_query_arg(['tab' => $tab_key, 'order_page' => 1]) : remove_query_arg(['tab', 'order_status', 'order_page']);
|
||
?>
|
||
<a href="<?php echo esc_url($tab_url); ?>" class="aksrt-orders-page__tab<?php echo $is_active ? ' is-active' : ''; ?>">
|
||
<?php echo esc_html($tab_label); ?>
|
||
</a>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
|
||
<?php if (!empty($orders)) : ?>
|
||
<div class="aksrt-orders-page__list">
|
||
<?php foreach ($orders as $order) :
|
||
$on = (string) ($order['order_number'] ?? '');
|
||
$os = (string) ($order['status'] ?? '');
|
||
$items = $order['items'] ?? [];
|
||
?>
|
||
<article class="aksrt-orders-page__card" data-aksrt-order-card="<?php echo esc_attr($on); ?>">
|
||
<!-- Card header -->
|
||
<div class="aksrt-orders-page__card-head">
|
||
<span class="aksrt-orders-page__card-number"><?php echo esc_html($on); ?></span>
|
||
<time class="aksrt-orders-page__card-time"><?php echo esc_html((string) ($order['created_at'] ?? '')); ?></time>
|
||
<span class="aksrt-orders-page__card-status"><?php echo esc_html((string) ($order['status_label'] ?? '')); ?></span>
|
||
</div>
|
||
|
||
<!-- Order items -->
|
||
<div class="aksrt-orders-page__card-items">
|
||
<?php if (!empty($items)) : ?>
|
||
<?php foreach ($items as $item) : ?>
|
||
<div class="aksrt-orders-page__card-item">
|
||
<?php if (!empty($item['image'])) : ?>
|
||
<img src="<?php echo esc_url((string) $item['image']); ?>" alt="" class="aksrt-orders-page__card-img">
|
||
<?php endif; ?>
|
||
<div class="aksrt-orders-page__card-item-info">
|
||
<span class="aksrt-orders-page__card-item-title"><?php echo esc_html((string) ($item['product_title'] ?? '')); ?></span>
|
||
<?php if (!empty($item['options_label'])) : ?>
|
||
<small class="aksrt-orders-page__card-item-opts"><?php echo esc_html((string) $item['options_label']); ?></small>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="aksrt-orders-page__card-item-price">
|
||
<strong>¥<?php echo esc_html(number_format((float) ($item['pay_price'] ?? $item['unit_price'] ?? 0), 2)); ?></strong>
|
||
<span>×<?php echo esc_html((string) ($item['quantity'] ?? 1)); ?></span>
|
||
</div>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
<?php else : ?>
|
||
<div class="aksrt-orders-page__card-item">
|
||
<span class="aksrt-orders-page__card-item-title"><?php echo esc_html((string) ($order['product_name'] ?? __('商品订单', 'aksrt'))); ?></span>
|
||
<strong>¥<?php echo esc_html(number_format((float) ($order['amount'] ?? 0), 2)); ?></strong>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<!-- Price summary -->
|
||
<div class="aksrt-orders-page__card-summary">
|
||
<span><?php esc_html_e('合计', 'aksrt'); ?></span>
|
||
<strong>¥<?php echo esc_html(number_format((float) ($order['amount'] ?? 0), 2)); ?></strong>
|
||
<?php if ((float) ($order['discount'] ?? 0) > 0) : ?>
|
||
<small>(<?php printf(esc_html__('已优惠 ¥%s', 'aksrt'), number_format((float) $order['discount'], 2)); ?>)</small>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<!-- Logistics timeline (collapsed) -->
|
||
<?php if (!empty($order['shipping_records'])) : ?>
|
||
<div class="aksrt-orders-page__timeline" data-aksrt-timeline>
|
||
<h4 class="aksrt-orders-page__timeline-toggle" data-aksrt-toggle-timeline>
|
||
<i class="fas fa-truck"></i> <?php esc_html_e('物流信息', 'aksrt'); ?> <i class="fas fa-chevron-down"></i>
|
||
</h4>
|
||
<div class="aksrt-orders-page__timeline-body" hidden>
|
||
<?php foreach ((array) ($order['timeline'] ?? []) as $tl) : ?>
|
||
<div class="aksrt-orders-page__timeline-item">
|
||
<time><?php echo esc_html((string) ($tl['time'] ?? '')); ?></time>
|
||
<span><?php echo esc_html((string) ($tl['label'] ?? '')); ?></span>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<!-- Actions -->
|
||
<div class="aksrt-orders-page__card-actions">
|
||
<?php if (!empty($order['actions']['can_pay'])) : ?>
|
||
<button type="button" class="btn-primary btn-sm" data-aksrt-order-pay="<?php echo esc_attr($on); ?>"><?php esc_html_e('去支付', 'aksrt'); ?></button>
|
||
<?php endif; ?>
|
||
<?php if (!empty($order['actions']['can_receipt'])) : ?>
|
||
<button type="button" class="btn-primary btn-sm" data-aksrt-order-receipt="<?php echo esc_attr($on); ?>"><?php esc_html_e('确认收货', 'aksrt'); ?></button>
|
||
<?php endif; ?>
|
||
<?php if ($os === AKSRT_Order::STATUS_PENDING_REVIEW) : ?>
|
||
<button type="button" class="btn-primary btn-sm" data-aksrt-order-review="<?php echo esc_attr($on); ?>"><?php esc_html_e('去评价', 'aksrt'); ?></button>
|
||
<?php endif; ?>
|
||
<?php if (!empty($order['actions']['can_cancel'])) : ?>
|
||
<button type="button" class="btn-ghost btn-sm" data-aksrt-order-cancel="<?php echo esc_attr($on); ?>"><?php esc_html_e('取消', 'aksrt'); ?></button>
|
||
<?php endif; ?>
|
||
<?php if (in_array($os, [AKSRT_Order::STATUS_COMPLETED, AKSRT_Order::STATUS_PENDING_REVIEW], true)) : ?>
|
||
<button type="button" class="btn-outline btn-sm" data-aksrt-order-rebuy="<?php echo esc_attr($on); ?>"><?php esc_html_e('再次购买', 'aksrt'); ?></button>
|
||
<?php endif; ?>
|
||
<?php if (!empty($order['actions']['can_after_sale'])) : ?>
|
||
<button type="button" class="btn-outline btn-sm" data-aksrt-order-after-sale="<?php echo esc_attr($on); ?>"><?php esc_html_e('售后', 'aksrt'); ?></button>
|
||
<?php endif; ?>
|
||
<?php if (!empty($order['time_left'])) : ?>
|
||
<span class="aksrt-orders-page__countdown" data-aksrt-order-countdown="<?php echo esc_attr((string) $order['time_left']); ?>">
|
||
<?php printf(esc_html__('%d秒后关闭', 'aksrt'), (int) $order['time_left']); ?>
|
||
</span>
|
||
<?php endif; ?>
|
||
</div>
|
||
</article>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
|
||
<?php if ($total_pages > 1) : ?>
|
||
<div class="aksrt-orders-page__pagination">
|
||
<?php for ($i = 1; $i <= $total_pages; $i++) :
|
||
$page_url = add_query_arg(['order_page' => $i]);
|
||
?>
|
||
<?php if ($i === $paged) : ?>
|
||
<span class="aksrt-orders-page__page-chip is-active"><?php echo esc_html((string) $i); ?></span>
|
||
<?php else : ?>
|
||
<a href="<?php echo esc_url($page_url); ?>" class="aksrt-orders-page__page-chip"><?php echo esc_html((string) $i); ?></a>
|
||
<?php endif; ?>
|
||
<?php endfor; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php else : ?>
|
||
<div class="aksrt-orders-page__empty">
|
||
<i class="fas fa-receipt" aria-hidden="true"></i>
|
||
<p><?php esc_html_e('暂无订单记录。', 'aksrt'); ?></p>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<!-- After-sale modal -->
|
||
<div class="aksrt-modal" data-aksrt-aftersale-modal hidden>
|
||
<div class="aksrt-modal__overlay"></div>
|
||
<div class="aksrt-modal__dialog">
|
||
<div class="aksrt-modal__header">
|
||
<h3><?php esc_html_e('申请售后', 'aksrt'); ?></h3>
|
||
<button type="button" class="aksrt-modal__close" data-aksrt-aftersale-modal-close>×</button>
|
||
</div>
|
||
<form class="aksrt-modal__body" data-aksrt-aftersale-form>
|
||
<input type="hidden" name="order_number" value="">
|
||
<div class="aksrt-orders-page__field">
|
||
<label><?php esc_html_e('售后类型', 'aksrt'); ?></label>
|
||
<select name="type" class="aksrt-orders-page__select">
|
||
<?php foreach (AKSRT_After_Sale::get_valid_types() as $type_key => $type_label) : ?>
|
||
<option value="<?php echo esc_attr($type_key); ?>"><?php echo esc_html($type_label); ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div class="aksrt-orders-page__field">
|
||
<label><?php esc_html_e('售后原因', 'aksrt'); ?> *</label>
|
||
<textarea name="reason" class="aksrt-orders-page__textarea" rows="4" required placeholder="<?php esc_attr_e('请描述问题', 'aksrt'); ?>"></textarea>
|
||
</div>
|
||
<div class="aksrt-modal__footer">
|
||
<button type="button" class="btn-ghost" data-aksrt-aftersale-modal-close><?php esc_html_e('取消', 'aksrt'); ?></button>
|
||
<button type="submit" class="btn-primary"><?php esc_html_e('提交', 'aksrt'); ?></button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Favorites section -->
|
||
<?php
|
||
$fav_tab = sanitize_key((string) ($_GET['section'] ?? ''));
|
||
if ($fav_tab === 'favorites' && $shop) :
|
||
$fav_data = $shop->get_user_favorites($user_id);
|
||
?>
|
||
<section class="aksrt-orders-page__favorites">
|
||
<h2><?php esc_html_e('收藏商品', 'aksrt'); ?></h2>
|
||
<?php if (!empty($fav_data['items'])) : ?>
|
||
<div class="aksrt-orders-page__fav-grid">
|
||
<?php foreach ($fav_data['items'] as $fav) : ?>
|
||
<a href="<?php echo esc_url((string) ($fav['permalink'] ?? '#')); ?>" class="aksrt-orders-page__fav-card">
|
||
<?php if (!empty($fav['image'])) : ?>
|
||
<img src="<?php echo esc_url((string) $fav['image']); ?>" alt="" loading="lazy">
|
||
<?php endif; ?>
|
||
<h3><?php echo esc_html((string) ($fav['title'] ?? '')); ?></h3>
|
||
<strong>¥<?php echo esc_html(number_format((float) ($fav['price'] ?? 0), 2)); ?></strong>
|
||
</a>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php else : ?>
|
||
<p><?php esc_html_e('暂无收藏商品', 'aksrt'); ?></p>
|
||
<?php endif; ?>
|
||
</section>
|
||
<?php endif; ?>
|
||
</div>
|
||
</main>
|
||
|
||
<?php get_footer(); ?>
|