feat: multiple improvements and bug fixes

- Add gift card redemption feature
- Resolve custom range selection issue in overview
- Allow log page size to be modified
- Add subscription path change notification
- Improve dynamic node rate feature
- Support markdown documentation display for plugins
- Reduce power reset service logging
- Fix backend version number not updating after update
This commit is contained in:
xboard
2025-07-14 00:33:04 +08:00
parent a01b94f131
commit a838a43ae5
38 changed files with 3056 additions and 325 deletions
+43 -1
View File
@@ -7,6 +7,7 @@ use App\Jobs\StatUserJob;
use App\Jobs\TrafficFetchJob;
use App\Models\Order;
use App\Models\Plan;
use App\Models\Server;
use App\Models\User;
use App\Services\Plugin\HookManager;
use App\Services\TrafficResetService;
@@ -113,8 +114,11 @@ class UserService
return true;
}
public function trafficFetch(array $server, string $protocol, array $data)
public function trafficFetch(Server $server, string $protocol, array $data)
{
$server->rate = $server->getCurrentRate();
$server = $server->toArray();
list($server, $protocol, $data) = HookManager::filter('traffic.before_process', [
$server,
$protocol,
@@ -227,6 +231,44 @@ class UserService
}
}
/**
* 为用户分配一个新套餐或续费现有套餐
*
* @param User $user 用户模型
* @param Plan $plan 套餐模型
* @param int $validityDays 购买天数
* @return User 更新后的用户模型
*/
public function assignPlan(User $user, Plan $plan, int $validityDays): User
{
$user->plan_id = $plan->id;
$user->group_id = $plan->group_id;
$user->transfer_enable = $plan->transfer_enable * 1073741824;
$user->speed_limit = $plan->speed_limit;
if ($validityDays > 0) {
$user = $this->extendSubscription($user, $validityDays);
}
$user->save();
return $user;
}
/**
* 延长用户的订阅有效期
*
* @param User $user 用户模型
* @param int $days 延长天数
* @return User 更新后的用户模型
*/
public function extendSubscription(User $user, int $days): User
{
$currentExpired = $user->expired_at ?? time();
$user->expired_at = max($currentExpired, time()) + ($days * 86400);
return $user;
}
/**
* 设置试用计划
*/