mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-26 05:17:28 +08:00
feat: enhance plan validation, traffic system and email verification
- feat: add plan price validation - feat: make traffic packages stackable - feat: add commission and invite info to admin order details - feat: apply email whitelist to verification code API - fix: subscription link copy compatibility for non-HTTPS - fix: resolve route editing 500 error in certain cases - refactor: restructure traffic reset logic
This commit is contained in:
@@ -115,72 +115,6 @@ class Plan extends Model
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一次流量重置时间
|
||||
*
|
||||
* @param Carbon|null $from 计算起始时间,默认为当前时间
|
||||
* @return Carbon|null 下次重置时间,如果不重置则返回null
|
||||
*/
|
||||
public function getNextResetTime(?Carbon $from = null): ?Carbon
|
||||
{
|
||||
$from = $from ?? Carbon::now();
|
||||
|
||||
switch ($this->reset_traffic_method) {
|
||||
case self::RESET_TRAFFIC_FIRST_DAY_MONTH:
|
||||
return $from->copy()->addMonth()->startOfMonth();
|
||||
|
||||
case self::RESET_TRAFFIC_MONTHLY:
|
||||
return $from->copy()->addMonth()->startOfDay();
|
||||
|
||||
case self::RESET_TRAFFIC_FIRST_DAY_YEAR:
|
||||
return $from->copy()->addYear()->startOfYear();
|
||||
|
||||
case self::RESET_TRAFFIC_YEARLY:
|
||||
return $from->copy()->addYear()->startOfDay();
|
||||
|
||||
case self::RESET_TRAFFIC_NEVER:
|
||||
return null;
|
||||
|
||||
case self::RESET_TRAFFIC_FOLLOW_SYSTEM:
|
||||
default:
|
||||
// 这里需要实现获取系统设置的逻辑
|
||||
// 可以通过系统配置或其他方式获取
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否需要重置流量
|
||||
*
|
||||
* @param Carbon|null $checkTime 检查时间点,默认为当前时间
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldResetTraffic(?Carbon $checkTime = null): bool
|
||||
{
|
||||
if ($this->reset_traffic_method === self::RESET_TRAFFIC_NEVER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$checkTime = $checkTime ?? Carbon::now();
|
||||
$nextResetTime = $this->getNextResetTime($checkTime);
|
||||
|
||||
if ($nextResetTime === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $checkTime->greaterThanOrEqualTo($nextResetTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流量重置方式的描述
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResetTrafficMethodName(): string
|
||||
{
|
||||
return self::getResetTrafficMethods()[$this->reset_traffic_method] ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有可用的订阅周期
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user