feat: adjust affiliate commissions and withdrawal strategy

This commit is contained in:
kate522 committed 2026-08-16 23:11:01 +08:00
1 parent 8fc6fe5312
commit 929603b9e2
13 files changed
+93 -111

No files matched your search

+22 -16
View File
@@ -282,30 +282,34 @@ class PaymentRuntime {
*/
public static function get_payment_affiliate_settings(): array {
$settings = Settings::get_all();
$ratio = max(0, min(100, (float) ($settings['affiliate_ratio'] ?? 5)));
$fee = max(0, min(100, (float) ($settings['affiliate_withdrawal_fee'] ?? 5)));
$clamp_ratio = static fn ($value): float => max(0, min(100, (float) $value));
$types = (array) ($settings['affiliate_order_types'] ?? ['membership', 'content']);
$types = array_values(array_intersect(['membership', 'content'], array_map('sanitize_key', $types)));
$types = array_values(array_intersect(['membership', 'content', 'credits'], array_map('sanitize_key', $types)));
if (!$types) { $types = ['membership', 'content']; }
$channels = array_values(array_intersect(['alipay', 'wechat'], array_map('sanitize_key', (array) ($settings['affiliate_payout_channels'] ?? ['alipay', 'wechat']))));
if (!$channels) { $channels = ['alipay', 'wechat']; }
return [
'enabled' => !empty($settings['affiliate_enabled']),
'ratio' => $ratio,
'ratios' => [
'user' => $clamp_ratio($settings['affiliate_ratio_user'] ?? 5),
'vip_1' => $clamp_ratio($settings['affiliate_ratio_vip_1'] ?? 5),
'vip_2' => $clamp_ratio($settings['affiliate_ratio_vip_2'] ?? 5),
],
'order_types' => $types,
'window_days' => max(1, min(365, (int) ($settings['affiliate_touch_window_days'] ?? 30))),
'settlement_days' => max(0, min(90, (int) ($settings['affiliate_settlement_days'] ?? 7))),
'min_withdrawal' => max(0, min(999999, (float) ($settings['affiliate_min_withdrawal'] ?? 50))),
'withdrawal_fee' => $fee,
'payout_channels' => $channels,
'allow_self_purchase' => !empty($settings['affiliate_allow_self_purchase']),
'show_stats' => !isset($settings['affiliate_show_stats']) || !empty($settings['affiliate_show_stats']),
'promotion_text' => sanitize_textarea_field((string) ($settings['affiliate_promotion_text'] ?? '')),
];
}
public static function affiliate_enabled(): bool { return !empty(self::get_payment_affiliate_settings()['enabled']); }
public static function affiliate_ratio(): float { return (float) self::get_payment_affiliate_settings()['ratio']; }
public static function affiliate_ratio_for_user(int $user_id): float {
$level = function_exists('aksrt_get_user_vip_level') ? (int) aksrt_get_user_vip_level($user_id) : 0;
return self::affiliate_ratio_for_level($level);
}
public static function affiliate_ratio_for_level(int $level): float {
$settings = self::get_payment_affiliate_settings();
$key = $level >= 2 ? 'vip_2' : ($level >= 1 ? 'vip_1' : 'user');
return (float) ($settings['ratios'][$key] ?? 0);
}
public static function get_affiliate_settings(): array { return self::get_payment_affiliate_settings(); }
public static function get_settlement_settings(): array {
$s = self::get_payment_affiliate_settings();
@@ -436,18 +440,20 @@ class PaymentRuntime {
];
}
/** @return array{min_amount:float,service_charge_rate:int,daily_count:int,daily_limit:float,reset_time:string} */
/** @return array{min_amount:float,service_charge_rate:int,daily_count:int,daily_limit:float,reset_time:string,payout_channels:string[]} */
public static function get_withdrawal_settings(): array {
$s = Settings::get_all();
$affiliate = self::get_payment_affiliate_settings();
$channels = array_values(array_intersect(['alipay', 'wechat'], array_map('sanitize_key', (array) ($s['affiliate_payout_channels'] ?? ['alipay', 'wechat']))));
if (!$channels) { $channels = ['alipay', 'wechat']; }
return [
'min_amount' => (float) $affiliate['min_withdrawal'],
'service_charge_rate' => (int) round((float) $affiliate['withdrawal_fee']),
'min_amount' => max(0, min(999999, (float) ($s['affiliate_min_withdrawal'] ?? 50))),
'service_charge_rate' => (int) round(max(0, min(100, (float) ($s['affiliate_withdrawal_fee'] ?? 5)))),
'daily_count' => max(0, min(99999, (int) ($s['affiliate_daily_withdrawal_count'] ?? 3))),
'daily_limit' => max(0, min(999999, (float) ($s['affiliate_daily_withdrawal_limit'] ?? 500))),
'reset_time' => preg_match('/^(?:[01]\\d|2[0-3]):[0-5]\\d$/', (string) ($s['affiliate_withdrawal_reset_time'] ?? '00:00'))
? (string) $s['affiliate_withdrawal_reset_time']
: '00:00',
'payout_channels' => $channels,
];
}