diff --git a/assets/admin/src/schema/sections/page-display/index.js b/assets/admin/src/schema/sections/page-display/index.js
index 27de3175..237fc00c 100644
--- a/assets/admin/src/schema/sections/page-display/index.js
+++ b/assets/admin/src/schema/sections/page-display/index.js
@@ -313,6 +313,7 @@ export const pageDisplaySchemas = {
user_home_tabs_mobile_hide: '',
user_home_sidebar: false,
user_home_cover: true,
+ user_home_route_identifier: 'nicename',
user_home_follow: true,
user_home_posts_per_page: 10,
user_home_avatar: true,
@@ -332,6 +333,7 @@ export const pageDisplaySchemas = {
icon: 'fas fa-th-large',
fields: [
{ key: 'user_home_cover', label: '封面区域', type: 'switch', default: true, help: '用户主页顶部封面图' },
+ { key: 'user_home_route_identifier', label: '主页 URL 标识', type: 'select', default: 'nicename', options: [{ label: '用户名 URL slug', value: 'nicename' }, { label: '数字用户 ID', value: 'uid' }] },
{ key: 'user_home_sidebar', label: '侧边栏(已弃用)', type: 'switch', default: false, help: '公开主页为通栏布局(对齐 Zibll author);运行时强制关闭。交易服务请去用户中心。' },
{ key: 'user_home_follow', label: '关注按钮', type: 'switch', default: true },
{ key: 'user_home_posts_per_page', label: '每页文章数', type: 'number', default: 10, min: 5, max: 50 },
diff --git a/assets/admin/src/schema/sections/payment/recharge.js b/assets/admin/src/schema/sections/payment/recharge.js
index d8d773bd..5759c6ba 100644
--- a/assets/admin/src/schema/sections/payment/recharge.js
+++ b/assets/admin/src/schema/sections/payment/recharge.js
@@ -24,7 +24,6 @@ export const rechargeSchema = {
pay_balance_exchange_rate: 100,
pay_balance_exchange_desc: '',
pay_balance_withdraw_s: false,
- pay_balance_withdraw_lowest_money: 50,
},
groups: [
{
@@ -94,7 +93,6 @@ export const rechargeSchema = {
icon: 'fas fa-hand-holding-usd',
fields: [
{ key: 'pay_balance_withdraw_s', label: '启用余额提现', type: 'switch', default: false, dependsOn: { key: 'pay_balance_s', value: true } },
- { key: 'pay_balance_withdraw_lowest_money', label: '最低提现金额', type: 'number', default: 50, min: 1, max: 99999, dependsOn: { key: 'pay_balance_withdraw_s', value: true } },
],
},
],
diff --git a/assets/admin/src/schema/sections/payment/withdrawal.js b/assets/admin/src/schema/sections/payment/withdrawal.js
index 2457f15d..ba497b41 100644
--- a/assets/admin/src/schema/sections/payment/withdrawal.js
+++ b/assets/admin/src/schema/sections/payment/withdrawal.js
@@ -2,11 +2,13 @@ export const withdrawalSchema = {
key: 'payment.withdrawal',
title: '提现管理',
icon: 'fas fa-hand-holding-usd',
- description: '配置提现门槛、手续费比例和提现说明。',
+ description: '配置提现门槛、手续费比例与每日限制。',
defaults: {
pay_rebate_withdraw_lowest_money: 50,
- withdraw_service_charge: 0,
- pay_rebate_withdraw_text_details: '
@@ -22,16 +17,16 @@ $wallet_fmt = (string) ($wallet_fmt ?? '0.00');
diff --git a/inc/modules/user-parts/routing.php b/inc/modules/user-parts/routing.php
index 14e6e815..ffb7b496 100644
--- a/inc/modules/user-parts/routing.php
+++ b/inc/modules/user-parts/routing.php
@@ -14,7 +14,8 @@ defined('ABSPATH') || exit;
// --- 3a. /user/{昵称} 自定义重写 ---
add_filter('query_vars', function ($vars) {
$vars[] = 'aksrt_user_center';
- $vars[] = 'user_nicename';
+ $vars[] = 'aksrt_user_center_tab';
+ $vars[] = 'aksrt_author_identifier';
$vars[] = 'aksrt_orders';
$vars[] = 'aksrt_revenue';
return $vars;
@@ -24,6 +25,14 @@ add_action('template_redirect', function () {
if (is_admin() || wp_doing_ajax() || is_feed() || is_embed() || is_preview()) {
return;
}
+ $request_path = trim((string) parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH), '/');
+ if ($request_path === 'profile' || str_starts_with($request_path, 'profile/')) {
+ global $wp_query;
+ if ($wp_query instanceof WP_Query) { $wp_query->set_404(); }
+ status_header(404);
+ nocache_headers();
+ return;
+ }
$resolved_path = aksrt_get_current_special_template_path();
if ($resolved_path === '') {
@@ -35,13 +44,36 @@ add_action('template_redirect', function () {
exit;
}, 100);
+// /user/{tab} only accepts registered user-center tabs; former public /user/{slug}
+// addresses must not silently resolve to the user-center home.
+add_action('template_redirect', function () {
+ if (is_admin() || wp_doing_ajax()) {
+ return;
+ }
+ $tab = (string) get_query_var('aksrt_user_center_tab');
+ if ($tab === '') {
+ return;
+ }
+ $tab = $tab === 'balance' ? 'credits' : sanitize_key($tab);
+ $allowed = class_exists('\\AKSRT\\User\\Center')
+ ? array_keys(\AKSRT\User\Center::get_instance()->get_dashboard_tabs())
+ : ['profile', 'level', 'creator', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings'];
+ if (!in_array($tab, $allowed, true)) {
+ global $wp_query;
+ if ($wp_query instanceof WP_Query) { $wp_query->set_404(); }
+ status_header(404);
+ nocache_headers();
+ }
+}, 1);
+
add_action('init', function () {
add_rewrite_tag('%aksrt_user_center%', '([^&]+)');
- add_rewrite_tag('%user_nicename%', '([^/]+)');
+ add_rewrite_tag('%aksrt_user_center_tab%', '([^/]+)');
+ add_rewrite_tag('%aksrt_author_identifier%', '([^/]+)');
add_rewrite_tag('%aksrt_orders%', '([0-1])');
add_rewrite_tag('%aksrt_revenue%', '([0-1])');
- add_rewrite_rule('^profile/?$', 'index.php?aksrt_user_center=1', 'top');
- add_rewrite_rule('^user/([^/]+)/?$', 'index.php?user_nicename=$matches[1]', 'top');
+ add_rewrite_rule('^user/([a-z0-9_-]+)/?$', 'index.php?aksrt_user_center=1&aksrt_user_center_tab=$matches[1]', 'top');
+ add_rewrite_rule('^author/([^/]+)/?$', 'index.php?aksrt_author_identifier=$matches[1]', 'top');
// Commerce center aliases (work even before WP page is assigned).
add_rewrite_rule('^orders/?$', 'index.php?aksrt_orders=1', 'top');
add_rewrite_rule('^revenue/?$', 'index.php?aksrt_revenue=1', 'top');
@@ -56,9 +88,9 @@ add_filter('template_include', function ($template) {
}
// A) /user/{昵称} even if special-path helper returned empty (user missing → 404).
- $nicename = (string) get_query_var('user_nicename');
- if ($nicename !== '') {
- $user = get_user_by('slug', $nicename);
+ $identifier = (string) get_query_var('aksrt_author_identifier');
+ if ($identifier !== '') {
+ $user = function_exists('aksrt_resolve_public_user') ? aksrt_resolve_public_user($identifier) : null;
if ($user instanceof WP_User) {
$tpl = aksrt_locate_template_file('templates/pages/page-user-home.php');
if ($tpl) {
@@ -78,18 +110,12 @@ add_filter('template_include', function ($template) {
return $four ?: $template;
}
- // B) profile slug page without rewrite var (permalink edge).
+ // B) ordinary assigned page templates.
if (is_page()) {
$page_id = get_queried_object_id();
if ($page_id) {
$slug = (string) get_post_field('post_name', $page_id);
$page_template = get_post_meta($page_id, '_wp_page_template', true);
- if ($slug === 'profile' || $page_template === 'templates/pages/page-profile.php') {
- $tpl = aksrt_locate_template_file('templates/pages/page-profile.php');
- if ($tpl) {
- return $tpl;
- }
- }
if (is_string($page_template) && strpos($page_template, 'templates/pages/') === 0) {
$tpl = aksrt_locate_template_file($page_template);
if ($tpl) {
@@ -157,13 +183,8 @@ add_action('init', function () {
aksrt_ensure_template_page($requested_template_key);
}
- // Always re-assert profile page template (blank WP page with slug profile is common).
- if (function_exists('aksrt_ensure_template_page')) {
- aksrt_ensure_template_page('profile');
- }
-
// 统一 flush 检查 — bump when user-home rewrite / author override changes
- $rewrite_version = AKSRT_VERSION . ':user-home-profile-routing-v5';
+ $rewrite_version = AKSRT_VERSION . ':user-center-author-routing-v6';
$flushed = get_option('aksrt_user_rules_flushed');
$rules = get_option('rewrite_rules');
$need_flush = ($flushed !== $rewrite_version)
@@ -199,15 +220,15 @@ add_filter('author_link', function ($link, $author_id) {
$user = get_userdata($author_id);
$slug = $user ? $user->user_nicename : ('user-' . max(0, $author_id));
if (!get_option('permalink_structure')) {
- return add_query_arg('user_nicename', rawurlencode($slug), home_url('/'));
+ return add_query_arg('aksrt_author', rawurlencode($slug), home_url('/'));
}
- return home_url('/user/' . trailingslashit($slug));
+ return home_url('/author/' . trailingslashit($slug));
}, 99, 2);
// Accept ?user_nicename= when pretty rewrites are unavailable.
add_filter('request', function ($query_vars) {
- if (empty($query_vars['user_nicename']) && !empty($_GET['user_nicename'])) {
- $query_vars['user_nicename'] = sanitize_title(wp_unslash((string) $_GET['user_nicename']));
+ if (empty($query_vars['aksrt_author_identifier']) && !empty($_GET['aksrt_author'])) {
+ $query_vars['aksrt_author_identifier'] = sanitize_text_field(wp_unslash((string) $_GET['aksrt_author']));
}
if (empty($query_vars['aksrt_user_center']) && isset($_GET['aksrt_user_center'])) {
$query_vars['aksrt_user_center'] = '1';
@@ -248,7 +269,7 @@ add_action('template_redirect', function () {
if (empty($_GET['author'])) {
return;
}
- if (get_query_var('user_nicename') || get_query_var('aksrt_user_center')) {
+ if (get_query_var('aksrt_author_identifier') || get_query_var('aksrt_user_center')) {
return;
}
if (is_author()) {
diff --git a/inc/modules/user-parts/template-registry.php b/inc/modules/user-parts/template-registry.php
index 0923d6f7..1a8150ad 100644
--- a/inc/modules/user-parts/template-registry.php
+++ b/inc/modules/user-parts/template-registry.php
@@ -369,12 +369,12 @@ function aksrt_clear_template_page_cache(): void {
function aksrt_get_user_home_template_path(): string {
global $_aksrt_special_templates, $aksrt_profile_user;
- $nicename = (string) get_query_var('user_nicename');
- if ($nicename === '') {
+ $identifier = (string) get_query_var('aksrt_author_identifier');
+ if ($identifier === '') {
return '';
}
- $user = get_user_by('slug', $nicename);
+ $user = function_exists('aksrt_resolve_public_user') ? aksrt_resolve_public_user($identifier) : null;
if (!$user instanceof WP_User) {
return '';
}
@@ -393,7 +393,7 @@ function aksrt_get_user_home_template_path(): string {
* Resolve the active special-page template path for the current request.
*/
function aksrt_get_current_special_template_path(): string {
- if (get_query_var('user_nicename')) {
+ if (get_query_var('aksrt_author_identifier')) {
return aksrt_get_user_home_template_path();
}
diff --git a/inc/modules/user-parts/urls.php b/inc/modules/user-parts/urls.php
index c6395dca..1eee54dd 100644
--- a/inc/modules/user-parts/urls.php
+++ b/inc/modules/user-parts/urls.php
@@ -19,28 +19,13 @@ if (!function_exists('aksrt_get_user_center_url')) :
* @return string
*/
function aksrt_get_user_center_url(string $tab = ''): string {
- if (get_option('permalink_structure')) {
- $url = home_url('/profile/');
- } else {
- $url = add_query_arg('aksrt_user_center', '1', home_url('/'));
- }
-
- if ($tab !== '') {
- $tab = sanitize_key($tab);
- // Deep-link aliases used by header wallet / VIP CTA.
- $aliases = [
- 'assets' => 'credits',
- 'vip' => 'vip', // dedicated vip tab when registered; resolver falls back if missing
- 'signin' => 'credits',
- 'invite' => 'revenue',
- 'promotion' => 'revenue',
- ];
- if (isset($aliases[$tab])) {
- $tab = $aliases[$tab];
- }
- $url = add_query_arg('tab', $tab, $url);
- }
- return $url;
+ $tab = sanitize_key($tab ?: 'profile');
+ $aliases = ['assets' => 'credits', 'signin' => 'credits', 'invite' => 'revenue', 'promotion' => 'revenue'];
+ $tab = $aliases[$tab] ?? $tab;
+ $path_tab = $tab === 'credits' ? 'balance' : $tab;
+ return get_option('permalink_structure')
+ ? home_url('/user/' . trailingslashit($path_tab))
+ : add_query_arg(['aksrt_user_center' => '1', 'aksrt_user_center_tab' => $tab], home_url('/'));
}
endif;
@@ -81,7 +66,7 @@ function aksrt_get_orders_page_url(): string {
if (function_exists('aksrt_get_user_center_url')) {
return aksrt_get_user_center_url('orders');
}
- return home_url('/profile/?tab=orders');
+ return home_url('/user/orders/');
}
endif;
@@ -96,7 +81,7 @@ function aksrt_get_revenue_page_url(): string {
if (function_exists('aksrt_get_user_center_url')) {
return aksrt_get_user_center_url('revenue');
}
- return home_url('/profile/?tab=revenue');
+ return home_url('/user/revenue/');
}
endif;
@@ -122,29 +107,37 @@ if (!function_exists('aksrt_get_user_home_url')) :
* @return string
*/
function aksrt_get_user_home_url($user = null): string {
- $slug = '';
+ $target = null;
+ $mode = class_exists('\\AKSRT\\Settings\\Settings') ? (string) (\AKSRT\Settings\Settings::get_user_home_settings()['route_identifier'] ?? 'nicename') : 'nicename';
if ($user instanceof WP_User) {
- $slug = $user->user_nicename;
+ $target = $user;
} elseif (is_int($user) && $user > 0) {
- $u = get_userdata($user);
- $slug = $u ? $u->user_nicename : '';
+ $target = get_userdata($user);
} elseif (is_numeric($user) && (int) $user > 0) {
- $u = get_userdata((int) $user);
- $slug = $u ? $u->user_nicename : '';
+ $target = get_userdata((int) $user);
} elseif (is_string($user) && $user) {
- $slug = $user;
+ $target = get_user_by('slug', $user);
} else {
- $current = wp_get_current_user();
- $slug = $current->ID ? $current->user_nicename : '';
+ $target = wp_get_current_user();
}
- if (!$slug) {
+ if (!$target instanceof WP_User || !$target->ID) {
return home_url('/');
}
- // Plain permalinks: Apache 404s pretty /user/{slug}/ before WP boots.
+ $identifier = $mode === 'uid' ? (string) $target->ID : $target->user_nicename;
if (!get_option('permalink_structure')) {
- return add_query_arg('user_nicename', rawurlencode($slug), home_url('/'));
+ return add_query_arg('aksrt_author', rawurlencode($identifier), home_url('/'));
}
- return home_url('/user/' . trailingslashit($slug));
+ return home_url('/author/' . trailingslashit($identifier));
+}
+endif;
+
+if (!function_exists('aksrt_resolve_public_user')) :
+function aksrt_resolve_public_user(string $identifier): ?WP_User {
+ $mode = class_exists('\\AKSRT\\Settings\\Settings') ? (string) (\AKSRT\Settings\Settings::get_user_home_settings()['route_identifier'] ?? 'nicename') : 'nicename';
+ if ($mode === 'uid') {
+ return ctype_digit($identifier) && (int) $identifier > 0 ? get_userdata((int) $identifier) ?: null : null;
+ }
+ return get_user_by('slug', sanitize_title($identifier)) ?: null;
}
endif;
@@ -154,7 +147,7 @@ if (!function_exists('aksrt_is_user_center_page')) :
*/
function aksrt_is_user_center_page(): bool {
return (bool) get_query_var('aksrt_user_center')
- || (is_page_template('templates/pages/page-profile.php') && !(bool) get_query_var('user_nicename'));
+ || (is_page_template('templates/pages/page-profile.php') && !(bool) get_query_var('aksrt_author_identifier'));
}
endif;
@@ -163,7 +156,7 @@ if (!function_exists('aksrt_is_user_home_page')) :
* 判断当前是否为公开用户主页
*/
function aksrt_is_user_home_page(): bool {
- return (bool) get_query_var('user_nicename')
+ return (bool) get_query_var('aksrt_author_identifier')
|| is_page_template('templates/pages/page-user-home.php');
}
endif;
diff --git a/src/Admin/Schema/SchemaPageDisplay.php b/src/Admin/Schema/SchemaPageDisplay.php
index a3a8442f..8c38b776 100644
--- a/src/Admin/Schema/SchemaPageDisplay.php
+++ b/src/Admin/Schema/SchemaPageDisplay.php
@@ -245,6 +245,7 @@ class SchemaPageDisplay {
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'layout', 'title' => '主页布局', 'fields' => [
+ ['key' => 'user_home_route_identifier', 'label' => '主页 URL 标识', 'type' => 'select', 'default' => 'nicename', 'options' => [['label' => '用户名 URL slug', 'value' => 'nicename'], ['label' => '数字用户 ID', 'value' => 'uid']]],
['key' => 'user_home_cover', 'label' => '封面区域', 'type' => 'switch', 'default' => true],
['key' => 'user_home_sidebar', 'label' => '侧边栏(已弃用)', 'type' => 'switch', 'default' => false, 'help' => '公开主页对齐 Zibll 作者页为通栏布局;交易/快捷入口仅在用户中心展示。此开关保留兼容,运行时强制关闭。'],
['key' => 'user_home_follow', 'label' => '关注按钮', 'type' => 'switch', 'default' => true],
diff --git a/src/Admin/Schema/SchemaPayment.php b/src/Admin/Schema/SchemaPayment.php
index 742cb65d..e4723736 100644
--- a/src/Admin/Schema/SchemaPayment.php
+++ b/src/Admin/Schema/SchemaPayment.php
@@ -97,7 +97,6 @@ class SchemaPayment {
]],
['key' => 'withdraw', 'title' => '余额提现', 'fields' => [
['key' => 'pay_balance_withdraw_s', 'label' => '启用余额提现', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'pay_balance_s', 'value' => true]],
- ['key' => 'pay_balance_withdraw_lowest_money', 'label' => '最低提现金额', 'type' => 'number', 'default' => 50, 'min' => 1, 'max' => 99999, 'dependsOn' => ['key' => 'pay_balance_withdraw_s', 'value' => true]],
]],
],
],
@@ -373,11 +372,11 @@ class SchemaPayment {
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'basic', 'title' => '提现设置', 'fields' => [
- ['key' => 'pay_rebate_withdraw_lowest_money', 'label' => '最低提现金额', 'type' => 'number', 'default' => 50, 'min' => 1, 'max' => 99999],
- ['key' => 'withdraw_service_charge', 'label' => '提现手续费(%)', 'type' => 'number', 'default' => 0, 'min' => 0, 'max' => 50],
- ['key' => 'pay_rebate_withdraw_text_details', 'label' => '提现说明', 'type' => 'textarea', 'default' => '
可提现金额达到50元后即可发起提现
-
申请提现需后台人工处理,一般2-3小时,请耐心等待
-
如有其它疑问,请与客服联系
'],
+ ['key' => 'pay_rebate_withdraw_lowest_money', 'label' => '最低提现金额', 'type' => 'number', 'default' => 50, 'min' => 0, 'max' => 99999],
+ ['key' => 'withdraw_service_charge', 'label' => '提现手续费(%)', 'type' => 'number', 'default' => 5, 'min' => 0, 'max' => 50],
+ ['key' => 'withdraw_daily_count', 'label' => '每日可提现次数', 'type' => 'number', 'default' => 3, 'min' => 0, 'max' => 99999, 'sanitize_type' => 'int'],
+ ['key' => 'withdraw_daily_limit', 'label' => '每日提现上限', 'type' => 'number', 'default' => 50, 'min' => 0, 'max' => 999999],
+ ['key' => 'withdraw_reset_time', 'label' => '重置时间', 'type' => 'input', 'default' => '00:00', 'help' => '按站点 WordPress 时区重置,格式 HH:MM。'],
]],
],
],
diff --git a/src/Admin/SchemaProvider.php b/src/Admin/SchemaProvider.php
index c8ff8c06..4bda98ed 100644
--- a/src/Admin/SchemaProvider.php
+++ b/src/Admin/SchemaProvider.php
@@ -207,6 +207,24 @@ class SchemaProvider {
}
}
+ if ($domain === 'payment' && $section === 'withdrawal') {
+ $stored = get_option('aksrt_settings', []);
+ $merged = is_array($stored) ? array_merge($stored, $data) : $data;
+ $count = $merged['withdraw_daily_count'] ?? 3;
+ $min = (float) ($merged['pay_rebate_withdraw_lowest_money'] ?? 50);
+ $limit = (float) ($merged['withdraw_daily_limit'] ?? 50);
+ $time = (string) ($merged['withdraw_reset_time'] ?? '00:00');
+ if (filter_var($count, FILTER_VALIDATE_INT) === false || (int) $count < 0) {
+ $errors[] = __('每日可提现次数必须是非负整数', 'aksrt');
+ }
+ if ($limit < $min) {
+ $errors[] = __('每日提现上限不得低于最低提现金额', 'aksrt');
+ }
+ if (preg_match('/^(?:[01]\\d|2[0-3]):[0-5]\\d$/', $time) !== 1) {
+ $errors[] = __('重置时间必须为 HH:MM', 'aksrt');
+ }
+ }
+
return ['valid' => empty($errors), 'errors' => $errors];
}
@@ -318,6 +336,10 @@ class SchemaProvider {
$stored[$key] = $value;
}
+ if (($schema['key'] ?? '') === 'withdrawal') {
+ unset($stored['pay_rebate_withdraw_text_details'], $stored['pay_balance_withdraw_lowest_money']);
+ }
+
// Captcha: keep enabled_scenarios / disabled_scenarios mirrors in sync.
if ($option_key === 'aksrt_captcha_config' && function_exists('aksrt_captcha_scenes')) {
$all = array_keys(aksrt_captcha_scenes());
diff --git a/src/Auth/OAuthPart2.php b/src/Auth/OAuthPart2.php
index 6e756ff0..ad0b94bd 100644
--- a/src/Auth/OAuthPart2.php
+++ b/src/Auth/OAuthPart2.php
@@ -165,7 +165,7 @@ trait OAuthPart2 {
}
$user = wp_get_current_user();
if ($user->ID) {
- return home_url('/user/' . $user->user_nicename . '/');
+ return function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : home_url('/');
}
return home_url('/');
}
diff --git a/src/Core/DBMigrator.php b/src/Core/DBMigrator.php
index 96d76aad..14ab076c 100644
--- a/src/Core/DBMigrator.php
+++ b/src/Core/DBMigrator.php
@@ -14,7 +14,7 @@ class DBMigrator {
use DBMigratorVip;
/** Current schema version; changing it re-runs dbDelta. */
- const SCHEMA_VERSION = '1.21.0';
+ const SCHEMA_VERSION = '1.22.0';
const OPT_KEY = 'aksrt_db_schema_version';
diff --git a/src/Core/DBMigratorPart2.php b/src/Core/DBMigratorPart2.php
index 57ddc21e..4fc41bda 100644
--- a/src/Core/DBMigratorPart2.php
+++ b/src/Core/DBMigratorPart2.php
@@ -224,6 +224,7 @@ trait DBMigratorPart2 {
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id BIGINT UNSIGNED NOT NULL,
amount DECIMAL(10,2) NOT NULL DEFAULT 0,
+ gross_amount DECIMAL(10,2) NOT NULL DEFAULT 0,
method VARCHAR(32) NOT NULL DEFAULT '',
account_info TEXT DEFAULT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
@@ -232,6 +233,7 @@ trait DBMigratorPart2 {
note TEXT DEFAULT NULL,
PRIMARY KEY (id),
KEY idx_user (user_id),
+ KEY idx_user_created (user_id, created_at),
KEY idx_status (status),
KEY idx_created (created_at)
) {$charset_collate};";
diff --git a/src/Core/ScriptsPart1b.php b/src/Core/ScriptsPart1b.php
index c7b477fc..1f80b802 100644
--- a/src/Core/ScriptsPart1b.php
+++ b/src/Core/ScriptsPart1b.php
@@ -292,7 +292,7 @@ $hmb_js = get_template_directory() . '/assets/js/header-newadd.js';
$is_resource_archive = function_exists('aksrt_is_resource_archive') && aksrt_is_resource_archive();
// /user/{nicename}/ 自定义重写路由(class-aksrt-user.php 注册)
// 此路径下 is_page() / is_page_template() 均为 false,需手动识别以正确入队 CSS
- $is_profile_route = (bool) get_query_var('user_nicename');
+ $is_profile_route = (bool) get_query_var('aksrt_author_identifier');
$is_user_center_route = (bool) get_query_var('aksrt_user_center');
$is_static_page = is_page() || is_singular('page') || $is_profile_route || $is_user_center_route;
$is_auth_route = (bool) get_query_var('aksrt_sign');
diff --git a/src/Core/ScriptsPart2.php b/src/Core/ScriptsPart2.php
index 73bb8a03..95fc0c38 100644
--- a/src/Core/ScriptsPart2.php
+++ b/src/Core/ScriptsPart2.php
@@ -111,7 +111,7 @@ trait ScriptsPart2 {
}
if ((function_exists('aksrt_is_user_center_page') && aksrt_is_user_center_page())
|| (function_exists('aksrt_is_user_home_page') && aksrt_is_user_home_page())
- || get_query_var('user_nicename')) {
+ || get_query_var('aksrt_author_identifier')) {
$classes[] = 'aksrt-profile';
}
// 区分本人中心与公开主页的 body class
diff --git a/src/Credits/BalanceServiceRest.php b/src/Credits/BalanceServiceRest.php
index 471b2ed6..c98167da 100644
--- a/src/Credits/BalanceServiceRest.php
+++ b/src/Credits/BalanceServiceRest.php
@@ -398,50 +398,37 @@ trait BalanceServiceRest {
if (class_exists('\AKSRT\Settings\Capabilities') && !\AKSRT\Settings\Capabilities::user_can('balance_withdraw', $user_id)) {
return new \WP_Error('aksrt_withdraw_forbidden', __('当前账号无权提现', 'aksrt'), ['status' => 403]);
}
- $amount = round((float) ($params['amount'] ?? 0), 2);
+ $raw_amount = $params['amount'] ?? 0;
+ if (filter_var($raw_amount, FILTER_VALIDATE_INT) === false || (int) $raw_amount <= 0) {
+ return new \WP_Error('aksrt_withdraw_amount', __('提现金额必须为正整数', 'aksrt'), ['status' => 400]);
+ }
+ $amount = (int) $raw_amount;
$method = sanitize_key((string) ($params['method'] ?? 'alipay'));
$account = sanitize_textarea_field((string) ($params['account_info'] ?? $params['account'] ?? ''));
- $lowest = max(1, (float) ($settings['pay_balance_withdraw_lowest_money'] ?? $settings['pay_rebate_withdraw_lowest_money'] ?? 50));
+ $withdraw_settings = class_exists('\\AKSRT\\Settings\\Settings')
+ ? \AKSRT\Settings\Settings::get_withdrawal_settings()
+ : ['min_amount' => 50, 'service_charge_rate' => 5, 'daily_count' => 3, 'daily_limit' => 50, 'reset_time' => '00:00'];
+ $lowest = (float) $withdraw_settings['min_amount'];
if ($amount < $lowest) {
- return new \WP_Error('aksrt_withdraw_min', sprintf(__('最低提现 %s 元', 'aksrt'), (string) $lowest), ['status' => 400]);
+ return new \WP_Error('withdraw_min_amount', sprintf(__('提现金额低于最低提现门槛(%s 元)', 'aksrt'), (string) $lowest), ['status' => 400]);
}
if ($account === '') {
return new \WP_Error('aksrt_withdraw_account', __('请填写收款账号信息', 'aksrt'), ['status' => 400]);
}
- // One open balance withdrawal at a time (Zibll parity).
- if (\AKSRT\Payment\Withdrawal::get_instance()->has_open_withdrawal($user_id)) {
- return new \WP_Error('aksrt_withdraw_pending', __('您有处理中的提现申请,请等待完成后再申请', 'aksrt'), ['status' => 409]);
- }
- $wallet = Balance::balance($user_id);
- if ($wallet < $amount) {
- return new \WP_Error('aksrt_balance_insufficient', __('余额不足', 'aksrt'), ['status' => 402]);
- }
- $deduct = Balance::deduct($user_id, $amount, 'withdraw_hold', ['type' => 'withdraw'], __('余额提现申请冻结', 'aksrt'));
- if (is_wp_error($deduct)) {
- return $deduct;
- }
- $fee_rate = max(0, min(50, (int) ($settings['withdraw_service_charge'] ?? 0)));
- $net = $fee_rate > 0 ? round($amount * (100 - $fee_rate) / 100, 2) : $amount;
- $account_payload = wp_json_encode([
- 'account' => $account,
- 'gross_amount' => $amount,
- 'fee_rate' => $fee_rate,
- 'source' => 'balance',
- ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: $account;
- $wid = \AKSRT\Payment\Withdrawal::get_instance()->create($user_id, $net, $method !== '' ? $method : 'alipay', $account_payload);
- if ($wid <= 0) {
- Balance::add($user_id, $amount, 'withdraw_refund', [], __('提现申请失败退回', 'aksrt'));
- return new \WP_Error('aksrt_withdraw_failed', __('提现申请失败', 'aksrt'), ['status' => 500]);
+ $result = \AKSRT\Payment\Withdrawal::get_instance()->create_balance_request($user_id, $amount, $method !== '' ? $method : 'alipay', $account, $withdraw_settings);
+ if (is_wp_error($result)) {
+ return $result;
}
return rest_ensure_response([
'success' => true,
'data' => [
'message' => __('提现申请已提交,请等待处理', 'aksrt'),
- 'withdrawal_id' => $wid,
+ 'withdrawal_id' => $result['withdrawal_id'],
'amount' => $amount,
- 'net_amount' => $net,
- 'wallet_balance' => Balance::balance($user_id),
- 'reload' => true,
+ 'net_amount' => $result['net_amount'],
+ 'wallet_balance' => $result['wallet_balance'],
+ 'remaining_count' => $result['usage']['remaining_count'],
+ 'remaining_amount' => $result['usage']['remaining_amount'],
],
]);
}
diff --git a/src/Payment/Withdrawal.php b/src/Payment/Withdrawal.php
index 76e821c0..a1d06669 100644
--- a/src/Payment/Withdrawal.php
+++ b/src/Payment/Withdrawal.php
@@ -30,7 +30,7 @@ class Withdrawal {
/**
* 创建提现申请
*/
- public function create(int $user_id, float $amount, string $method = '', string $account_info = ''): int {
+ public function create(int $user_id, float $amount, string $method = '', string $account_info = '', ?float $gross_amount = null): int {
global $wpdb;
if ($user_id <= 0 || $amount <= 0) {
@@ -40,15 +40,122 @@ class Withdrawal {
$wpdb->insert($this->table(), [
'user_id' => $user_id,
'amount' => $amount,
+ 'gross_amount' => $gross_amount === null ? $amount : $gross_amount,
'method' => sanitize_key($method),
'account_info' => sanitize_textarea_field($account_info),
'status' => self::STATUS_PENDING,
'created_at' => current_time('mysql'),
- ], ['%d', '%f', '%s', '%s', '%s', '%s']);
+ ], ['%d', '%f', '%f', '%s', '%s', '%s', '%s']);
return (int) $wpdb->insert_id;
}
+ /**
+ * Daily withdrawal window in the configured WordPress timezone.
+ * @return array{start:string,end:string}
+ */
+ public function daily_window(string $reset_time = '00:00', ?\DateTimeInterface $now = null): array {
+ if (preg_match('/^(?:[01]\\d|2[0-3]):[0-5]\\d$/', $reset_time) !== 1) {
+ $reset_time = '00:00';
+ }
+ $tz = wp_timezone();
+ $local_now = $now ? \DateTimeImmutable::createFromInterface($now)->setTimezone($tz) : new \DateTimeImmutable('now', $tz);
+ $today_reset = new \DateTimeImmutable($local_now->format('Y-m-d') . ' ' . $reset_time . ':00', $tz);
+ $start = $local_now < $today_reset ? $today_reset->modify('-1 day') : $today_reset;
+ return ['start' => $start->format('Y-m-d H:i:s'), 'end' => $start->modify('+1 day')->format('Y-m-d H:i:s')];
+ }
+
+ /** @return array{count:int,total:float,remaining_count:int,remaining_amount:float,window:array{start:string,end:string}} */
+ public function daily_usage(int $user_id, array $settings): array {
+ $window = $this->daily_window((string) ($settings['reset_time'] ?? '00:00'));
+ return $this->daily_usage_in_window($user_id, $settings, $window);
+ }
+
+ /** @return array{count:int,total:float,remaining_count:int,remaining_amount:float,window:array{start:string,end:string}} */
+ private function daily_usage_in_window(int $user_id, array $settings, array $window): array {
+ global $wpdb;
+ $row = $wpdb->get_row($wpdb->prepare(
+ "SELECT COUNT(*) AS count, COALESCE(SUM(CASE WHEN gross_amount > 0 THEN gross_amount ELSE amount END), 0) AS total FROM {$this->table()} WHERE user_id = %d AND created_at >= %s AND created_at < %s",
+ $user_id, $window['start'], $window['end']
+ ), ARRAY_A);
+ $count = (int) ($row['count'] ?? 0);
+ $total = round((float) ($row['total'] ?? 0), 2);
+ $max_count = max(0, (int) ($settings['daily_count'] ?? 3));
+ $max_amount = max(0, (float) ($settings['daily_limit'] ?? 50));
+ return [
+ 'count' => $count,
+ 'total' => $total,
+ 'remaining_count' => max(0, $max_count - $count),
+ 'remaining_amount' => max(0, round($max_amount - $total, 2)),
+ 'window' => $window,
+ ];
+ }
+
+ /**
+ * Atomically validates quotas, freezes wallet funds, writes the ledger and creates an order.
+ * @return array{withdrawal_id:int,net_amount:float,wallet_balance:float,usage:array}|\WP_Error
+ */
+ public function create_balance_request(int $user_id, int $gross_amount, string $method, string $account, array $settings) {
+ global $wpdb;
+ if ($user_id <= 0 || $gross_amount <= 0) {
+ return new \WP_Error('aksrt_withdraw_amount', __('提现金额必须为正整数', 'aksrt'), ['status' => 400]);
+ }
+ if (!class_exists('\AKSRT\\Credits\\Balance')) {
+ return new \WP_Error('aksrt_withdraw_unavailable', __('提现服务不可用', 'aksrt'), ['status' => 500]);
+ }
+ $meta_table = $wpdb->usermeta;
+ $meta_key = \AKSRT\Credits\Balance::META_KEY;
+ if (!metadata_exists('user', $user_id, $meta_key)) {
+ add_user_meta($user_id, $meta_key, '0', true);
+ }
+ $wpdb->query('START TRANSACTION');
+ try {
+ $meta_id = $wpdb->get_var($wpdb->prepare("SELECT umeta_id FROM {$meta_table} WHERE user_id = %d AND meta_key = %s LIMIT 1 FOR UPDATE", $user_id, $meta_key));
+ if (!$meta_id) {
+ throw new \RuntimeException('wallet row unavailable');
+ }
+ $window = $this->daily_window((string) ($settings['reset_time'] ?? '00:00'));
+ $usage = $this->daily_usage_in_window($user_id, $settings, $window);
+ if ($usage['remaining_count'] <= 0) {
+ $wpdb->query('ROLLBACK');
+ return new \WP_Error('withdraw_count_limit', __('当日提现次数已用尽', 'aksrt'), ['status' => 409]);
+ }
+ if ($gross_amount > $usage['remaining_amount']) {
+ $wpdb->query('ROLLBACK');
+ return new \WP_Error('withdraw_amount_limit', __('本次提现后将超出单日提现总额上限', 'aksrt'), ['status' => 409]);
+ }
+ $before = (float) $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$meta_table} WHERE umeta_id = %d", $meta_id));
+ if ($before < $gross_amount) {
+ $wpdb->query('ROLLBACK');
+ return new \WP_Error('aksrt_balance_insufficient', __('余额不足', 'aksrt'), ['status' => 402]);
+ }
+ $after = round($before - $gross_amount, 2);
+ if ($wpdb->update($meta_table, ['meta_value' => (string) $after], ['umeta_id' => $meta_id], ['%s'], ['%d']) !== 1) {
+ throw new \RuntimeException('wallet update failed');
+ }
+ $fee_rate = max(0, min(50, (int) ($settings['service_charge_rate'] ?? 5)));
+ $net = round($gross_amount * (100 - $fee_rate) / 100, 2);
+ $payload = wp_json_encode(['account' => $account, 'gross_amount' => $gross_amount, 'fee_rate' => $fee_rate, 'source' => 'balance'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: $account;
+ $ok = $wpdb->insert($this->table(), [
+ 'user_id' => $user_id, 'amount' => $net, 'gross_amount' => $gross_amount, 'method' => sanitize_key($method),
+ 'account_info' => $payload, 'status' => self::STATUS_PENDING, 'created_at' => current_time('mysql'),
+ ], ['%d', '%f', '%f', '%s', '%s', '%s', '%s']);
+ if (!$ok) { throw new \RuntimeException('withdrawal insert failed'); }
+ $withdrawal_id = (int) $wpdb->insert_id;
+ \AKSRT\Credits\Balance::log($user_id, -$gross_amount, $after, 'withdraw_hold', ['type' => 'withdraw', 'id' => $withdrawal_id], __('余额提现申请冻结', 'aksrt'));
+ $wpdb->query('COMMIT');
+ wp_cache_delete($user_id, 'user_meta');
+ $usage['count']++;
+ $usage['total'] = round($usage['total'] + $gross_amount, 2);
+ $usage['remaining_count']--;
+ $usage['remaining_amount'] = max(0, round($usage['remaining_amount'] - $gross_amount, 2));
+ return ['withdrawal_id' => $withdrawal_id, 'net_amount' => $net, 'wallet_balance' => $after, 'usage' => $usage];
+ } catch (\Throwable $e) {
+ $wpdb->query('ROLLBACK');
+ return new \WP_Error('aksrt_withdraw_failed', __('提现申请失败', 'aksrt'), ['status' => 500]);
+ }
+ }
+
/**
* Get single row.
*
@@ -394,6 +501,9 @@ class Withdrawal {
* @param array
$meta
*/
private function resolve_gross_amount(array $row, array $meta): float {
+ if ((float) ($row['gross_amount'] ?? 0) > 0) {
+ return max(0, round((float) $row['gross_amount'], 2));
+ }
if (isset($meta['gross_amount'])) {
return max(0, round((float) $meta['gross_amount'], 2));
}
diff --git a/src/Settings/PaymentRuntime.php b/src/Settings/PaymentRuntime.php
index 11020d38..116dfef6 100644
--- a/src/Settings/PaymentRuntime.php
+++ b/src/Settings/PaymentRuntime.php
@@ -438,16 +438,18 @@ class PaymentRuntime {
];
}
- /**
- * @return array{min_amount:int,service_charge_rate:int,text:string}
- */
+ /** @return array{min_amount:float,service_charge_rate:int,daily_count:int,daily_limit:float,reset_time:string} */
public static function get_withdrawal_settings(): array {
$s = Settings::get_all();
return [
- 'min_amount' => max(1, min(99999, (int) ($s['pay_rebate_withdraw_lowest_money'] ?? 50))),
- 'service_charge_rate' => max(0, min(50, (int) ($s['withdraw_service_charge'] ?? 0))),
- 'text' => sanitize_textarea_field((string) ($s['pay_rebate_withdraw_text_details'] ?? '')),
+ 'min_amount' => max(0, min(99999, (float) ($s['pay_rebate_withdraw_lowest_money'] ?? 50))),
+ 'service_charge_rate' => max(0, min(50, (int) ($s['withdraw_service_charge'] ?? 5))),
+ 'daily_count' => max(0, min(99999, (int) ($s['withdraw_daily_count'] ?? 3))),
+ 'daily_limit' => max(0, min(999999, (float) ($s['withdraw_daily_limit'] ?? 50))),
+ 'reset_time' => preg_match('/^(?:[01]\\d|2[0-3]):[0-5]\\d$/', (string) ($s['withdraw_reset_time'] ?? '00:00'))
+ ? (string) $s['withdraw_reset_time']
+ : '00:00',
];
}
diff --git a/src/Settings/UserRuntime.php b/src/Settings/UserRuntime.php
index 32679353..dd9ef691 100644
--- a/src/Settings/UserRuntime.php
+++ b/src/Settings/UserRuntime.php
@@ -54,6 +54,7 @@ class UserRuntime {
$mobile_hide = $parse_csv('user_home_tabs_mobile_hide', '');
return [
+ 'route_identifier' => (($settings['user_home_route_identifier'] ?? 'nicename') === 'uid') ? 'uid' : 'nicename',
'tabs' => $normalized_tabs,
'tabs_order' => $ordered,
'tabs_pc_hide' => $pc_hide,
diff --git a/templates/pages/page-profile.php b/templates/pages/page-profile.php
index 196aba4c..098ce120 100644
--- a/templates/pages/page-profile.php
+++ b/templates/pages/page-profile.php
@@ -19,15 +19,6 @@ if (!is_user_logged_in()) {
$current_user = wp_get_current_user();
$user_id = (int) $current_user->ID;
-$requested_nicename = get_query_var('user_nicename');
-if ($requested_nicename && $requested_nicename !== $current_user->user_nicename) {
- $requested_user = get_user_by('slug', $requested_nicename);
- wp_safe_redirect($requested_user && function_exists('aksrt_get_user_home_url')
- ? aksrt_get_user_home_url($requested_user)
- : aksrt_get_user_center_url());
- exit;
-}
-
if ('POST' === ($_SERVER['REQUEST_METHOD'] ?? '') && isset($_POST['action']) && 'aksrt_save_profile' === sanitize_key(wp_unslash($_POST['action']))) {
$nonce = isset($_POST['_profile_nonce']) ? sanitize_text_field(wp_unslash($_POST['_profile_nonce'])) : '';
if (!wp_verify_nonce($nonce, 'aksrt_profile_save')) {