feat: unify referral promotion tabs and compact earnings UI
This commit is contained in:
@@ -140,6 +140,47 @@ final class ReferralAttribution {
|
||||
return ['promoters' => $promoters, 'effective_payers' => $payers];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return users bound through the forward-only ref relation.
|
||||
*
|
||||
* @return array{items:array<int,array<string,mixed>>,total:int,page:int,per_page:int,max_pages:int}
|
||||
*/
|
||||
public function list_referred_users(int $promoter_id, int $page = 1, int $per_page = 10): array {
|
||||
global $wpdb;
|
||||
$table = \AKSRT\Core\DBMigrator::table('affiliate_relation');
|
||||
$page = max(1, $page);
|
||||
$per_page = max(1, min(50, $per_page));
|
||||
if ($promoter_id <= 0 || $table === '') {
|
||||
return ['items' => [], 'total' => 0, 'page' => $page, 'per_page' => $per_page, 'max_pages' => 1];
|
||||
}
|
||||
$total = (int) $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT COUNT(*) FROM {$table} WHERE promoter_id=%d AND status='bound' AND invitee_id > 0",
|
||||
$promoter_id
|
||||
));
|
||||
$rows = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT invitee_id, referral_code, bound_at, status FROM {$table} WHERE promoter_id=%d AND status='bound' AND invitee_id > 0 ORDER BY id DESC LIMIT %d OFFSET %d",
|
||||
$promoter_id,
|
||||
$per_page,
|
||||
($page - 1) * $per_page
|
||||
), ARRAY_A);
|
||||
$items = [];
|
||||
foreach ((array) $rows as $row) {
|
||||
$invitee_id = (int) ($row['invitee_id'] ?? 0);
|
||||
$user = $invitee_id > 0 ? get_userdata($invitee_id) : null;
|
||||
if (!$user instanceof \WP_User) {
|
||||
continue;
|
||||
}
|
||||
$items[] = [
|
||||
'user_id' => $invitee_id,
|
||||
'name' => $user->display_name,
|
||||
'avatar' => get_avatar_url($invitee_id, ['size' => 64]),
|
||||
'bound_at' => (string) ($row['bound_at'] ?? ''),
|
||||
'status' => (string) ($row['status'] ?? 'bound'),
|
||||
];
|
||||
}
|
||||
return ['items' => $items, 'total' => $total, 'page' => $page, 'per_page' => $per_page, 'max_pages' => max(1, (int) ceil($total / $per_page))];
|
||||
}
|
||||
|
||||
public function register_routes(): void {
|
||||
register_rest_route('aksrt/v1', '/promotion/me', [
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
|
||||
Reference in New Issue
Block a user