mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 20:17:32 +08:00
fix: resolve issue where dynamic rate cannot be disabled
This commit is contained in:
+10
-7
@@ -28,6 +28,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
|||||||
* @property string|null $network 网络类型
|
* @property string|null $network 网络类型
|
||||||
* @property int|null $parent_id 父节点ID
|
* @property int|null $parent_id 父节点ID
|
||||||
* @property float|null $rate 倍率
|
* @property float|null $rate 倍率
|
||||||
|
* @property boolean $rate_time_enable 是否启用时间范围功能
|
||||||
* @property array|null $rate_time_ranges 倍率时间范围
|
* @property array|null $rate_time_ranges 倍率时间范围
|
||||||
* @property int|null $sort 排序
|
* @property int|null $sort 排序
|
||||||
* @property array|null $protocol_settings 协议设置
|
* @property array|null $protocol_settings 协议设置
|
||||||
@@ -455,13 +456,15 @@ class Server extends Model
|
|||||||
|
|
||||||
public function getCurrentRate(): float
|
public function getCurrentRate(): float
|
||||||
{
|
{
|
||||||
$now = date('H:i');
|
if (!$this->rate_time_enable) {
|
||||||
$ranges = $this->rate_time_ranges ?? [];
|
return (float) $this->rate;
|
||||||
foreach ($ranges as $range) {
|
|
||||||
if ($now >= $range['start'] && $now <= $range['end']) {
|
|
||||||
return (float) $range['rate'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (float) $this->rate;
|
|
||||||
|
$now = now()->format('H:i');
|
||||||
|
$ranges = $this->rate_time_ranges ?? [];
|
||||||
|
$matchedRange = collect($ranges)
|
||||||
|
->first(fn($range) => $now >= $range['start'] && $now <= $range['end']);
|
||||||
|
|
||||||
|
return $matchedRange ? (float) $matchedRange['rate'] : (float) $this->rate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user