229 lines
11 KiB
PHP
229 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* 订阅编辑页面模板
|
|
*
|
|
* @package Yoone_Subscriptions
|
|
* @version 1.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit; // 防止直接访问
|
|
}
|
|
|
|
// $subscription 变量由调用文件传入
|
|
?>
|
|
|
|
<div class="wrap">
|
|
<h1><?php printf(__('编辑订阅 #%d', 'yoone-subscriptions'), $subscription->id); ?></h1>
|
|
|
|
<form method="post" action="">
|
|
<?php wp_nonce_field('edit_subscription_' . $subscription->id); ?>
|
|
|
|
<table class="form-table">
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="subscription_id"><?php _e('订阅ID', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" id="subscription_id" value="<?php echo esc_attr($subscription->id); ?>" readonly class="regular-text" />
|
|
<p class="description"><?php _e('订阅的唯一标识符', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="user_id"><?php _e('用户', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<?php
|
|
$user = get_user_by('id', $subscription->user_id);
|
|
if ($user) {
|
|
echo '<a href="' . admin_url('user-edit.php?user_id=' . $user->ID) . '">';
|
|
echo esc_html($user->display_name . ' (' . $user->user_email . ')');
|
|
echo '</a>';
|
|
} else {
|
|
_e('用户不存在', 'yoone-subscriptions');
|
|
}
|
|
?>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="product_id"><?php _e('产品', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<?php
|
|
$product = wc_get_product($subscription->product_id);
|
|
if ($product) {
|
|
echo '<a href="' . admin_url('post.php?post=' . $product->get_id() . '&action=edit') . '">';
|
|
echo esc_html($product->get_name());
|
|
echo '</a>';
|
|
} else {
|
|
_e('产品不存在', 'yoone-subscriptions');
|
|
}
|
|
?>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="status"><?php _e('状态', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<select name="status" id="status" class="regular-text">
|
|
<option value="active" <?php selected($subscription->status, 'active'); ?>><?php _e('活跃', 'yoone-subscriptions'); ?></option>
|
|
<option value="paused" <?php selected($subscription->status, 'paused'); ?>><?php _e('暂停', 'yoone-subscriptions'); ?></option>
|
|
<option value="cancelled" <?php selected($subscription->status, 'cancelled'); ?>><?php _e('已取消', 'yoone-subscriptions'); ?></option>
|
|
<option value="expired" <?php selected($subscription->status, 'expired'); ?>><?php _e('已过期', 'yoone-subscriptions'); ?></option>
|
|
</select>
|
|
<p class="description"><?php _e('订阅的当前状态', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="billing_period"><?php _e('计费周期', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" value="<?php echo Yoone_Helper::format_billing_period($subscription->billing_period, $subscription->billing_interval); ?>" readonly class="regular-text" />
|
|
<p class="description"><?php _e('订阅的计费周期(只读)', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="subscription_price"><?php _e('订阅价格', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" value="<?php echo Yoone_Helper::format_price($subscription->subscription_price); ?>" readonly class="regular-text" />
|
|
<p class="description"><?php _e('每个计费周期的价格(只读)', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="start_date"><?php _e('开始日期', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" value="<?php echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($subscription->start_date)); ?>" readonly class="regular-text" />
|
|
<p class="description"><?php _e('订阅开始的日期(只读)', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="next_payment_date"><?php _e('下次付款日期', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="date" name="next_payment_date" id="next_payment_date"
|
|
value="<?php echo $subscription->next_payment_date ? date('Y-m-d', strtotime($subscription->next_payment_date)) : ''; ?>"
|
|
class="regular-text" />
|
|
<p class="description"><?php _e('下次自动付款的日期', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="end_date"><?php _e('结束日期', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" value="<?php echo $subscription->end_date ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($subscription->end_date)) : __('无', 'yoone-subscriptions'); ?>" readonly class="regular-text" />
|
|
<p class="description"><?php _e('订阅结束的日期(只读)', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="trial_end_date"><?php _e('试用结束日期', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" value="<?php echo $subscription->trial_end_date ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($subscription->trial_end_date)) : __('无试用期', 'yoone-subscriptions'); ?>" readonly class="regular-text" />
|
|
<p class="description"><?php _e('免费试用期结束的日期(只读)', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="created_at"><?php _e('创建时间', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" value="<?php echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($subscription->created_at)); ?>" readonly class="regular-text" />
|
|
<p class="description"><?php _e('订阅创建的时间(只读)', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="updated_at"><?php _e('更新时间', 'yoone-subscriptions'); ?></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" value="<?php echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($subscription->updated_at)); ?>" readonly class="regular-text" />
|
|
<p class="description"><?php _e('订阅最后更新的时间(只读)', 'yoone-subscriptions'); ?></p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?php submit_button(__('更新订阅', 'yoone-subscriptions')); ?>
|
|
</form>
|
|
|
|
<!-- 订阅历史记录 -->
|
|
<h2><?php _e('订阅历史', 'yoone-subscriptions'); ?></h2>
|
|
|
|
<?php
|
|
global $wpdb;
|
|
|
|
// 获取相关订单
|
|
$orders = $wpdb->get_results($wpdb->prepare(
|
|
"SELECT p.ID, p.post_date, pm.meta_value as order_total, pm2.meta_value as order_status
|
|
FROM {$wpdb->posts} p
|
|
LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id AND pm.meta_key = '_order_total'
|
|
LEFT JOIN {$wpdb->postmeta} pm2 ON p.ID = pm2.post_id AND pm2.meta_key = '_order_status'
|
|
LEFT JOIN {$wpdb->postmeta} pm3 ON p.ID = pm3.post_id AND pm3.meta_key = '_yoone_subscription_id'
|
|
WHERE p.post_type = 'shop_order' AND pm3.meta_value = %d
|
|
ORDER BY p.post_date DESC",
|
|
$subscription->id
|
|
));
|
|
?>
|
|
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<thead>
|
|
<tr>
|
|
<th><?php _e('订单ID', 'yoone-subscriptions'); ?></th>
|
|
<th><?php _e('日期', 'yoone-subscriptions'); ?></th>
|
|
<th><?php _e('金额', 'yoone-subscriptions'); ?></th>
|
|
<th><?php _e('状态', 'yoone-subscriptions'); ?></th>
|
|
<th><?php _e('操作', 'yoone-subscriptions'); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($orders)): ?>
|
|
<tr>
|
|
<td colspan="5"><?php _e('暂无相关订单', 'yoone-subscriptions'); ?></td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($orders as $order): ?>
|
|
<tr>
|
|
<td>#<?php echo $order->ID; ?></td>
|
|
<td><?php echo date_i18n(get_option('date_format'), strtotime($order->post_date)); ?></td>
|
|
<td><?php echo Yoone_Helper::format_price($order->order_total); ?></td>
|
|
<td><?php echo esc_html($order->order_status); ?></td>
|
|
<td>
|
|
<a href="<?php echo admin_url('post.php?post=' . $order->ID . '&action=edit'); ?>" class="button button-small">
|
|
<?php _e('查看', 'yoone-subscriptions'); ?>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<p>
|
|
<a href="<?php echo admin_url('admin.php?page=yoone-subscriptions'); ?>" class="button">
|
|
<?php _e('返回订阅列表', 'yoone-subscriptions'); ?>
|
|
</a>
|
|
</p>
|
|
</div>
|