feat(admin): express timeline, coupon scope, plate/topic permission fields
Native shipping can query/show express timelines; coupons accept include/exclude/category product_scope; plate meta gains allow_view and add_limit; topic list shows visibility column.
This commit is contained in:
@@ -36,6 +36,7 @@ class AKSRT_Admin_Pay_Menus {
|
||||
add_action('admin_post_aksrt_pay_disable_charge_card', [$this, 'handle_disable_charge_card']);
|
||||
add_action('admin_post_aksrt_pay_batch_charge_cards', [$this, 'handle_batch_charge_cards']);
|
||||
add_action('admin_post_aksrt_pay_update_shipping', [$this, 'handle_update_shipping']);
|
||||
add_action('admin_post_aksrt_pay_query_express', [$this, 'handle_query_express']);
|
||||
add_action('admin_post_aksrt_pay_create_shipping', [$this, 'handle_create_shipping']);
|
||||
add_action('admin_post_aksrt_pay_update_after_sale', [$this, 'handle_update_after_sale']);
|
||||
add_action('admin_post_aksrt_pay_create_after_sale', [$this, 'handle_create_after_sale']);
|
||||
@@ -214,6 +215,8 @@ class AKSRT_Admin_Pay_Menus {
|
||||
'shipping_failed' => __('物流状态更新失败。', 'aksrt'),
|
||||
'shipping_created' => __('发货记录已创建。', 'aksrt'),
|
||||
'shipping_create_failed' => __('发货记录创建失败。', 'aksrt'),
|
||||
'express_ok' => __('物流轨迹已更新。', 'aksrt'),
|
||||
'express_failed' => __('物流轨迹查询失败。', 'aksrt'),
|
||||
'after_sale_updated' => __('售后状态已更新。', 'aksrt'),
|
||||
'after_sale_failed' => __('售后状态更新失败。', 'aksrt'),
|
||||
'after_sale_created' => __('售后工单已创建。', 'aksrt'),
|
||||
@@ -1148,6 +1151,7 @@ class AKSRT_Admin_Pay_Menus {
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ceil(max(1, $total) / $per_page));
|
||||
$row_status_options = $this->shipping_status_options(false);
|
||||
$show_express_id = isset($_GET['express_id']) ? (int) $_GET['express_id'] : 0;
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('订单号', 'aksrt') . '</th><th>' . esc_html__('承运商', 'aksrt') . '</th><th>' . esc_html__('运单号', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
@@ -1166,7 +1170,8 @@ class AKSRT_Admin_Pay_Menus {
|
||||
echo '<td>' . esc_html((string) ($row['tracking_no'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html($row_status_options[$st] ?? $st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td><form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:4px;align-items:center;">';
|
||||
echo '<td style="display:flex;gap:6px;flex-wrap:wrap;align-items:center;">';
|
||||
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_shipping" />';
|
||||
echo '<input type="hidden" name="shipping_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_update_shipping_' . $id);
|
||||
@@ -1177,7 +1182,21 @@ class AKSRT_Admin_Pay_Menus {
|
||||
echo '</select>';
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('备注', 'aksrt') . '" />';
|
||||
submit_button(__('更新', 'aksrt'), 'small', '', false);
|
||||
echo '</form></td></tr>';
|
||||
echo '</form>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_query_express" />';
|
||||
echo '<input type="hidden" name="shipping_id" value="' . esc_attr((string) $id) . '" />';
|
||||
echo '<input type="hidden" name="force" value="1" />';
|
||||
wp_nonce_field('aksrt_pay_query_express_' . $id);
|
||||
submit_button(__('查物流', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
echo '<a class="button button-small" href="' . esc_url($this->page_url('aksrt_shipping', ['view' => 'records', 'express_id' => $id, 's' => $order_number])) . '">' . esc_html__('轨迹', 'aksrt') . '</a>';
|
||||
echo '</td></tr>';
|
||||
if ($show_express_id === $id) {
|
||||
echo '<tr class="aksrt-express-row"><td colspan="7">';
|
||||
$this->render_express_timeline_panel($id);
|
||||
echo '</td></tr>';
|
||||
}
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
@@ -1276,7 +1295,37 @@ class AKSRT_Admin_Pay_Menus {
|
||||
exit;
|
||||
}
|
||||
|
||||
wp_safe_redirect($this->page_url('aksrt_shipping', ['aksrt_pay_msg' => $ok ? 'shipping_updated' : 'shipping_failed']));
|
||||
wp_safe_redirect($this->page_url('aksrt_shipping', [
|
||||
'view' => 'records',
|
||||
'aksrt_pay_msg' => $ok ? 'shipping_updated' : 'shipping_failed',
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function handle_query_express(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['shipping_id']) ? (int) $_POST['shipping_id'] : 0;
|
||||
$force = !empty($_POST['force']);
|
||||
check_admin_referer('aksrt_pay_query_express_' . $id);
|
||||
|
||||
$ok = false;
|
||||
$order_number = '';
|
||||
if ($id > 0 && class_exists('AKSRT_Shipping')) {
|
||||
$svc = AKSRT_Shipping::get_instance();
|
||||
$record = $svc->get($id);
|
||||
$order_number = is_array($record) ? (string) ($record['order_number'] ?? '') : '';
|
||||
$result = $svc->query_express($id, $force);
|
||||
$ok = !empty($result['success']);
|
||||
}
|
||||
|
||||
wp_safe_redirect($this->page_url('aksrt_shipping', [
|
||||
'view' => 'records',
|
||||
'express_id' => $id,
|
||||
's' => $order_number,
|
||||
'aksrt_pay_msg' => $ok ? 'express_ok' : 'express_failed',
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1594,6 +1643,13 @@ class AKSRT_Admin_Pay_Menus {
|
||||
echo '<p><label>' . esc_html__('最高优惠(百分比用)', 'aksrt') . '<br><input type="number" step="0.01" name="max_discount" value="0" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('总次数(0=不限)', 'aksrt') . '<br><input type="number" name="usage_limit" value="0" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('每人限次(0=不限)', 'aksrt') . '<br><input type="number" name="per_user_limit" value="0" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('适用范围', 'aksrt') . '<br><select name="scope_type">';
|
||||
echo '<option value="">' . esc_html__('全部商品', 'aksrt') . '</option>';
|
||||
echo '<option value="include">' . esc_html__('仅指定商品 ID', 'aksrt') . '</option>';
|
||||
echo '<option value="exclude">' . esc_html__('排除商品 ID', 'aksrt') . '</option>';
|
||||
echo '<option value="category">' . esc_html__('指定分类 ID', 'aksrt') . '</option>';
|
||||
echo '</select></label></p>';
|
||||
echo '<p><label>' . esc_html__('范围 ID', 'aksrt') . '<br><input type="text" name="scope_ids" class="regular-text" placeholder="' . esc_attr__('逗号分隔,如 12,34', 'aksrt') . '" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('过期时间', 'aksrt') . '<br><input type="datetime-local" name="expires_at" /></label></p>';
|
||||
submit_button(__('创建', 'aksrt'), 'primary', '', false);
|
||||
echo '</form>';
|
||||
@@ -1653,10 +1709,10 @@ class AKSRT_Admin_Pay_Menus {
|
||||
$pages = max(1, (int) ($result['total_pages'] ?? 1));
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('代码', 'aksrt') . '</th><th>' . esc_html__('类型', 'aksrt') . '</th><th>' . esc_html__('面值', 'aksrt') . '</th><th>' . esc_html__('门槛/封顶', 'aksrt') . '</th><th>' . esc_html__('已用/上限/每人', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('过期', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '<th>ID</th><th>' . esc_html__('代码', 'aksrt') . '</th><th>' . esc_html__('类型', 'aksrt') . '</th><th>' . esc_html__('面值', 'aksrt') . '</th><th>' . esc_html__('门槛/封顶', 'aksrt') . '</th><th>' . esc_html__('范围', 'aksrt') . '</th><th>' . esc_html__('已用/上限/每人', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('过期', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="9">' . esc_html__('暂无优惠码', 'aksrt') . '</td></tr>';
|
||||
echo '<tr><td colspan="10">' . esc_html__('暂无优惠码', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
@@ -1668,6 +1724,7 @@ class AKSRT_Admin_Pay_Menus {
|
||||
echo '<td>' . esc_html($type_labels[$row_type] ?? $row_type) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['value'] ?? '')) . ($row_type === 'percent' ? '%' : '') . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['min_amount'] ?? 0)) . ' / ' . esc_html((string) ($row['max_discount'] ?? 0)) . '</td>';
|
||||
echo '<td>' . esc_html($this->format_coupon_scope_label($row['product_scope'] ?? [])) . '</td>';
|
||||
echo '<td>' . esc_html((string) ((int) ($row['used_count'] ?? 0)) . '/' . (string) ((int) ($row['usage_limit'] ?? 0)) . '/' . (string) ((int) ($row['per_user_limit'] ?? 0))) . '</td>';
|
||||
echo '<td>' . esc_html($status_labels[$st] ?? $st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['expires_at'] ?? '')) . '</td>';
|
||||
@@ -1719,6 +1776,7 @@ class AKSRT_Admin_Pay_Menus {
|
||||
'max_discount' => (float) ($_POST['max_discount'] ?? 0),
|
||||
'usage_limit' => (int) ($_POST['usage_limit'] ?? 0),
|
||||
'per_user_limit' => (int) ($_POST['per_user_limit'] ?? 0),
|
||||
'product_scope' => $this->parse_coupon_product_scope_from_request(),
|
||||
'expires_at' => $expires,
|
||||
]);
|
||||
$ok = $id > 0;
|
||||
@@ -2128,6 +2186,82 @@ class AKSRT_Admin_Pay_Menus {
|
||||
}
|
||||
}
|
||||
|
||||
private function render_express_timeline_panel(int $shipping_id): void {
|
||||
if ($shipping_id <= 0 || !class_exists('AKSRT_Shipping')) {
|
||||
echo '<p>' . esc_html__('无法加载物流轨迹。', 'aksrt') . '</p>';
|
||||
return;
|
||||
}
|
||||
$svc = AKSRT_Shipping::get_instance();
|
||||
// Prefer cached data; do not force remote query on pure view.
|
||||
$timeline = $svc->build_express_timeline($shipping_id);
|
||||
$record = $svc->get($shipping_id);
|
||||
echo '<div style="padding:10px 12px;background:#f6f7f7;border:1px solid #dcdcde;">';
|
||||
echo '<p style="margin:0 0 8px;"><strong>' . esc_html__('物流轨迹', 'aksrt') . '</strong> · ';
|
||||
echo esc_html((string) ($record['carrier'] ?? '')) . ' / ' . esc_html((string) ($record['tracking_no'] ?? ''));
|
||||
echo '</p>';
|
||||
if (!$timeline) {
|
||||
echo '<p style="margin:0;">' . esc_html__('暂无轨迹,可点击「查物流」拉取快递 API。', 'aksrt') . '</p>';
|
||||
echo '</div>';
|
||||
return;
|
||||
}
|
||||
echo '<ol style="margin:0;padding-left:18px;">';
|
||||
// newest first for operators
|
||||
$timeline = array_reverse($timeline);
|
||||
foreach ($timeline as $item) {
|
||||
$time = (string) ($item['time'] ?? '');
|
||||
$label = (string) ($item['label'] ?? '');
|
||||
echo '<li style="margin:0 0 6px;"><code>' . esc_html($time) . '</code> ' . esc_html($label) . '</li>';
|
||||
}
|
||||
echo '</ol></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function parse_coupon_product_scope_from_request(): array {
|
||||
$type = isset($_POST['scope_type']) ? sanitize_key((string) wp_unslash($_POST['scope_type'])) : '';
|
||||
if ($type === '' || !in_array($type, ['include', 'exclude', 'category'], true)) {
|
||||
return [];
|
||||
}
|
||||
$raw = isset($_POST['scope_ids']) ? (string) wp_unslash($_POST['scope_ids']) : '';
|
||||
$parts = preg_split('/[\s,;]+/', $raw) ?: [];
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', $parts))));
|
||||
if (!$ids) {
|
||||
return [];
|
||||
}
|
||||
$scope = [
|
||||
'type' => $type,
|
||||
'ids' => $ids,
|
||||
];
|
||||
if ($type === 'category') {
|
||||
$scope['taxonomies'] = ['aksrt_product_cat', 'category'];
|
||||
}
|
||||
return $scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $scope
|
||||
*/
|
||||
private function format_coupon_scope_label($scope): string {
|
||||
if (is_string($scope) && $scope !== '') {
|
||||
$decoded = json_decode($scope, true);
|
||||
$scope = is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
if (!is_array($scope) || empty($scope)) {
|
||||
return __('全部', 'aksrt');
|
||||
}
|
||||
$type = sanitize_key((string) ($scope['type'] ?? ''));
|
||||
$ids = array_map('intval', (array) ($scope['ids'] ?? []));
|
||||
$id_text = $ids ? implode(',', $ids) : '—';
|
||||
$map = [
|
||||
'include' => __('含商品', 'aksrt'),
|
||||
'exclude' => __('排除商品', 'aksrt'),
|
||||
'category' => __('分类', 'aksrt'),
|
||||
];
|
||||
$label = $map[$type] ?? $type;
|
||||
return $label . ':' . $id_text;
|
||||
}
|
||||
|
||||
private function render_pagination(int $pages, int $page_num): void {
|
||||
if ($pages <= 1) {
|
||||
return;
|
||||
|
||||
@@ -52,6 +52,8 @@ class AKSRT_Plate_Meta_Box {
|
||||
$applications = get_post_meta($post->ID, '_aksrt_moderator_applications', true);
|
||||
$applications = is_array($applications) ? $applications : [];
|
||||
}
|
||||
$allow_view = (string) (get_post_meta($post->ID, '_aksrt_allow_view', true) ?: 'public');
|
||||
$add_limit = (string) (get_post_meta($post->ID, '_aksrt_add_limit', true) ?: 'all');
|
||||
|
||||
$moderator_labels = [];
|
||||
foreach ($moderator_ids as $uid) {
|
||||
@@ -61,6 +63,30 @@ class AKSRT_Plate_Meta_Box {
|
||||
: (string) (int) $uid;
|
||||
}
|
||||
?>
|
||||
<p>
|
||||
<label for="aksrt_plate_allow_view"><strong><?php esc_html_e('浏览权限', 'aksrt'); ?></strong></label>
|
||||
<select id="aksrt_plate_allow_view" name="aksrt_plate_allow_view" class="widefat">
|
||||
<?php foreach ([
|
||||
'public' => __('公开', 'aksrt'),
|
||||
'login' => __('登录可见', 'aksrt'),
|
||||
'moderator' => __('版主可见', 'aksrt'),
|
||||
] as $k => $label) : ?>
|
||||
<option value="<?php echo esc_attr($k); ?>" <?php selected($allow_view, $k); ?>><?php echo esc_html($label); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label for="aksrt_plate_add_limit"><strong><?php esc_html_e('发帖权限', 'aksrt'); ?></strong></label>
|
||||
<select id="aksrt_plate_add_limit" name="aksrt_plate_add_limit" class="widefat">
|
||||
<?php foreach ([
|
||||
'all' => __('所有人', 'aksrt'),
|
||||
'login' => __('登录用户', 'aksrt'),
|
||||
'moderator' => __('仅版主', 'aksrt'),
|
||||
] as $k => $label) : ?>
|
||||
<option value="<?php echo esc_attr($k); ?>" <?php selected($add_limit, $k); ?>><?php echo esc_html($label); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label for="aksrt_plate_moderators"><strong><?php esc_html_e('版主用户 ID', 'aksrt'); ?></strong></label>
|
||||
<textarea id="aksrt_plate_moderators" name="aksrt_plate_moderators" rows="3" class="widefat" placeholder="1,2,3"><?php echo esc_textarea(implode(',', array_map('intval', $moderator_ids))); ?></textarea>
|
||||
@@ -111,6 +137,18 @@ class AKSRT_Plate_Meta_Box {
|
||||
return;
|
||||
}
|
||||
|
||||
$allow_view = isset($_POST['aksrt_plate_allow_view']) ? sanitize_key((string) wp_unslash($_POST['aksrt_plate_allow_view'])) : 'public';
|
||||
if (!in_array($allow_view, ['public', 'login', 'moderator'], true)) {
|
||||
$allow_view = 'public';
|
||||
}
|
||||
update_post_meta($post_id, '_aksrt_allow_view', $allow_view);
|
||||
|
||||
$add_limit = isset($_POST['aksrt_plate_add_limit']) ? sanitize_key((string) wp_unslash($_POST['aksrt_plate_add_limit'])) : 'all';
|
||||
if (!in_array($add_limit, ['all', 'login', 'moderator'], true)) {
|
||||
$add_limit = 'all';
|
||||
}
|
||||
update_post_meta($post_id, '_aksrt_add_limit', $add_limit);
|
||||
|
||||
$raw = isset($_POST['aksrt_plate_moderators']) ? (string) wp_unslash($_POST['aksrt_plate_moderators']) : '';
|
||||
$ids = preg_split('/[\s,;]+/', $raw) ?: [];
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', $ids))));
|
||||
|
||||
@@ -46,6 +46,7 @@ class AKSRT_Topic_Admin_List {
|
||||
$new['aksrt_locked'] = __('锁定', 'aksrt');
|
||||
$new['aksrt_review'] = __('审核', 'aksrt');
|
||||
$new['aksrt_bbs_type']= __('类型', 'aksrt');
|
||||
$new['aksrt_visibility'] = __('可见性', 'aksrt');
|
||||
$new['aksrt_views'] = __('阅读', 'aksrt');
|
||||
}
|
||||
}
|
||||
@@ -116,6 +117,20 @@ class AKSRT_Topic_Admin_List {
|
||||
echo esc_html($type === 'question' ? __('提问', 'aksrt') : __('标准', 'aksrt'));
|
||||
break;
|
||||
|
||||
case 'aksrt_visibility':
|
||||
$visibility = (string) (get_post_meta($post_id, '_aksrt_visibility', true) ?: 'public');
|
||||
$map = [
|
||||
'public' => __('公开', 'aksrt'),
|
||||
'login' => __('登录', 'aksrt'),
|
||||
'comment' => __('评论', 'aksrt'),
|
||||
'role' => __('角色', 'aksrt'),
|
||||
'credits' => __('积分', 'aksrt'),
|
||||
'pay' => __('付费', 'aksrt'),
|
||||
'moderator' => __('版主', 'aksrt'),
|
||||
];
|
||||
echo esc_html($map[$visibility] ?? $visibility);
|
||||
break;
|
||||
|
||||
case 'aksrt_views':
|
||||
echo esc_html((string) (int) get_post_meta($post_id, '_aksrt_views', true));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user