diff --git a/inc/helpers/user-center-renderers/profile-revenue.php b/inc/helpers/user-center-renderers/profile-revenue.php
index 60d12d03..c2653cd3 100644
--- a/inc/helpers/user-center-renderers/profile-revenue.php
+++ b/inc/helpers/user-center-renderers/profile-revenue.php
@@ -17,10 +17,11 @@ if ($user_id <= 0) {
$affiliate = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_payment_affiliate_settings()
: [];
+$affiliate_on = !empty($affiliate['enabled']);
$withdrawal = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_withdrawal_settings()
: [];
-$withdraw_on = !empty($affiliate['enabled'])
+$withdraw_on = $affiliate_on
&& class_exists('\AKSRT\Credits\Balance')
&& \AKSRT\Credits\Balance::enabled();
if ($withdraw_on && class_exists('\AKSRT\Settings\Capabilities') && !\AKSRT\Settings\Capabilities::user_can('balance_withdraw', $user_id)) {
@@ -46,6 +47,9 @@ $active_reward_tab = sanitize_key((string) ($revenue_request['reward_tab'] ?? ($
if (!in_array($active_reward_tab, ['detail', 'orders', 'users'], true)) {
$active_reward_tab = 'detail';
}
+if (!$affiliate_on && $active_reward_tab === 'orders') {
+ $active_reward_tab = 'detail';
+}
$base_url = function_exists('aksrt_get_user_center_tab_url')
? aksrt_get_user_center_tab_url('revenue')
: home_url('/user/revenue/');
@@ -91,6 +95,7 @@ $status_labels = [
];
?>
+
@@ -107,14 +112,15 @@ $status_labels = [
+
-
%
+
%
+
+
diff --git a/src/Admin/ImportExportController.php b/src/Admin/ImportExportController.php
index cd850008..f4589726 100644
--- a/src/Admin/ImportExportController.php
+++ b/src/Admin/ImportExportController.php
@@ -352,7 +352,6 @@ class ImportExportController extends ControllerBase {
$expected_tables = [
$wpdb->prefix . 'aksrt_credit_log',
$wpdb->prefix . 'aksrt_signin_log',
- $wpdb->prefix . 'aksrt_invite',
$wpdb->prefix . 'aksrt_dl_token',
$wpdb->prefix . 'aksrt_notification',
];
diff --git a/src/Admin/Native/UsersMenus.php b/src/Admin/Native/UsersMenus.php
index 2112a5a6..863b6824 100644
--- a/src/Admin/Native/UsersMenus.php
+++ b/src/Admin/Native/UsersMenus.php
@@ -11,6 +11,7 @@ class UsersMenus {
use UsersMenusVerify;
use UsersMenusVip;
+ use UsersMenusReferral;
public const CAPABILITY = 'manage_options';
@@ -37,12 +38,21 @@ class UsersMenus {
add_action('admin_post_aksrt_users_add_restriction', [$this, 'handle_add_restriction']);
add_action('admin_post_aksrt_users_remove_restriction', [$this, 'handle_remove_restriction']);
add_action('admin_post_aksrt_users_process_appeal', [$this, 'handle_process_appeal']);
- add_action('admin_post_aksrt_users_batch_invite_codes', [$this, 'handle_batch_invite_codes']);
- add_action('admin_post_aksrt_users_disable_invite_code', [$this, 'handle_disable_invite_code']);
add_action('admin_post_aksrt_users_mutate_vip', [$this, 'handle_mutate_vip']);
}
public function register_menus(): void {
+ if (current_user_can('manage_users')) {
+ add_submenu_page(
+ 'users.php',
+ __('推广码运营', 'aksrt'),
+ __('推广码运营', 'aksrt'),
+ 'manage_users',
+ 'aksrt_referral_codes',
+ [$this, 'render_referral_codes_page']
+ );
+ }
+
if (!current_user_can(self::CAPABILITY)) {
return;
}
@@ -55,14 +65,6 @@ class UsersMenus {
'aksrt_messages',
[$this, 'render_messages_page']
);
- add_submenu_page(
- 'users.php',
- __('邀请码管理', 'aksrt'),
- __('邀请码管理', 'aksrt'),
- self::CAPABILITY,
- 'aksrt_invite_codes',
- [$this, 'render_invite_codes_page']
- );
add_submenu_page(
'users.php',
__('用户会员', 'aksrt'),
@@ -164,10 +166,6 @@ class UsersMenus {
'appeal_approved' => __('申诉已通过,限制已解除。', 'aksrt'),
'appeal_rejected' => __('申诉已驳回。', 'aksrt'),
'appeal_failed' => __('申诉处理失败。', 'aksrt'),
- 'invite_batch_ok' => __('邀请码批量生成完成。', 'aksrt'),
- 'invite_batch_failed' => __('邀请码批量生成失败。', 'aksrt'),
- 'invite_disabled' => __('邀请码已禁用。', 'aksrt'),
- 'invite_failed' => __('邀请码操作失败。', 'aksrt'),
'vip_updated' => __('会员状态已更新。', 'aksrt'),
'vip_partial' => __('部分用户的会员状态已更新。', 'aksrt'),
'vip_failed' => __('会员操作失败。', 'aksrt'),
@@ -281,209 +279,6 @@ class UsersMenus {
$this->redirect('aksrt_messages', $ok ? 'message_sent' : 'message_failed');
}
- /* ------------------------------------------------------------------
- * Invite codes
- * ----------------------------------------------------------------*/
-
- public function render_invite_codes_page(): void {
- $this->ensure_cap();
- echo '' . esc_html__('邀请码管理', 'aksrt') . '
';
- $this->flash();
-
- echo '
' . esc_html__('批量生成独立邀请码', 'aksrt') . '
';
- echo '
';
-
- if (!empty($_GET['aksrt_generated'])) {
- echo '
' . esc_html(sprintf(
- /* translators: %d count */
- __('成功生成 %d 个邀请码。', 'aksrt'),
- (int) $_GET['aksrt_generated']
- )) . '
';
- }
-
- $standalone = get_option('aksrt_standalone_invite_codes', []);
- $standalone = is_array($standalone) ? array_reverse(array_values($standalone)) : [];
-
- echo '
' . esc_html__('独立邀请码', 'aksrt') . '
';
- echo '
';
- echo '| ' . esc_html__('邀请码', 'aksrt') . ' | ' . esc_html__('状态', 'aksrt') . ' | ' . esc_html__('批次', 'aksrt') . ' | ' . esc_html__('备注', 'aksrt') . ' | ' . esc_html__('创建时间', 'aksrt') . ' | ' . esc_html__('操作', 'aksrt') . ' | ';
- echo '
';
- if (!$standalone) {
- echo '| ' . esc_html__('暂无独立邀请码', 'aksrt') . ' |
';
- }
- $shown = 0;
- foreach ($standalone as $entry) {
- if ($shown >= 200) {
- break;
- }
- $code = sanitize_key((string) ($entry['code'] ?? ''));
- if ($code === '') {
- continue;
- }
- $disabled = !empty($entry['disabled']);
- $used = !empty($entry['used']) || !empty($entry['used_by']);
- $status = $disabled ? __('已禁用', 'aksrt') : ($used ? __('已使用', 'aksrt') : __('可用', 'aksrt'));
- echo '';
- echo '' . esc_html($code) . ' | ';
- echo '' . esc_html($status) . ' | ';
- echo '' . esc_html((string) ($entry['batch_id'] ?? '')) . ' | ';
- echo '' . esc_html((string) ($entry['note'] ?? '')) . ' | ';
- echo '' . esc_html((string) ($entry['created_at'] ?? '')) . ' | ';
- echo '';
- if (!$disabled && !$used) {
- echo '';
- } else {
- echo '—';
- }
- echo ' |
';
- $shown++;
- }
- echo '
';
-
- global $wpdb;
- $rows = $wpdb->get_results(
- "SELECT user_id, meta_value AS invite_code FROM {$wpdb->usermeta} WHERE meta_key = 'aksrt_invite_code' ORDER BY umeta_id DESC LIMIT 200",
- ARRAY_A
- );
-
- echo '
' . esc_html__('用户邀请码', 'aksrt') . '
';
- echo '
';
- echo '| ' . esc_html__('用户', 'aksrt') . ' | ' . esc_html__('邀请码', 'aksrt') . ' | ' . esc_html__('邀请人数', 'aksrt') . ' | ';
- echo '
';
- if (!$rows) {
- echo '| ' . esc_html__('暂无用户邀请码', 'aksrt') . ' |
';
- }
- $invite_table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('invite') : '';
- foreach ((array) $rows as $row) {
- $user_id = (int) ($row['user_id'] ?? 0);
- $user = $user_id > 0 ? get_userdata($user_id) : null;
- $count = 0;
- if ($invite_table) {
- $count = (int) $wpdb->get_var($wpdb->prepare(
- "SELECT COUNT(*) FROM {$invite_table} WHERE inviter_id = %d",
- $user_id
- ));
- }
- echo '';
- echo '| ' . ($user ? esc_html($user->display_name . ' (#' . $user_id . ')') : esc_html((string) $user_id)) . ' | ';
- echo '' . esc_html((string) ($row['invite_code'] ?? '')) . ' | ';
- echo '' . esc_html((string) $count) . ' | ';
- echo '
';
- }
- echo '
';
- }
-
- public function handle_batch_invite_codes(): void {
- if (!current_user_can(self::CAPABILITY)) {
- wp_die(esc_html__('权限不足', 'aksrt'));
- }
- check_admin_referer('aksrt_users_batch_invite_codes');
-
- $count = isset($_POST['count']) ? max(1, min(100, (int) $_POST['count'])) : 10;
- $length = isset($_POST['length']) ? max(4, min(12, (int) $_POST['length'])) : 6;
- $prefix = isset($_POST['prefix']) ? sanitize_key((string) wp_unslash($_POST['prefix'])) : '';
- $note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
- $batch = 'INV-' . gmdate('YmdHis') . '-' . wp_generate_password(4, false, false);
- $alphabet = 'abcdefghjkmnpqrstuvwxyz23456789';
-
- $codes = get_option('aksrt_standalone_invite_codes', []);
- $codes = is_array($codes) ? array_values($codes) : [];
- $existing = [];
- foreach ($codes as $entry) {
- $c = sanitize_key((string) ($entry['code'] ?? ''));
- if ($c !== '') {
- $existing[$c] = true;
- }
- }
-
- global $wpdb;
- $generated = [];
- for ($i = 0; $i < $count; $i++) {
- $code = '';
- for ($attempt = 0; $attempt < 20; $attempt++) {
- $candidate = $prefix;
- for ($j = 0; $j < $length; $j++) {
- $candidate .= $alphabet[random_int(0, strlen($alphabet) - 1)];
- }
- $candidate = sanitize_key($candidate);
- if ($candidate === '' || isset($existing[$candidate])) {
- continue;
- }
- $user_hit = $wpdb->get_var($wpdb->prepare(
- "SELECT umeta_id FROM {$wpdb->usermeta} WHERE meta_key = 'aksrt_invite_code' AND meta_value = %s LIMIT 1",
- $candidate
- ));
- if ($user_hit) {
- continue;
- }
- $code = $candidate;
- break;
- }
- if ($code === '') {
- continue;
- }
- $existing[$code] = true;
- $codes[] = [
- 'code' => $code,
- 'created_at' => current_time('mysql'),
- 'used' => false,
- 'used_by' => 0,
- 'used_at' => '',
- 'disabled' => false,
- 'note' => $note,
- 'batch_id' => $batch,
- 'created_by' => get_current_user_id(),
- ];
- $generated[] = $code;
- }
-
- update_option('aksrt_standalone_invite_codes', array_values($codes), false);
- $ok = !empty($generated);
- $this->redirect('aksrt_invite_codes', $ok ? 'invite_batch_ok' : 'invite_batch_failed', [
- 'aksrt_generated' => count($generated),
- ]);
- }
-
- public function handle_disable_invite_code(): void {
- if (!current_user_can(self::CAPABILITY)) {
- wp_die(esc_html__('权限不足', 'aksrt'));
- }
- $code = isset($_POST['code']) ? sanitize_key((string) wp_unslash($_POST['code'])) : '';
- check_admin_referer('aksrt_users_disable_invite_code_' . $code);
-
- $ok = false;
- if ($code !== '') {
- $codes = get_option('aksrt_standalone_invite_codes', []);
- $codes = is_array($codes) ? $codes : [];
- foreach ($codes as $i => $entry) {
- if (sanitize_key((string) ($entry['code'] ?? '')) !== $code) {
- continue;
- }
- $entry['disabled'] = true;
- $codes[$i] = $entry;
- $ok = true;
- break;
- }
- if ($ok) {
- update_option('aksrt_standalone_invite_codes', array_values($codes), false);
- }
- }
- $this->redirect('aksrt_invite_codes', $ok ? 'invite_disabled' : 'invite_failed');
- }
-
/* ------------------------------------------------------------------
* Ban / reports
* ----------------------------------------------------------------*/
diff --git a/src/Admin/Native/UsersMenusReferral.php b/src/Admin/Native/UsersMenusReferral.php
new file mode 100644
index 00000000..7f965e40
--- /dev/null
+++ b/src/Admin/Native/UsersMenusReferral.php
@@ -0,0 +1,144 @@
+
+