fix(payment): refresh rebate metrics and unify withdrawal statuses

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Fable 5 committed 2026-08-06 14:06:28 +08:00
1 parent 99f5c5e834
commit 50236b07fa
6 files changed
+59 -22

No files matched your search

+12 -10
View File
@@ -9,11 +9,10 @@ defined('ABSPATH') || exit;
class Withdrawal {
public const STATUS_PENDING = 'pending';
public const STATUS_APPROVED = 'approved';
public const STATUS_PROCESSING = 'processing';
public const STATUS_COMPLETED = 'completed';
public const STATUS_REJECTED = 'rejected';
public const STATUS_PENDING = 'pending';
public const STATUS_PROCESSING = 'processing';
public const STATUS_COMPLETED = 'completed';
public const STATUS_REJECTED = 'rejected';
private static $instance = null;
@@ -99,7 +98,6 @@ class Withdrawal {
$new_status = sanitize_key($new_status);
$allowed = [
self::STATUS_PENDING,
self::STATUS_APPROVED,
self::STATUS_PROCESSING,
self::STATUS_COMPLETED,
self::STATUS_REJECTED,
@@ -195,7 +193,7 @@ class Withdrawal {
}
/**
* Whether user has open (pending/processing/approved) withdrawals.
* Whether user has open (pending/processing) withdrawals.
*/
public function has_open_withdrawal(int $user_id): bool {
return $this->count_open($user_id) > 0;
@@ -211,7 +209,7 @@ class Withdrawal {
}
return (int) $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM {$this->table()}
WHERE user_id = %d AND status IN ('pending','approved','processing')",
WHERE user_id = %d AND status IN ('pending','processing')",
$user_id
));
}
@@ -226,7 +224,7 @@ class Withdrawal {
}
$rows = $wpdb->get_results($wpdb->prepare(
"SELECT amount, account_info FROM {$this->table()}
WHERE user_id = %d AND status IN ('pending','approved','processing')",
WHERE user_id = %d AND status IN ('pending','processing')",
$user_id
), ARRAY_A);
$total = 0.0;
@@ -253,7 +251,7 @@ class Withdrawal {
$params = [$user_id];
if (!empty($args['open_only'])) {
$where[] = "status IN ('pending','approved','processing')";
$where[] = "status IN ('pending','processing')";
} else {
$status = sanitize_key((string) ($args['status'] ?? ''));
if ($status !== '') {
@@ -326,6 +324,8 @@ class Withdrawal {
"SELECT
COUNT(*) as total,
SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) as pending,
SUM(CASE WHEN status = 'processing' THEN 1 ELSE 0 END) as processing,
SUM(CASE WHEN status = 'rejected' THEN 1 ELSE 0 END) as rejected,
SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END) as completed,
COALESCE(SUM(CASE WHEN status = 'completed' THEN amount ELSE 0 END), 0) as total_paid
FROM {$this->table()}",
@@ -335,6 +335,8 @@ class Withdrawal {
return [
'total' => (int) ($row['total'] ?? 0),
'pending' => (int) ($row['pending'] ?? 0),
'processing' => (int) ($row['processing'] ?? 0),
'rejected' => (int) ($row['rejected'] ?? 0),
'completed' => (int) ($row['completed'] ?? 0),
'total_paid' => (float) ($row['total_paid'] ?? 0),
];