feat: upgrade widgets and affiliate commission flow

This commit is contained in:
2026-08-16 18:29:31 +08:00
parent 22c0c9df9c
commit 698a9beb74
33 changed files with 709 additions and 227 deletions
+16 -1
View File
@@ -110,6 +110,11 @@ class Withdrawal {
}
$wpdb->query('START TRANSACTION');
try {
$open = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$this->table()} WHERE user_id = %d AND status IN ('pending','processing') FOR UPDATE", $user_id));
if ($open > 0) {
$wpdb->query('ROLLBACK');
return new \WP_Error('withdraw_pending', __('已有待处理提现申请', 'aksrt'), ['status' => 409]);
}
$meta_id = $wpdb->get_var($wpdb->prepare("SELECT umeta_id FROM {$meta_table} WHERE user_id = %d AND meta_key = %s LIMIT 1 FOR UPDATE", $user_id, $meta_key));
if (!$meta_id) {
throw new \RuntimeException('wallet row unavailable');
@@ -222,6 +227,15 @@ class Withdrawal {
if ($old_status === $new_status && $note === '') {
return true;
}
$transitions = [
self::STATUS_PENDING => [self::STATUS_PROCESSING, self::STATUS_REJECTED],
self::STATUS_PROCESSING => [self::STATUS_COMPLETED, self::STATUS_REJECTED],
self::STATUS_COMPLETED => [],
self::STATUS_REJECTED => [],
];
if (!in_array($new_status, $transitions[$old_status] ?? [], true)) {
return new \WP_Error('aksrt_withdraw_transition', __('提现状态转换不合法', 'aksrt'), ['status' => 409]);
}
$meta = $this->parse_account_meta((string) ($row['account_info'] ?? ''));
$user_id = (int) ($row['user_id'] ?? 0);
@@ -459,7 +473,8 @@ class Withdrawal {
$row['meta'] = $meta;
$row['gross_amount'] = $gross;
$row['fee_rate'] = (int) ($meta['fee_rate'] ?? 0);
$row['display_account'] = (string) ($meta['account'] ?? $row['account_info'] ?? '');
$display = (string) ($meta['account'] ?? $row['account_info'] ?? '');
$row['display_account'] = strlen($display) > 4 ? substr($display, 0, 2) . str_repeat('*', max(2, strlen($display) - 4)) . substr($display, -2) : '****';
$row['source'] = (string) ($meta['source'] ?? 'balance');
return $row;
}