feat: unify invite flow with referral ref
This commit is contained in:
1 parent
f1d6809109
commit
b501cf4611
47 files changed
+1083
-2548
No files matched your search
@@ -26,39 +26,19 @@ trait CreditsPaymentGroups {
|
||||
return CreditsRuntime::get_signin_reward_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalized runtime settings for invite rewards and registration gating.
|
||||
*
|
||||
* @return array{
|
||||
* enabled:bool,
|
||||
* inviter_amount:int,
|
||||
* invitee_amount:int,
|
||||
* require_verify:bool,
|
||||
* ip_daily_cap:int,
|
||||
* register_field:string,
|
||||
* reject_invalid:bool,
|
||||
* registration_enabled:bool
|
||||
* }
|
||||
*/
|
||||
public static function get_invite_reward_settings(): array {
|
||||
return CreditsRuntime::get_invite_reward_settings();
|
||||
/** @return array{code_length:int,window_days:int} */
|
||||
public static function get_referral_settings(): array {
|
||||
return CreditsRuntime::get_referral_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Canonical invite registration config derived from users.invite fields.
|
||||
*
|
||||
* @return array{
|
||||
* enabled:bool,
|
||||
* mode:string,
|
||||
* register_field:string,
|
||||
* reject_invalid:bool,
|
||||
* code_length:int,
|
||||
* open_desc:string,
|
||||
* must_desc:string
|
||||
* }
|
||||
*/
|
||||
public static function get_invite_registration_config(): array {
|
||||
return CreditsRuntime::get_invite_registration_config();
|
||||
/** @return array<string,mixed> */
|
||||
public static function get_referral_reward_settings(): array {
|
||||
return CreditsRuntime::get_referral_reward_settings();
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public static function get_referral_registration_settings(): array {
|
||||
return CreditsRuntime::get_referral_registration_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,39 +55,30 @@ trait CreditsPaymentGroups {
|
||||
return CreditsRuntime::get_currency_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请系统是否启用(=积分系统启用 && invite_reward.enabled)。
|
||||
* 用于 UI 入口(个人中心邀请 Tab)的展示门禁。
|
||||
*/
|
||||
public static function invite_enabled(): bool {
|
||||
return CreditsRuntime::invite_enabled();
|
||||
public static function referral_reward_enabled(): bool {
|
||||
return CreditsRuntime::referral_reward_enabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请注册功能总开关(独立于积分系统)。
|
||||
* 控制邀请链接、注册页邀请码字段、用户中心邀请卡片的显示。
|
||||
* 存储在 aksrt_settings(invit_code_s / invite_registration_enabled)。
|
||||
*/
|
||||
public static function invite_registration_enabled(): bool {
|
||||
return CreditsRuntime::invite_registration_enabled();
|
||||
public static function referral_registration_enabled(): bool {
|
||||
return CreditsRuntime::referral_registration_enabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册页邀请码字段模式:'hidden' | 'optional' | 'required'
|
||||
*/
|
||||
public static function invite_register_field_mode(): string {
|
||||
return CreditsRuntime::invite_register_field_mode();
|
||||
public static function referral_register_field_mode(): string {
|
||||
return CreditsRuntime::referral_register_field_mode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 必填模式下邀请码无效是否拒绝注册。
|
||||
*/
|
||||
public static function invite_reject_invalid(): bool {
|
||||
return CreditsRuntime::invite_reject_invalid();
|
||||
public static function referral_reject_invalid(): bool {
|
||||
return CreditsRuntime::referral_reject_invalid();
|
||||
}
|
||||
|
||||
public static function invite_code_length(): int {
|
||||
return CreditsRuntime::invite_code_length();
|
||||
public static function referral_code_length(): int {
|
||||
return CreditsRuntime::referral_code_length();
|
||||
}
|
||||
|
||||
public static function referral_enabled(): bool {
|
||||
return self::referral_registration_enabled()
|
||||
|| self::referral_reward_enabled()
|
||||
|| PaymentRuntime::affiliate_enabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+66
-132
@@ -38,14 +38,13 @@ class CreditsRuntime {
|
||||
'on_approved' => true,
|
||||
],
|
||||
|
||||
'invite_reward' => [
|
||||
'enabled' => true,
|
||||
'inviter_amount' => 5,
|
||||
'invitee_amount' => 2,
|
||||
'require_verify' => true,
|
||||
'ip_daily_cap' => 3,
|
||||
'register_field' => 'optional',
|
||||
'reject_invalid' => true,
|
||||
'referral_reward' => [
|
||||
'enabled' => true,
|
||||
'promoter_amount' => 5,
|
||||
'referred_amount' => 2,
|
||||
'require_verify' => true,
|
||||
'ip_daily_cap' => 3,
|
||||
'level_points' => 0,
|
||||
],
|
||||
|
||||
'download_default_cost' => 0,
|
||||
@@ -54,6 +53,9 @@ class CreditsRuntime {
|
||||
if (!is_array($saved)) {
|
||||
$saved = [];
|
||||
}
|
||||
// Superseded top-level keys remain physically stored but are not exposed
|
||||
// to runtime consumers or written back by current admin clients.
|
||||
$saved = array_intersect_key($saved, $defaults);
|
||||
return array_replace_recursive($defaults, $saved);
|
||||
}
|
||||
|
||||
@@ -87,119 +89,60 @@ class CreditsRuntime {
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalized runtime settings for invite rewards and registration gating.
|
||||
* Shared ref-code settings.
|
||||
*
|
||||
* @return array{
|
||||
* enabled:bool,
|
||||
* inviter_amount:int,
|
||||
* invitee_amount:int,
|
||||
* require_verify:bool,
|
||||
* ip_daily_cap:int,
|
||||
* register_field:string,
|
||||
* reject_invalid:bool,
|
||||
* registration_enabled:bool
|
||||
* }
|
||||
* @return array{code_length:int,window_days:int}
|
||||
*/
|
||||
public static function get_invite_reward_settings(): array {
|
||||
$config = self::get_credit_settings();
|
||||
$invite = is_array($config['invite_reward'] ?? null) ? $config['invite_reward'] : [];
|
||||
public static function get_referral_settings(): array {
|
||||
$all = Settings::get_all();
|
||||
$register_field = (string) ($invite['register_field'] ?? 'optional');
|
||||
|
||||
if (!in_array($register_field, ['hidden', 'optional', 'required'], true)) {
|
||||
$register_field = 'optional';
|
||||
}
|
||||
|
||||
$inviter_amount = array_key_exists('invit_reward_points', $all)
|
||||
? max(0, (int) $all['invit_reward_points'])
|
||||
: max(0, (int) ($invite['inviter_amount'] ?? 0));
|
||||
$invitee_enabled = array_key_exists('invit_invitee_reward', $all)
|
||||
? !empty($all['invit_invitee_reward'])
|
||||
: max(0, (int) ($invite['invitee_amount'] ?? 0)) > 0;
|
||||
$invitee_amount = $invitee_enabled
|
||||
? max(0, (int) ($invite['invitee_amount'] ?? $inviter_amount))
|
||||
: 0;
|
||||
|
||||
return [
|
||||
'enabled' => !empty($config['enabled']) && !empty($invite['enabled']),
|
||||
'inviter_amount' => $inviter_amount,
|
||||
'invitee_amount' => $invitee_amount,
|
||||
'require_verify' => !empty($invite['require_verify']),
|
||||
'ip_daily_cap' => max(0, (int) ($invite['ip_daily_cap'] ?? 0)),
|
||||
'register_field' => $register_field,
|
||||
'reject_invalid' => !empty($invite['reject_invalid']),
|
||||
'registration_enabled' => self::invite_registration_enabled(),
|
||||
'invit_reward_points' => $inviter_amount,
|
||||
'invit_reward_level' => max(0, (int) ($all['invit_reward_level'] ?? 0)),
|
||||
'invit_reward_vip_days' => max(0, (int) ($all['invit_reward_vip_days'] ?? 0)),
|
||||
'invit_invitee_reward' => $invitee_enabled,
|
||||
'code_length' => max(4, min(12, (int) ($all['referral_code_length'] ?? 12))),
|
||||
'window_days' => max(1, min(365, (int) ($all['referral_window_days'] ?? 30))),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Canonical invite registration config derived from users.invite fields.
|
||||
*
|
||||
* @return array{
|
||||
* enabled:bool,
|
||||
* mode:string,
|
||||
* register_field:string,
|
||||
* reject_invalid:bool,
|
||||
* code_length:int,
|
||||
* open_desc:string,
|
||||
* must_desc:string
|
||||
* }
|
||||
* @return array{enabled:bool,promoter_amount:int,referred_amount:int,require_verify:bool,ip_daily_cap:int,level_points:int}
|
||||
*/
|
||||
public static function get_invite_registration_config(): array {
|
||||
$all = Settings::get_all();
|
||||
$credit_config = self::get_credit_settings();
|
||||
|
||||
$enabled = array_key_exists('invit_code_s', $all)
|
||||
? !empty($all['invit_code_s'])
|
||||
: (!isset($all['invite_registration_enabled']) || !empty($all['invite_registration_enabled']));
|
||||
|
||||
$mode = isset($all['invit_code_mode']) ? (string) $all['invit_code_mode'] : '';
|
||||
if (!in_array($mode, ['open', 'must', 'close'], true)) {
|
||||
$legacy_mode = (string) ($credit_config['invite_reward']['register_field'] ?? 'optional');
|
||||
if ($legacy_mode === 'required') {
|
||||
$mode = 'must';
|
||||
} elseif ($legacy_mode === 'hidden') {
|
||||
$mode = 'close';
|
||||
} else {
|
||||
$mode = 'open';
|
||||
}
|
||||
}
|
||||
|
||||
$register_field = 'optional';
|
||||
if (!$enabled || $mode === 'close') {
|
||||
$register_field = 'hidden';
|
||||
} elseif ($mode === 'must') {
|
||||
$register_field = 'required';
|
||||
}
|
||||
|
||||
$open_desc = trim((string) ($all['invit_code_open_desc'] ?? ''));
|
||||
if ($open_desc === '') {
|
||||
$open_desc = __('邀请码为选填,没有邀请码也可以注册', 'aksrt');
|
||||
}
|
||||
|
||||
$must_desc = trim((string) ($all['invit_code_must_desc'] ?? ''));
|
||||
if ($must_desc === '') {
|
||||
$must_desc = __('请输入邀请码', 'aksrt');
|
||||
}
|
||||
|
||||
$code_length = isset($all['invit_code_length']) ? (int) $all['invit_code_length'] : 0;
|
||||
if ($code_length <= 0) {
|
||||
$code_length = (int) ($all['invite_code_length'] ?? 6);
|
||||
}
|
||||
$code_length = max(4, min(12, $code_length));
|
||||
public static function get_referral_reward_settings(): array {
|
||||
$config = self::get_credit_settings();
|
||||
$reward = is_array($config['referral_reward'] ?? null) ? $config['referral_reward'] : [];
|
||||
|
||||
return [
|
||||
'enabled' => $enabled && $mode !== 'close',
|
||||
'mode' => $mode,
|
||||
'enabled' => !empty($config['enabled']) && !empty($reward['enabled']),
|
||||
'promoter_amount' => max(0, (int) ($reward['promoter_amount'] ?? 0)),
|
||||
'referred_amount' => max(0, (int) ($reward['referred_amount'] ?? 0)),
|
||||
'require_verify' => !empty($reward['require_verify']),
|
||||
'ip_daily_cap' => max(0, (int) ($reward['ip_daily_cap'] ?? 0)),
|
||||
'level_points' => max(0, (int) ($reward['level_points'] ?? 0)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{enabled:bool,register_field:string,reject_invalid:bool,open_desc:string,required_desc:string}
|
||||
*/
|
||||
public static function get_referral_registration_settings(): array {
|
||||
$all = Settings::get_all();
|
||||
$enabled = !isset($all['referral_registration_enabled']) || !empty($all['referral_registration_enabled']);
|
||||
$register_field = sanitize_key((string) ($all['referral_register_field'] ?? 'optional'));
|
||||
if (!in_array($register_field, ['hidden', 'optional', 'required'], true)) {
|
||||
$register_field = 'optional';
|
||||
}
|
||||
$open_desc = trim((string) ($all['referral_open_desc'] ?? ''));
|
||||
if ($open_desc === '') {
|
||||
$open_desc = __('推广码为选填,没有推广码也可以注册', 'aksrt');
|
||||
}
|
||||
$required_desc = trim((string) ($all['referral_required_desc'] ?? ''));
|
||||
if ($required_desc === '') {
|
||||
$required_desc = __('请输入推广码', 'aksrt');
|
||||
}
|
||||
|
||||
return [
|
||||
'enabled' => $enabled,
|
||||
'register_field' => $register_field,
|
||||
'reject_invalid' => !empty($credit_config['invite_reward']['reject_invalid']),
|
||||
'code_length' => $code_length,
|
||||
'reject_invalid' => !isset($all['referral_reject_invalid']) || !empty($all['referral_reject_invalid']),
|
||||
'open_desc' => $open_desc,
|
||||
'must_desc' => $must_desc,
|
||||
'required_desc' => $required_desc,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -222,40 +165,31 @@ class CreditsRuntime {
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请系统是否启用(=积分系统启用 && invite_reward.enabled)。
|
||||
* 用于 UI 入口(个人中心邀请 Tab)的展示门禁。
|
||||
* Ref 积分奖励是否启用。
|
||||
*/
|
||||
public static function invite_enabled(): bool {
|
||||
$config = self::get_credit_settings();
|
||||
return !empty($config['enabled']) && !empty($config['invite_reward']['enabled']);
|
||||
public static function referral_reward_enabled(): bool {
|
||||
return !empty(self::get_referral_reward_settings()['enabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请注册功能总开关(独立于积分系统)。
|
||||
* 控制邀请链接、注册页邀请码字段、用户中心邀请卡片的显示。
|
||||
* 存储在 aksrt_settings(invit_code_s / invite_registration_enabled)。
|
||||
*/
|
||||
public static function invite_registration_enabled(): bool {
|
||||
return !empty(self::get_invite_registration_config()['enabled']);
|
||||
public static function referral_registration_enabled(): bool {
|
||||
return !empty(self::get_referral_registration_settings()['enabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册页邀请码字段模式:'hidden' | 'optional' | 'required'
|
||||
*/
|
||||
public static function invite_register_field_mode(): string {
|
||||
$mode = (string) (self::get_invite_registration_config()['register_field'] ?? 'hidden');
|
||||
public static function referral_register_field_mode(): string {
|
||||
$registration = self::get_referral_registration_settings();
|
||||
if (empty($registration['enabled'])) {
|
||||
return 'hidden';
|
||||
}
|
||||
$mode = (string) ($registration['register_field'] ?? 'hidden');
|
||||
return in_array($mode, ['hidden', 'optional', 'required'], true) ? $mode : 'hidden';
|
||||
}
|
||||
|
||||
/**
|
||||
* 必填模式下邀请码无效是否拒绝注册。
|
||||
*/
|
||||
public static function invite_reject_invalid(): bool {
|
||||
return !empty(self::get_invite_registration_config()['reject_invalid']);
|
||||
public static function referral_reject_invalid(): bool {
|
||||
return !empty(self::get_referral_registration_settings()['reject_invalid']);
|
||||
}
|
||||
|
||||
public static function invite_code_length(): int {
|
||||
return max(4, min(12, (int) (self::get_invite_registration_config()['code_length'] ?? 6)));
|
||||
public static function referral_code_length(): int {
|
||||
return (int) self::get_referral_settings()['code_length'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -294,7 +294,7 @@ class PaymentRuntime {
|
||||
'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))),
|
||||
'window_days' => (int) CreditsRuntime::get_referral_settings()['window_days'],
|
||||
'settlement_days' => max(0, min(90, (int) ($settings['affiliate_settlement_days'] ?? 7))),
|
||||
'promotion_text' => sanitize_textarea_field((string) ($settings['affiliate_promotion_text'] ?? '')),
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user