374 lines
13 KiB
PHP
374 lines
13 KiB
PHP
<?php
|
||
/**
|
||
* 我的账户 - 订阅管理模板
|
||
*
|
||
* 显示用户的所有订阅
|
||
*/
|
||
|
||
if (!defined('ABSPATH')) {
|
||
exit;
|
||
}
|
||
|
||
$customer_id = get_current_user_id();
|
||
|
||
if (!$customer_id) {
|
||
return;
|
||
}
|
||
|
||
// 获取用户订阅
|
||
global $wpdb;
|
||
$subscriptions = $wpdb->get_results($wpdb->prepare("
|
||
SELECT * FROM {$wpdb->prefix}yoone_subscriptions
|
||
WHERE customer_id = %d
|
||
ORDER BY created_at DESC
|
||
", $customer_id));
|
||
|
||
?>
|
||
|
||
<div class="yoone-my-subscriptions">
|
||
<h2><?php _e('我的订阅', 'yoone-subscriptions'); ?></h2>
|
||
|
||
<?php if (empty($subscriptions)): ?>
|
||
<div class="no-subscriptions">
|
||
<p><?php _e('您还没有任何订阅。', 'yoone-subscriptions'); ?></p>
|
||
<a href="<?php echo esc_url(wc_get_page_permalink('shop')); ?>" class="button">
|
||
<?php _e('开始购物', 'yoone-subscriptions'); ?>
|
||
</a>
|
||
</div>
|
||
<?php else: ?>
|
||
<div class="subscriptions-list">
|
||
<?php foreach ($subscriptions as $subscription): ?>
|
||
<?php
|
||
$subscription_obj = new Yoone_Subscription($subscription->id);
|
||
$subscription_items = $subscription_obj->get_items();
|
||
$next_payment = $subscription_obj->get_next_payment_date();
|
||
?>
|
||
|
||
<div class="subscription-item" data-subscription-id="<?php echo esc_attr($subscription->id); ?>">
|
||
<div class="subscription-header">
|
||
<div class="subscription-id">
|
||
<h3><?php printf(__('订阅 #%d', 'yoone-subscriptions'), $subscription->id); ?></h3>
|
||
<span class="subscription-status status-<?php echo esc_attr($subscription->status); ?>">
|
||
<?php echo esc_html($this->get_status_label($subscription->status)); ?>
|
||
</span>
|
||
</div>
|
||
|
||
<div class="subscription-actions">
|
||
<?php if ($subscription->status === 'active'): ?>
|
||
<a href="<?php echo esc_url($this->get_subscription_action_url($subscription->id, 'pause')); ?>"
|
||
class="button subscription-pause">
|
||
<?php _e('暂停', 'yoone-subscriptions'); ?>
|
||
</a>
|
||
<?php elseif ($subscription->status === 'paused'): ?>
|
||
<a href="<?php echo esc_url($this->get_subscription_action_url($subscription->id, 'resume')); ?>"
|
||
class="button subscription-resume">
|
||
<?php _e('恢复', 'yoone-subscriptions'); ?>
|
||
</a>
|
||
<?php endif; ?>
|
||
|
||
<?php if (in_array($subscription->status, array('active', 'paused'))): ?>
|
||
<a href="<?php echo esc_url($this->get_subscription_action_url($subscription->id, 'cancel')); ?>"
|
||
class="button subscription-cancel"
|
||
onclick="return confirm('<?php _e('确定要取消这个订阅吗?', 'yoone-subscriptions'); ?>')">
|
||
<?php _e('取消', 'yoone-subscriptions'); ?>
|
||
</a>
|
||
<?php endif; ?>
|
||
|
||
<a href="<?php echo esc_url($this->get_subscription_details_url($subscription->id)); ?>"
|
||
class="button subscription-details">
|
||
<?php _e('查看详情', 'yoone-subscriptions'); ?>
|
||
</a>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="subscription-info">
|
||
<div class="subscription-products">
|
||
<h4><?php _e('订阅产品', 'yoone-subscriptions'); ?></h4>
|
||
<?php if (!empty($subscription_items)): ?>
|
||
<ul class="subscription-items">
|
||
<?php foreach ($subscription_items as $item): ?>
|
||
<?php
|
||
$product = wc_get_product($item['product_id']);
|
||
if (!$product) continue;
|
||
?>
|
||
<li class="subscription-item-row">
|
||
<div class="item-image">
|
||
<?php echo $product->get_image('thumbnail'); ?>
|
||
</div>
|
||
<div class="item-details">
|
||
<span class="item-name"><?php echo esc_html($product->get_name()); ?></span>
|
||
<span class="item-quantity">× <?php echo esc_html($item['quantity']); ?></span>
|
||
<span class="item-price"><?php echo wc_price($item['price']); ?></span>
|
||
</div>
|
||
</li>
|
||
<?php endforeach; ?>
|
||
</ul>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="subscription-details-info">
|
||
<div class="detail-row">
|
||
<span class="detail-label"><?php _e('订阅金额:', 'yoone-subscriptions'); ?></span>
|
||
<span class="detail-value"><?php echo wc_price($subscription->total); ?></span>
|
||
</div>
|
||
|
||
<div class="detail-row">
|
||
<span class="detail-label"><?php _e('计费周期:', 'yoone-subscriptions'); ?></span>
|
||
<span class="detail-value">
|
||
<?php echo esc_html($this->format_billing_period($subscription->billing_period, $subscription->billing_interval)); ?>
|
||
</span>
|
||
</div>
|
||
|
||
<?php if ($subscription->status === 'active' && $next_payment): ?>
|
||
<div class="detail-row">
|
||
<span class="detail-label"><?php _e('下次付款:', 'yoone-subscriptions'); ?></span>
|
||
<span class="detail-value">
|
||
<?php echo date_i18n(get_option('date_format'), strtotime($next_payment)); ?>
|
||
</span>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="detail-row">
|
||
<span class="detail-label"><?php _e('创建日期:', 'yoone-subscriptions'); ?></span>
|
||
<span class="detail-value">
|
||
<?php echo date_i18n(get_option('date_format'), strtotime($subscription->created_at)); ?>
|
||
</span>
|
||
</div>
|
||
|
||
<?php if ($subscription->payment_method): ?>
|
||
<div class="detail-row">
|
||
<span class="detail-label"><?php _e('支付方式:', 'yoone-subscriptions'); ?></span>
|
||
<span class="detail-value">
|
||
<?php echo esc_html($this->get_payment_method_title($subscription->payment_method)); ?>
|
||
</span>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
|
||
<?php if ($subscription->status === 'active'): ?>
|
||
<div class="subscription-management">
|
||
<h4><?php _e('订阅管理', 'yoone-subscriptions'); ?></h4>
|
||
|
||
<div class="management-actions">
|
||
<a href="<?php echo esc_url($this->get_subscription_action_url($subscription->id, 'change_payment')); ?>"
|
||
class="button change-payment">
|
||
<?php _e('更改支付方式', 'yoone-subscriptions'); ?>
|
||
</a>
|
||
|
||
<a href="<?php echo esc_url($this->get_subscription_action_url($subscription->id, 'change_address')); ?>"
|
||
class="button change-address">
|
||
<?php _e('更改配送地址', 'yoone-subscriptions'); ?>
|
||
</a>
|
||
|
||
<a href="<?php echo esc_url($this->get_subscription_action_url($subscription->id, 'skip_next')); ?>"
|
||
class="button skip-delivery">
|
||
<?php _e('跳过下次配送', 'yoone-subscriptions'); ?>
|
||
</a>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
|
||
<div class="subscriptions-pagination">
|
||
<?php
|
||
// 这里可以添加分页逻辑
|
||
?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<style>
|
||
.yoone-my-subscriptions {
|
||
margin: 20px 0;
|
||
}
|
||
|
||
.no-subscriptions {
|
||
text-align: center;
|
||
padding: 40px 20px;
|
||
background: #f9f9f9;
|
||
border-radius: 5px;
|
||
}
|
||
|
||
.subscription-item {
|
||
margin-bottom: 30px;
|
||
padding: 20px;
|
||
border: 1px solid #ddd;
|
||
border-radius: 5px;
|
||
background: white;
|
||
}
|
||
|
||
.subscription-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 20px;
|
||
padding-bottom: 15px;
|
||
border-bottom: 1px solid #eee;
|
||
}
|
||
|
||
.subscription-id h3 {
|
||
margin: 0 0 5px 0;
|
||
font-size: 18px;
|
||
}
|
||
|
||
.subscription-status {
|
||
padding: 3px 8px;
|
||
border-radius: 3px;
|
||
font-size: 12px;
|
||
font-weight: bold;
|
||
text-transform: uppercase;
|
||
}
|
||
|
||
.subscription-status.status-active {
|
||
background: #4caf50;
|
||
color: white;
|
||
}
|
||
|
||
.subscription-status.status-paused {
|
||
background: #ff9800;
|
||
color: white;
|
||
}
|
||
|
||
.subscription-status.status-cancelled {
|
||
background: #f44336;
|
||
color: white;
|
||
}
|
||
|
||
.subscription-status.status-expired {
|
||
background: #9e9e9e;
|
||
color: white;
|
||
}
|
||
|
||
.subscription-actions {
|
||
display: flex;
|
||
gap: 10px;
|
||
}
|
||
|
||
.subscription-actions .button {
|
||
padding: 5px 10px;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.subscription-info {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 20px;
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.subscription-products h4,
|
||
.subscription-details-info h4 {
|
||
margin: 0 0 15px 0;
|
||
font-size: 14px;
|
||
color: #666;
|
||
text-transform: uppercase;
|
||
}
|
||
|
||
.subscription-items {
|
||
list-style: none;
|
||
padding: 0;
|
||
margin: 0;
|
||
}
|
||
|
||
.subscription-item-row {
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 10px 0;
|
||
border-bottom: 1px solid #f0f0f0;
|
||
}
|
||
|
||
.subscription-item-row:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.subscription-item-row .item-image {
|
||
flex: 0 0 50px;
|
||
margin-right: 10px;
|
||
}
|
||
|
||
.subscription-item-row .item-details {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.subscription-item-row .item-name {
|
||
font-weight: bold;
|
||
margin-bottom: 3px;
|
||
}
|
||
|
||
.subscription-item-row .item-quantity,
|
||
.subscription-item-row .item-price {
|
||
font-size: 12px;
|
||
color: #666;
|
||
}
|
||
|
||
.detail-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
margin-bottom: 10px;
|
||
padding: 5px 0;
|
||
}
|
||
|
||
.detail-label {
|
||
font-weight: bold;
|
||
color: #333;
|
||
}
|
||
|
||
.detail-value {
|
||
color: #666;
|
||
}
|
||
|
||
.subscription-management {
|
||
padding-top: 15px;
|
||
border-top: 1px solid #eee;
|
||
}
|
||
|
||
.subscription-management h4 {
|
||
margin: 0 0 15px 0;
|
||
font-size: 14px;
|
||
color: #666;
|
||
text-transform: uppercase;
|
||
}
|
||
|
||
.management-actions {
|
||
display: flex;
|
||
gap: 10px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.management-actions .button {
|
||
padding: 8px 15px;
|
||
font-size: 12px;
|
||
}
|
||
|
||
@media (max-width: 768px) {
|
||
.subscription-header {
|
||
flex-direction: column;
|
||
align-items: flex-start;
|
||
gap: 15px;
|
||
}
|
||
|
||
.subscription-actions {
|
||
width: 100%;
|
||
justify-content: flex-start;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.subscription-info {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
|
||
.management-actions {
|
||
flex-direction: column;
|
||
}
|
||
|
||
.management-actions .button {
|
||
width: 100%;
|
||
text-align: center;
|
||
}
|
||
}
|
||
</style>
|