mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 11:20:53 +08:00
Revert "fix: resolve PHPStan static analysis warnings"
This reverts commit 2d3e4b4a95.
This commit is contained in:
@@ -12,7 +12,7 @@ use App\Services\Plugin\HookManager;
|
||||
|
||||
class UserService
|
||||
{
|
||||
private function calcResetDayByMonthFirstDay(): int
|
||||
private function calcResetDayByMonthFirstDay()
|
||||
{
|
||||
$today = date('d');
|
||||
$lastDay = date('d', strtotime('last day of +0 months'));
|
||||
@@ -51,34 +51,55 @@ class UserService
|
||||
return (int) (($nextYear - time()) / 86400);
|
||||
}
|
||||
|
||||
public function getResetDay(User $user): ?int
|
||||
public function getResetDay(User $user)
|
||||
{
|
||||
// 前置条件检查
|
||||
if ($user->expired_at <= time() || $user->expired_at === null) {
|
||||
return null;
|
||||
if (!isset($user->plan)) {
|
||||
$user->plan = Plan::find($user->plan_id);
|
||||
}
|
||||
|
||||
// 获取重置方式逻辑统一
|
||||
$resetMethod = $user->plan->reset_traffic_method === Plan::RESET_TRAFFIC_FOLLOW_SYSTEM
|
||||
? (int)admin_setting('reset_traffic_method', 0)
|
||||
: $user->plan->reset_traffic_method;
|
||||
|
||||
// 验证重置方式有效性
|
||||
if (!in_array($resetMethod, array_keys(Plan::getResetTrafficMethods()), true)) {
|
||||
if ($user->expired_at <= time() || $user->expired_at === NULL)
|
||||
return null;
|
||||
// if reset method is not reset
|
||||
if ($user->plan->reset_traffic_method === 2)
|
||||
return null;
|
||||
switch (true) {
|
||||
case ($user->plan->reset_traffic_method === NULL): {
|
||||
$resetTrafficMethod = admin_setting('reset_traffic_method', 0);
|
||||
switch ((int) $resetTrafficMethod) {
|
||||
// month first day
|
||||
case 0:
|
||||
return $this->calcResetDayByMonthFirstDay();
|
||||
// expire day
|
||||
case 1:
|
||||
return $this->calcResetDayByExpireDay($user->expired_at);
|
||||
// no action
|
||||
case 2:
|
||||
return null;
|
||||
// year first day
|
||||
case 3:
|
||||
return $this->calcResetDayByYearFirstDay();
|
||||
// year expire day
|
||||
case 4:
|
||||
return $this->calcResetDayByYearExpiredAt($user->expired_at);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ($user->plan->reset_traffic_method === 0): {
|
||||
return $this->calcResetDayByMonthFirstDay();
|
||||
}
|
||||
case ($user->plan->reset_traffic_method === 1): {
|
||||
return $this->calcResetDayByExpireDay($user->expired_at);
|
||||
}
|
||||
case ($user->plan->reset_traffic_method === 2): {
|
||||
return null;
|
||||
}
|
||||
case ($user->plan->reset_traffic_method === 3): {
|
||||
return $this->calcResetDayByYearFirstDay();
|
||||
}
|
||||
case ($user->plan->reset_traffic_method === 4): {
|
||||
return $this->calcResetDayByYearExpiredAt($user->expired_at);
|
||||
}
|
||||
}
|
||||
|
||||
// 方法映射表
|
||||
$methodHandlers = [
|
||||
Plan::RESET_TRAFFIC_FIRST_DAY_MONTH => fn() => $this->calcResetDayByMonthFirstDay(),
|
||||
Plan::RESET_TRAFFIC_MONTHLY => fn() => $this->calcResetDayByExpireDay($user->expired_at),
|
||||
Plan::RESET_TRAFFIC_FIRST_DAY_YEAR => fn() => $this->calcResetDayByYearFirstDay(),
|
||||
Plan::RESET_TRAFFIC_YEARLY => fn() => $this->calcResetDayByYearExpiredAt($user->expired_at),
|
||||
];
|
||||
|
||||
$handler = $methodHandlers[$resetMethod] ?? null;
|
||||
|
||||
return $handler ? $handler() : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isAvailable(User $user)
|
||||
|
||||
Reference in New Issue
Block a user