mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-03 11:09:27 +00:00
Add 套餐限速功能(正确方式)
This commit is contained in:
27
app/Console/Commands/UpdateUserSpeedLimit.php
Normal file
27
app/Console/Commands/UpdateUserSpeedLimit.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Console\Command;
|
||||
use Log;
|
||||
|
||||
class UpdateUserSpeedLimit extends Command
|
||||
{
|
||||
protected $signature = 'updateUserSpeedLimit';
|
||||
protected $description = '根据商品更新用户限速';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$jobStartTime = microtime(true);
|
||||
|
||||
foreach (Order::whereStatus(2)->whereIsExpire(0)->where('goods_id', '>', '0')->oldest()->with(['user', 'goods'])->has('goods')->has('user')->get() as $order) {
|
||||
$order->user->update(['speed_limit' => $order->goods->speed_limit]);
|
||||
}
|
||||
|
||||
$jobEndTime = microtime(true);
|
||||
$jobUsedTime = round(($jobEndTime - $jobStartTime), 4);
|
||||
|
||||
Log::info('---【'.$this->description.'】完成---,耗时'.$jobUsedTime.'秒');
|
||||
}
|
||||
}
|
||||
@@ -27,16 +27,10 @@ class TrojanController extends BaseController
|
||||
public function getUserList(Node $node): JsonResponse
|
||||
{
|
||||
foreach ($node->users() as $user) {
|
||||
$order = $user->orders()->activePlan()->first(); // 取出用户正在使用的套餐
|
||||
if ($order) {
|
||||
$speed_limit = $order->goods->getRawOriginal('speed_limit');
|
||||
} else {
|
||||
$speed_limit = $user->getRawOriginal('speed_limit');
|
||||
}
|
||||
$data[] = [
|
||||
'uid' => $user->id,
|
||||
'password' => $user->passwd,
|
||||
'speed_limit' => $speed_limit,
|
||||
'speed_limit' => $user->getRawOriginal('speed_limit'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -44,16 +44,10 @@ class V2RayController extends BaseController
|
||||
public function getUserList(Node $node): JsonResponse
|
||||
{
|
||||
foreach ($node->users() as $user) {
|
||||
$order = $user->orders()->activePlan()->first(); // 取出用户正在使用的套餐
|
||||
if ($order) {
|
||||
$speed_limit = $order->goods->getRawOriginal('speed_limit');
|
||||
} else {
|
||||
$speed_limit = $user->getRawOriginal('speed_limit');
|
||||
}
|
||||
$data[] = [
|
||||
'uid' => $user->id,
|
||||
'vmess_uid' => $user->vmess_id,
|
||||
'speed_limit' => $speed_limit,
|
||||
'speed_limit' => $user->getRawOriginal('speed_limit'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,11 @@ class User extends Authenticatable implements JWTSubject
|
||||
return $telegram->identifier ?? null;
|
||||
}
|
||||
|
||||
public function userAuths(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserOauth::class);
|
||||
}
|
||||
|
||||
public function profile()
|
||||
{
|
||||
return [
|
||||
@@ -70,11 +75,6 @@ class User extends Authenticatable implements JWTSubject
|
||||
];
|
||||
}
|
||||
|
||||
public function userAuths(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserOauth::class);
|
||||
}
|
||||
|
||||
public function onlineIpLogs(): HasMany
|
||||
{
|
||||
return $this->hasMany(NodeOnlineIp::class);
|
||||
@@ -264,7 +264,7 @@ class User extends Authenticatable implements JWTSubject
|
||||
}
|
||||
|
||||
public function incrementData(int $data): bool
|
||||
{// 添加用户流量
|
||||
{ // 添加用户流量
|
||||
$this->transfer_enable += $data;
|
||||
|
||||
return $this->save();
|
||||
@@ -272,7 +272,6 @@ class User extends Authenticatable implements JWTSubject
|
||||
|
||||
public function isNotCompleteOrderByUserId(int $userId): bool
|
||||
{ // 添加用户余额
|
||||
|
||||
return Order::uid($userId)->whereIn('status', [0, 1])->exists();
|
||||
}
|
||||
|
||||
@@ -299,7 +298,7 @@ class User extends Authenticatable implements JWTSubject
|
||||
}
|
||||
|
||||
public function isTrafficWarning(): bool
|
||||
{// 流量异常警告
|
||||
{ // 流量异常警告
|
||||
return $this->recentTrafficUsed() >= (sysConfig('traffic_ban_value') * GB);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,9 +103,10 @@ class OrderService
|
||||
Order::whereId(self::$order->id)->update(['expired_at' => date('Y-m-d H:i:s', strtotime(self::$goods->days.' days'))]);
|
||||
$oldData = self::$user->transfer_enable;
|
||||
$updateData = [
|
||||
'invite_num' => self::$user->invite_num + (self::$goods->invite_num ?: 0),
|
||||
'level' => self::$goods->level,
|
||||
'enable' => 1,
|
||||
'invite_num' => self::$user->invite_num + (self::$goods->invite_num ?: 0),
|
||||
'level' => self::$goods->level,
|
||||
'speed_limit' => self::$goods->speed_limit,
|
||||
'enable' => 1,
|
||||
];
|
||||
|
||||
// 无端口用户 添加端口
|
||||
|
||||
@@ -177,6 +177,10 @@ return [
|
||||
'active_prepaid_question' => 'Are you sure to active prepaid order?',
|
||||
'active_prepaid_tips' => 'After active:<br>Current order will be set to expired! <br> Expired dates will be recalculated!',
|
||||
],
|
||||
'service' => [
|
||||
'node_count' => 'Include <code>:num</code> Nodes',
|
||||
'unlimited' => 'Unlimited Speed',
|
||||
],
|
||||
'node' => [
|
||||
'info' => 'Configuration information',
|
||||
'setting' => 'Proxy settings',
|
||||
|
||||
@@ -161,6 +161,10 @@ return [
|
||||
'conflict_tips' => '<p>当前购买套餐将自动设置为 <code>预支付套餐</code><p><ol class="text-left"><li> 预支付套餐会在生效中的套餐失效后自动开通!</li><li> 您可以在支付后手动激活套餐!</li></ol>',
|
||||
'call4help' => '请开工单通知客服',
|
||||
],
|
||||
'service' => [
|
||||
'node_count' => '<code>:num</code>条优质线路',
|
||||
'unlimited' => '不限速',
|
||||
],
|
||||
'payment' => [
|
||||
'error' => '充值余额不合规',
|
||||
'creating' => '创建支付单中...',
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<br>
|
||||
<strong>{{$goods->traffic_label}}</strong> {{trans('user.attribute.data')}}
|
||||
<br>
|
||||
{{trans('user.account.speed_limit')}}<strong>{{$goods->speed_limit}} MB</strong>
|
||||
{{trans('user.account.speed_limit')}}<strong> {{ $goods->speed_limit ? $goods->speed_limit.' Mbps' : trans('user.service.unlimited') }} </strong>
|
||||
</td>
|
||||
<td class="text-middle"> ¥{{$goods->price}} </td>
|
||||
<td class="text-middle"> x 1</td>
|
||||
|
||||
@@ -73,11 +73,15 @@
|
||||
</div>
|
||||
<ul class="pricing-features">
|
||||
<li>
|
||||
<strong>{{$goods->traffic_label}} </strong>{{trans('user.attribute.data')}}
|
||||
<strong>{{$goods->traffic_label}}</strong>{{trans('user.attribute.data')}}
|
||||
{!!$goods->type === 1? ' <code>'.$dataPlusDays.'</code> '.trans('validation.attributes.day'):'/'.trans('validation.attributes.month')!!}
|
||||
</li>
|
||||
<li>
|
||||
{{trans('user.account.speed_limit')}}<strong> {{ $goods->speed_limit > 0 ? $goods->speed_limit.' MB' : '不限速' }} </strong>
|
||||
{!!trans('user.service.node_count', ['num' => Auth::user()->nodes()->where('level', '<=', $goods->level)->count()])!!}
|
||||
</li>
|
||||
<li>
|
||||
{{trans('user.account.speed_limit')}}
|
||||
<strong> {{ $goods->speed_limit ? $goods->speed_limit.' Mbps' : trans('user.service.unlimited') }} </strong>
|
||||
</li>
|
||||
{!!$goods->info!!}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user