feat(user-center): merge promotion rewards into revenue

This commit is contained in:
2026-08-05 23:43:16 +08:00
parent a87fd32fa3
commit 39c92017d9
14 changed files with 1048 additions and 159 deletions
+23 -9
View File
@@ -59,18 +59,30 @@ class Invite {
'permission_callback' => function () {
return is_user_logged_in();
},
'args' => [
'page' => [
'type' => 'integer',
'default' => 1,
'minimum' => 1,
],
'per_page' => [
'type' => 'integer',
'default' => 10,
'minimum' => 1,
'maximum' => 50,
],
],
]);
}
/** 捕获 ?invite=XYZ */
/** Capture ?ref=XYZ, with legacy ?invite=XYZ support. */
public function capture_invite_cookie(): void {
if (is_admin()) return;
if (empty($_GET['invite'])) return;
$raw_code = $_GET['ref'] ?? $_GET['invite'] ?? '';
if ($raw_code === '') return;
// 邀请注册功能关闭时不处理
if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::invite_registration_enabled()) return;
$code = sanitize_key((string) $_GET['invite']);
$code = sanitize_key(wp_unslash((string) $raw_code));
if ($code === '') return;
// 校验邀请码是否对应真实用户
@@ -609,7 +621,7 @@ class Invite {
}
}
$invite_url = add_query_arg('invite', $code, aksrt_get_register_url());
$invite_url = add_query_arg('ref', $code, home_url('/'));
return new \WP_REST_Response([
'code' => $code,
@@ -626,9 +638,7 @@ class Invite {
global $wpdb;
$user_id = get_current_user_id();
$page = max(1, (int) $request->get_param('page'));
$per_page = min(50, max(1, (int) $request->get_param('per_page') ?: 20));
$offset = ($page - 1) * $per_page;
$per_page = min(50, max(1, (int) $request->get_param('per_page') ?: 10));
$table = \AKSRT\Core\DBMigrator::table('invite');
if (!$table) {
return new \WP_REST_Response(['items' => [], 'total' => 0], 200);
@@ -638,6 +648,9 @@ class Invite {
"SELECT COUNT(*) FROM {$table} WHERE inviter_id = %d",
$user_id
));
$total_pages = max(1, (int) ceil($total / $per_page));
$page = min($page, $total_pages);
$offset = ($page - 1) * $per_page;
$rows = $wpdb->get_results($wpdb->prepare(
"SELECT * FROM {$table} WHERE inviter_id = %d ORDER BY created_at DESC LIMIT %d OFFSET %d",
$user_id,
@@ -664,6 +677,7 @@ class Invite {
'total' => $total,
'page' => $page,
'per_page' => $per_page,
'total_pages' => $total_pages,
], 200);
}
}