feat(users): merge promotion into revenue center

This commit is contained in:
2026-08-03 15:38:17 +08:00
parent 156060d2ec
commit 49c12b761f
20 changed files with 369 additions and 413 deletions
+1 -1
View File
@@ -526,7 +526,7 @@ class SchemaUsers {
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'center', 'title' => '用户中心', 'fields' => [
['key' => 'user_center_tabs', 'label' => '用户中心 Tab', 'type' => 'input', 'default' => 'profile,level,posts,comments,favorites,vip,credits,promotion,auth', 'help' => '逗号分隔。level=我的等级;promotion=推广中心;auth=官方认证;等级、VIP、订单、推广中心和认证会按功能开关自动注入'],
['key' => 'user_center_tabs', 'label' => '用户中心 Tab', 'type' => 'input', 'default' => 'profile,level,posts,comments,favorites,vip,credits,revenue,auth', 'help' => '逗号分隔。level=我的等级;revenue=收益中心;auth=官方认证;等级、VIP、订单、收益中心和认证会按功能开关自动注入'],
['key' => 'user_cover_upload', 'label' => '封面上传', 'type' => 'switch', 'default' => true],
['key' => 'user_social_links', 'label' => '社交链接', 'type' => 'switch', 'default' => true],
['key' => 'user_desc_std', 'label' => '默认签名', 'type' => 'input', 'default' => '这家伙很懒…', 'desc' => '用户未设置个人简介时显示的默认文案'],
+15 -6
View File
@@ -679,13 +679,22 @@ $hmb_js = get_template_directory() . '/assets/js/header-newadd.js';
);
}
// 收益中心页
if (is_page_template('templates/pages/page-revenue.php') || (bool) get_query_var('aksrt_revenue')) {
wp_enqueue_style(
// 收益中心:旧路由重定向页 / 用户中心 tab=revenue。
$is_revenue_surface = is_page_template('templates/pages/page-revenue.php')
|| (bool) get_query_var('aksrt_revenue')
|| (
(function_exists('aksrt_is_user_center_page') && aksrt_is_user_center_page())
&& isset($_GET['tab'])
&& in_array(sanitize_key((string) wp_unslash($_GET['tab'])), ['revenue', 'invite', 'promotion'], true)
);
if ($is_revenue_surface) {
$revenue_js = get_template_directory() . '/assets/js/revenue.js';
wp_enqueue_script(
'aksrt-revenue',
$base_uri . '/assets/css/routes/revenue.css',
['aksrt-tokens'],
$version
$base_uri . '/assets/js/revenue.js',
['aksrt-script'],
file_exists($revenue_js) ? (string) filemtime($revenue_js) : $version,
true
);
}
+1
View File
@@ -367,6 +367,7 @@ class Balance {
'tip_received' => __('收到打赏', 'aksrt'),
'admin' => __('管理员调整', 'aksrt'),
'exchange_from_credits' => __('积分兑换', 'aksrt'),
'creator_income' => __('创作收益结算', 'aksrt'),
'withdraw_hold' => __('提现冻结', 'aksrt'),
'withdraw_refund' => __('提现退回', 'aksrt'),
];
+46 -7
View File
@@ -54,13 +54,52 @@ class Revenue {
public function settle(int $revenue_id): bool {
global $wpdb;
return $wpdb->update(
$this->table(),
['status' => 'settled', 'settled_at' => current_time('mysql')],
['id' => $revenue_id, 'status' => 'pending'],
['%s', '%s'],
['%d', '%s']
) !== false;
if (!class_exists('\AKSRT\Credits\Balance')) {
return false;
}
$wpdb->query('START TRANSACTION');
try {
$revenue = $wpdb->get_row($wpdb->prepare(
"SELECT id, user_id, amount, order_number FROM {$this->table()} WHERE id = %d AND status = %s FOR UPDATE",
$revenue_id,
'pending'
), ARRAY_A);
if (!is_array($revenue)) {
$wpdb->query('ROLLBACK');
return false;
}
$credited = \AKSRT\Credits\Balance::add(
(int) $revenue['user_id'],
(float) $revenue['amount'],
'creator_income',
['type' => 'revenue', 'id' => $revenue_id],
sprintf(__('创作收益结算(订单 %s)', 'aksrt'), (string) $revenue['order_number'])
);
if (is_wp_error($credited)) {
$wpdb->query('ROLLBACK');
return false;
}
$settled = $wpdb->update(
$this->table(),
['status' => 'settled', 'settled_at' => current_time('mysql')],
['id' => $revenue_id, 'status' => 'pending'],
['%s', '%s'],
['%d', '%s']
);
if ($settled !== 1) {
$wpdb->query('ROLLBACK');
return false;
}
$wpdb->query('COMMIT');
return true;
} catch (\Throwable $e) {
$wpdb->query('ROLLBACK');
return false;
}
}
/**
+2 -2
View File
@@ -83,14 +83,14 @@ class UserRuntime {
*/
public static function get_user_center_settings(): array {
$settings = Settings::get_all();
$raw_tabs = $settings['user_center_tabs'] ?? 'profile,level,posts,comments,credits,promotion,favorites,auth';
$raw_tabs = $settings['user_center_tabs'] ?? 'profile,level,posts,comments,credits,revenue,favorites,auth';
$tabs = is_array($raw_tabs)
? $raw_tabs
: preg_split('/[\s,]+/', (string) $raw_tabs, -1, PREG_SPLIT_NO_EMPTY);
// Built-in switchable panels. VIP is always auto-injected when enabled
// by AKSRT\User\Center — keep it allowed for explicit config too.
$allowed_tabs = ['profile', 'level', 'posts', 'comments', 'favorites', 'credits', 'promotion', 'vip', 'orders', 'auth', 'settings'];
$allowed_tabs = ['profile', 'level', 'posts', 'comments', 'favorites', 'credits', 'revenue', 'vip', 'orders', 'auth', 'settings'];
$normalized_tabs = ['profile'];
foreach ((array) $tabs as $tab) {
+13 -7
View File
@@ -91,9 +91,9 @@ class Center {
'priority' => 50,
'type' => 'panel',
],
'promotion' => [
'label' => __('推广中心', 'aksrt'),
'icon' => 'user-plus',
'revenue' => [
'label' => __('收益中心', 'aksrt'),
'icon' => 'chart-line',
'priority' => 55,
'type' => 'panel',
],
@@ -127,10 +127,16 @@ class Center {
&& !empty(\AKSRT\User\Level::settings()['enabled']);
$credits_on = class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::credits_enabled();
$balance_on = class_exists('\AKSRT\Credits\Balance') && \AKSRT\Credits\Balance::enabled();
$promotion_on = $credits_on
$invite_on = $credits_on
&& class_exists('\AKSRT\Settings\Settings')
&& \AKSRT\Settings\Settings::invite_enabled()
&& \AKSRT\Settings\Settings::invite_registration_enabled();
$revenue_on = class_exists('\AKSRT\Settings\Settings')
&& (
!empty(\AKSRT\Settings\Settings::get_payment_revenue_settings()['enabled'])
|| !empty(\AKSRT\Settings\Settings::get_payment_affiliate_settings()['enabled'])
);
$revenue_tab_on = $revenue_on || $invite_on;
$vip_on = class_exists('\AKSRT\Settings\Settings')
&& !empty(\AKSRT\Settings\Settings::get_payment_vip_settings()['enabled']);
@@ -177,7 +183,7 @@ class Center {
if (($credits_on || $balance_on) && !in_array('credits', $order, true)) {
$order[] = 'credits';
}
if ($promotion_on && !in_array('promotion', $order, true)) {
if ($revenue_tab_on && !in_array('revenue', $order, true)) {
$insert_at = count($order);
foreach (['credits', 'favorites', 'posts'] as $anchor) {
$idx = array_search($anchor, $order, true);
@@ -186,7 +192,7 @@ class Center {
break;
}
}
array_splice($order, $insert_at, 0, ['promotion']);
array_splice($order, $insert_at, 0, ['revenue']);
}
$auth_on = class_exists('\AKSRT\User\AuthApply')
&& !empty(\AKSRT\User\AuthApply::settings()['enabled']);
@@ -207,7 +213,7 @@ class Center {
if ($key === 'credits' && !$credits_on && !$balance_on) {
continue;
}
if ($key === 'promotion' && !$promotion_on) {
if ($key === 'revenue' && !$revenue_tab_on) {
continue;
}
if ($key === 'vip' && !$vip_on) {